I am trying to implement the pause subscription API for Paypal in my React app.
I don't think I am really understanding properly how to do this.
First I am trying to generate an auth token, and then use that in the pause subscription API.
The original code from the documentation is a curl so I have changed it to axios, but I don't think I am using it correctly.
Here is the code I am using:
async function cancel() {
const response = await axios.post(
'https://api-m.sandbox.paypal.com/v1/oauth2/token',
new URLSearchParams({
'grant_type': 'client_credentials'
}),
{
headers: {
'Accept': 'application/json',
'Accept-Language': 'en_US'
},
auth: {
username: 'MY CLIENT ID IS HERE',
password: 'MY SECRET IS HERE'
}
}
);
const response2 = await axios.post(
'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/suspend',
'',
{
headers: {
'Content-Type': 'application/json',
Authorization: response.data.access_token
}
}
);
}
This is the error the console returns:




