Why can't I open my referral URL?

JustinMann8
Contributor
Contributor

I have created a small script to generate referral URLs before I continue with the integration. I can successfully make a call to the API with a valid token and get the referral URL(action_url). When I paste the URL in the browser I get a blank screen and when I view the JSON data it tells me this:

dataAPI.png

 

I made the API call with a valid token so it is confusing me. How do I add an auth header if this is a link I would just be redirecting a user to? The app I am integrating with is built using the MERN stack.

Login to Me Too
2 REPLIES 2

MTS_Jennifer
Moderator
Moderator

Hi @JustinMann8 ,

Thank you for posting to the PayPal Merchant Community.

The error you are seeing usually means the incorrect payer-action url is being used.

Before you create the order, make certain that you are getting a valid access_token:

https://developer.paypal.com/api/rest/authentication/

 

When you create the order, in the response you should see the payer-action link.

This document has an example request and response:

https://developer.paypal.com/docs/api/orders/v2/#orders_create

In the response the payer-action link looks similar to this:

{

    "href": "https://www.paypal.com/checkoutnow?token=5O190127TN364715T",
    "rel": "payer-action",
    "method": "GET"

}

As you can see the link is a checkout now link with a token that is returned to you in the response.

If you are not opening a link that looks like the above, you will see an authentication error.

 

Thank you,

Jennifer

MTS

PayPal

 

Login to Me Too

JustinMann8
Contributor
Contributor

Hey Jennifer,

 

Thank you for getting back so quick!

 

I may have been a little unclear. I am trying to integrate the on boarding process for my app so users can connect their PayPal accounts, not creating orders just yet. Using the partner referral API: https://api-m.sandbox.paypal.com/v2/customer/partner-referrals

 

It seems I resolved the issue by adding more data in the request body in the initial API request. Could you just confirm that I am on the proper path?

 

This is the old request:

const createReferal = async () => {
  const paypalApiUrl =
    'https://api-m.sandbox.paypal.com/v2/customer/partner-referrals';

  const requestBody = {
    operations: [{ operation: 'API_INTEGRATION' }],
    legal_consents: [{ type: 'SHARE_DATA_CONSENT', granted: true }],
    products: ['EXPRESS_CHECKOUT'],
  };

  axios
    .post(paypalApiUrl, requestBody, {
      headers: {
        'Content-Type': 'application/json',
        Authorization: `Bearer {VALID TOKEN GOES HERE}`,
      },
    })
    .then((response) => {
      console.log(response.data);
    })
    .catch((error) => {
      console.log({ error: error.message });
    });
};

 This is the new request:

const createUrl = async () => {
  const paypalApiUrl =
    'https://api-m.sandbox.paypal.com/v2/customer/partner-referrals';

  const requestBody = {
    operations: [
      {
        operation: 'API_INTEGRATION',
        api_integration_preference: {
          rest_api_integration: {
            integration_method: 'PAYPAL',
            integration_type: 'THIRD_PARTY',
            third_party_details: {
              features: ['PAYMENT', 'REFUND'],
            },
          },
        },
      },
    ],
    legal_consents: [{ type: 'SHARE_DATA_CONSENT', granted: true }],
    products: ['EXPRESS_CHECKOUT'],
    web_experience_preference: {
      return_url: 'https://fruntt.com/settings',
    },
  };

  axios
    .post(paypalApiUrl, requestBody, {
      headers: {
        'Content-Type': 'application/json',
        Authorization: `Bearer {VAlID TOKEN GOES HERE}`,
      },
    })
    .then((response) => {
      console.log(response.data);
    })
    .catch((error) => {
      console.log({ error: error.message });
    });
};

 

 

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.