Hello everyone!
I have a problem to get my PayPal-REST-API to work.
My problem is about the PayPal-Authentication-process using Wix-Fetch .
Let’s take this example here, where you try to get ACCESS-TOKEN from PayPal…
export async function getAccessToken() {
const response = await fetch("https://api.sandbox.paypal.com/v1/oauth2/token", {
method: 'post',
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Basic " + ""
},
body: "grant_type=client_credentials"
});
let jasonResponse = await response.json();
return (jasonResponse);
}
The “Authorization”-part in the “headers”-section, is the problematic part.
I know what kind of type is expected and which parameters, but putting all the needed parameters directly into the CODE, does not work like it should.
The authorization-process asks for a STRING-combination of…
"Basic " + " + “:” +
Should be something like…
"Authorization": "Basic " + "Client-ID-Here" + ":" + "Secret-ID-here"
Regarding the CURL-CODING…
So, expected is a BASE64-encoded ClientID-Secret-combination separated by a —> “:”
'Authorization: Basic {Your Base64-encoded ClientID:Secret}'
Using POSTMAN, everything looks good and you get the ACCESS-TOKEN without any problems…
You get something like…
{
"scope": "https://api.paypal.com/v1....,
"access_token": "A21AAIESP7kstuC1o-5aIA8...",
"token_type": "Bearer",
"app_id": "APP-80W284485P...T",
"expires_in": 32399,
"nonce": "2022-09-12T15:05:08Z..."
}
…including the token-type and the token itself.
But when doing it directly without the usage of POSTMAN, you get a complete different response…
…something like…
Response: {...}jsonWixCode_Console_Table_ViewWixCode_Console_Copy_JSON
url: "https://api.sandbox.paypal.com/v1/oauth2/token"
status: 200
statusText: "OK"
headers: {...}
ok: true
body: {...}
bodyUsed: false
size: 0
timeout: 0
_raw: [...]
_abort: false
Where you are able to find some buffered binary-data…
So still a step missing?