I have this fetch statement below that works fine in my .ts file.
<code>const fileResult = await fetch(environment.stripeFileUrl, {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + environment.stripePublishableKey
},
body: data,
});
const fileData = await fileResult.json();</code>
<code>const fileResult = await fetch(environment.stripeFileUrl, {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + environment.stripePublishableKey
},
body: data,
});
const fileData = await fileResult.json();</code>
const fileResult = await fetch(environment.stripeFileUrl, {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + environment.stripePublishableKey
},
body: data,
});
const fileData = await fileResult.json();
But when I write it like this below I get a status 401, status Text Ok, but an error that says my API key is incorrect.
Am I plugging in the header incorrectly?
New code that doesn’t work
<code>this.accountService.getStripeIdentityToken(data).subscribe(response => {
if (response.error) {
this.showError(response.error.message);
} else {
this.outputFile.emit({
file: response.id,
description: null
});
}
}, error => {
console.log(error);
}).add(() => {
this.loading(false);
});
getStripeIdentityToken(data: any) {
let headers = new HttpHeaders();
headers = headers.set('Authorization', `Bearer ${environment.stripePublishableKey}`);
return this.http.post<any>(environment.stripeFileUrl, data, {
headers
});
}</code>
<code>this.accountService.getStripeIdentityToken(data).subscribe(response => {
if (response.error) {
this.showError(response.error.message);
} else {
this.outputFile.emit({
file: response.id,
description: null
});
}
}, error => {
console.log(error);
}).add(() => {
this.loading(false);
});
getStripeIdentityToken(data: any) {
let headers = new HttpHeaders();
headers = headers.set('Authorization', `Bearer ${environment.stripePublishableKey}`);
return this.http.post<any>(environment.stripeFileUrl, data, {
headers
});
}</code>
this.accountService.getStripeIdentityToken(data).subscribe(response => {
if (response.error) {
this.showError(response.error.message);
} else {
this.outputFile.emit({
file: response.id,
description: null
});
}
}, error => {
console.log(error);
}).add(() => {
this.loading(false);
});
getStripeIdentityToken(data: any) {
let headers = new HttpHeaders();
headers = headers.set('Authorization', `Bearer ${environment.stripePublishableKey}`);
return this.http.post<any>(environment.stripeFileUrl, data, {
headers
});
}