Home > Enterprise >  PayPal Partner Referrals API URL
PayPal Partner Referrals API URL

Time:05-18

I am having trouble setting up Partner Referrals when calling the PayPal API using Node.

Every time I attempt to call the API I receive the following error:

error: "invalid_token" error_description: "The token passed in was not found in the system"

According to the documentation the URL to call is https://api-m.sandbox.paypal.com/v2/customer/partner-referrals

Looking at the URL and the error message, I believe I am getting this error because I am using production credentials, not sandbox. However, I cannot find any documentation showing the production URL for this.

Am I correct in believing this is the sandbox URL? What is the production URL if so?

Ive followed the onboarding checklist but cant seem to make this work.

Here is my code:

 getAuthToken = async () => {
    const clientIdAndSecret = "mylongsecret";
    const authUrl = "https://api-m.paypal.com/v1/oauth2/token";
    const base64 = Buffer.from(clientIdAndSecret).toString('base64')

    const response = await fetch(authUrl, { 
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            'Accept-Language': 'en_US',
            'Authorization': `Basic ${base64}`,
        },
        body: 'grant_type=client_credentials'
    });
    const data = await response.json();
    return data;
}

setUpMerchant = async () => {
    let authData = await this.getAuthToken();
    const partnerUrl = "https://api-m.sandbox.paypal.com/v2/customer/partner-referrals";
    const request = await fetch(partnerUrl, { 
        method: 'get', 
        headers: {
          'Authorization': 'Bearer ' authData.access_token, 
          'Content-Type': 'application/json'
        }, 
    });
    const partnerData = await request.json();
    return partnerData;
}

Edit: I discovered the issue was I was running a GET request instead of a POST. The accepted answer is the correct URL

CodePudding user response:

According to the documentation the URL to call is https://api-m.sandbox.paypal.com/v2/customer/partner-referrals

The production URL does not have sandbox. in the domain.

  • Related