From postman to libcurl

Hi all,

I am less familiar with libcurl, but working with json content works quite well. But now I need to request an access token in form-data and I’m struggling with the syntax. If Ipaste the code below into Postman, it will works fine. But I am not able to put this into correct Clarion code. Does anyone have a suggestion or example?

 curl --location 'https://api.mysite.com/token' \
--header 'Cookie: last_account_activity=1741340252' \
--form 'client_id="MyID"' \
--form 'client_secret="MySecret"' \
--form 'grant_type="client_credentials"
    curl.addHttpHeader('Content-Type: application/form-data')
    curl.addHttpHeader('Cookie: last_account_activity=1741340252')
    curl.setHttpHeaders()
    curl.FormAdd('client_id',BUZ:clientId)
    curl.FormAdd('client_secret',BUZ:clientSecret)
    curl.FormAdd('grant_type','client_credentials')
    cfres = curl.FormPost(CLIP(BUZ:url)&'/token')
    IF res = CURLE_OK
        MESSAGE('OK')

I’ll get a reponse OK but how to get received data. Should be a json like this:

{
    "token_type": "Bearer",
    "expires_in": 3600,
    "access_token": "eyJ0eXAiOiJKV1QiLCJhbGQbtSVNdg7bT9PIECGA2maMBNCLz1MqiUNvNiuMQ"
}

Regards,

Henk

Look at the FormPost method declaration.

Hi Mike,

Thanks for your hint. It brings me to the github examples.

Now I use:

curl.FormPostStr(CLIP(buz:url)&'/token',respString)

and the response is coming into respString.

Regards,

Henk

Have you tried CapeSoft’s curl to NetTalk conversion?

https://www.capesoft.com/curlcode

Hes using Libcurl, not NetTalk.

I understand that but he had curl code that he wanted to change to Clarion code and I was thinking the Capesoft converter might give him more examples to look at. Sorry it didn’t meet your expectations.

By the way, FormPost is considered an outdated approach, MimePost is recommended.