[Paypal REST API] - Access Token returns "error": "unsupported_grant_type"

Hi there

I am trying to integrate the Paypal REST API and am confounded at the very first step. The Access token grant type throws up the following JSON response 


"error": "unsupported_grant_type" ,
"error_description": "Grant Type is NULL"

Please find below the steps for what I have done :


1. In the Logic tab -> Integrations -> created a new "Consume REST API" action 

2. In the Token details popup, within the TEST tab, entered the following details for the Header and Authentication values 


3. The BODY Content only has "grant_type" as shown in the screenshot below 


4. This results in the following Request being sent out which seems to be well formed as per Paypal instructions, however the RESPONSE returns the error of "unsupported_grant_type"

REQUEST :

(I have modified the Authorization encrypted string slightly for security purposes)

POST /v1/oauth2/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Accept: application/json
Host: api.sandbox.paypal.com
User-Agent: OutSystemsPlatform
Authorization: Basic QWNYRGRFNsadsadsdb1R3UnphM2pkOE1hZnZhVGVUNXFIbjJ6Q0pSdnlhYmJMN25Tb3JDdWFDdWJXRzBqS08yRzN1Vng1ck1ZRXpKTngdfgdfgdfVBDREE1Z1hsNGQ2X0NGRkJvSzlEX0M3UVRxLVdvX3dnTUo2amNmLVhrc0hOd29lYnV0c3V4SHJVSnl6NWtZck9yeVJOVjktaTRaV3c5X2E=

"data": {    "grant_type": "client_credentials"  }

RESPONSE :

(I haven't included the headers)

{  "error": "unsupported_grant_type",  "error_description": "Grant Type is NULL"}


Can you please let me know what I have missed out? It seems there is probably an issue with the parameters for the body but I just can't figure out what it could be! 

Many thanks in advance!
Sharad





Hi,

1- Goto Headers/Auth in REST API & set Request header:

Content-Type: application/x-www-form-urlencoded

2- Check the Request you are passing :

    It should be : "grant_type": "client_credentials"


    not what you are passing like : "data": {    "grant_type": "client_credentials"  }


And if incase it does not help, Do check the Integration Log after setting the logging level to Full? This will allow you to see exactly what is sent to the external service.

Thanks

Assif

Solution

Hi 

I am sure you would have checked the paypal documentation

https://developer.paypal.com/docs/api/overview/#make-your-first-call


I tried with the below and am getting a client authentication failed as I am entering dummy creds. 

I am sending only 1 header : Accept and the body grant_type=client_credentials

Please check if this works for you 

Solution

assif_tiger wrote:

Hi,

1- Goto Headers/Auth in REST API & set Request header:

Content-Type: application/x-www-form-urlencoded

2- Check the Request you are passing :

    It should be : "grant_type": "client_credentials"


    not what you are passing like : "data": {    "grant_type": "client_credentials"  }


And if incase it does not help, Do check the Integration Log after setting the logging level to Full? This will allow you to see exactly what is sent to the external service.

Thanks

Assif

Hi Assif


many thanks for your suggestions! :) I altered the Body request as per our suggestion but Im still getting the same error. (My Content-Type was set correctly as per what you have suggested - screenshot below)



I tried to setup the Logging level but (for now) the consumed API does not show up in the Integrations. (Perhaps it will after I log in and out)


If you can help point me to a working demonstration that woudl be really helpful in finding out what I missed!

many thanks
Sharad


Amal Raj wrote:

Hi 

I am sure you would have checked the paypal documentation

https://developer.paypal.com/docs/api/overview/#make-your-first-call


I tried with the below and am getting a client authentication failed as I am entering dummy creds. 

I am sending only 1 header : Accept and the body grant_type=client_credentials

Please check if this works for you 

Hi Amal Raj


This worked perfectly! :) Thanks a lot ... Its quite odd that the documentation suggests that the Header should include Content-Type and then rejects it because it was not initialised/had a NULL value.

TL : DR - Only having 1 parameter in the Header values (Accept) As Amal suggested above, is the solution. 

Once again thank you very much! This was such a silly little thing and I reckon this bit probably needs to get added to the documentation!

Regards
Sharad


Amal Raj wrote:

Hi 

I am sure you would have checked the paypal documentation

https://developer.paypal.com/docs/api/overview/#make-your-first-call


I tried with the below and am getting a client authentication failed as I am entering dummy creds. 

I am sending only 1 header : Accept and the body grant_type=client_credentials

Please check if this works for you 

That's great.