Help with passing client_id & client_secrete in POST for access token

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
Shakeer
Posts: 1
Joined: Thu Dec 29, 2022 8:02 pm

Help with passing client_id & client_secrete in POST for access token

Post 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.
Attachments
Capture.PNG
Capture.PNG (9.83 KiB) Viewed 2713 times
Scott Klement
Site Admin
Posts: 635
Joined: Sun Jul 04, 2021 5:12 am

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

Post 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.
Post Reply