I've been trying to use fetch to create an order and I keep getting this error: I can get an access token without any problem but I keep getting the error in the picture above. Here's my code (with my credentials replaced): try{
const attempt_access = await fetch("<a href="https://api.sandbox.paypal.com/v1/oauth2/token" target="_blank">https://api.sandbox.paypal.com/v1/oauth2/token</a>", {
body: "grant_type=client_credentials",
headers: {
Accept: "application/json",
Authorization: <MY_CREDENTIALS>,
"Content-Type": "application/x-www-form-urlencoded"
},
method: "POST"
});
const result_access = await attempt_access.json();
console.log(result_access);
var access = result_access.token_type+" "+result_access.access_token;
console.log("Access Token Aquired");
} catch (error) {
console.log('There has been a problem with your fetch operation: ', error.message);
}
try{
var body = {
"intent": "CAPTURE",
"purchase_units": [{
"amount": {
"currency_code": "USD",
"value": parseFloat(total).toFixed(2)
}
}]
};
var headers = {
"Authorization": access,
"Content-Type": "application/json"
};
const attempt_order = await fetch("<a href="https://api.sandbox.paypal.com/v2/checkout/orders" target="_blank">https://api.sandbox.paypal.com/v2/checkout/orders</a>", {
body,
headers,
method: "POST"
});
const result_order = await attempt_order.json();
console.log("Creating Order...");
console.log(result_order);
} catch (error) {
console.log('There has been a problem with your fetch operation: ', error.message);
}
... View more