Page 1 of 1

Help with passing client_id & client_secrete in POST for access token

Posted: Thu Dec 29, 2022 9:35 pm
by Shakeer
Hi,

Can you please help me in fetching the access token while posting the below cURL request through RPG. Im getting response in postman, but missing something while coding in RPG. Attached the postman snippet. Below is the curl
----------------------------------------------------------------------------------------------------------------------------
curl --location --request POST '<URL>' \
--form 'grant_type=client_credentials' \

--form 'client_id=<Client_Id>' \
--form 'client_secret=<Client_Secret>'
----------------------------------------------------------------------------------------------------------------------------
Below is the RPG code snipped trying to invoke http_req()

form_data = 'grant_type=client_credentials'
+ '&' + 'client_id=' + '<Clinet_Id>'
+ '&' + 'client_secret=' + '<Client_Secret>';

@url = '<URL>';

Sav_Rc = http_Req('POST'
:@url
:*omit
:Output
:*omit
:%trim(form_data)
:'application/x-www-form-urlencoded');

Tried replacing content-type above with multipart/form-data,but, no response.

Re: Help with passing client_id & client_secrete in POST for access token

Posted: Fri Dec 30, 2022 10:27 pm
by Scott Klement
You haven't provide much information aside from that it's not working for you.

Have you tried using HTTPAPI's tools for creating form data, instead of building the form manually?

Also, your Postman example is using form-data, but your HTTPAPI example is using x-www-form-urlencoded. I don't just mean the content-type parameter, but the way you are encoding the data is urlencoded rather than form-data. Does that matter?

Please understand that every API is different, and you haven't provided any details of what this one requires. All we know is what you've posted that doesn't work -- and we don't even know what happens when you try it. A little more detail would be helpful.