About connect to API via CURL

Hi,

I am trying to connect via curl but if I do it from the command line I get an error:
curl: (60) SSL certificate problem: unable to get local issuer certificate

using the same command but in Run Curl Commands Online it works perfect, I don’t know much about this topic, can I get some help please?.

I’m using curl like this

curl -X POST -H “Content-Type:application/json” -H “Authorization:TOKEN” -d ‘{“query”:"{ boards (ids: xxxxxxxxxx){name views{name}}}"}’ “https://api.monday.com/v2

if I use -k or --insecure I only get a empty pair of curly braces.

I appreciate any help.

Regards,
Javier

Hey @jparada :wave:

Thanks for reaching out to us! I see this is your first post as well - my warmest welcome to our community. :slight_smile:

I’ve just tried using the same cURL request you’ve provided, and I didn’t face any issues using the API call. Seems like this might be related to cURL using a self-signed certificate by default when you’re trying to send the API call, and it is not recognized correctly.

From doing some quick reading up on StackOverflow and Medium, it seems like the solution is to update your php.ini file, in case you are making the cURL request through PHP. Here’s what was suggested in Medium:

Fixing cURL error 60

Let us know if this helps resolve this behavior :face_with_monocle:

-Alex

Hi @AlexSavchuk

Thanks for answering, I can solve my reported problem, what I did was the following:

Download the latest cacert.pem file from curl - Extract CA Certs from Mozilla and set the environment variable

SET CURL_CA_BUNDLE=/cacert.pem

with this I solved my problem about the error (60) SSL certificate problem.

then I had another problem sending the query, receiving a pair of empty braces as a response, then I had to escape the query, change from this:

‘{“query”:"{ boards (ids: xxxxxx){name views{name}}}"}’

to this:

“{“query”:”{ boards (ids: xxxxxx){name views{name}}}"}"

and now everything works fine.

This test with cURL has been successful, I also tried to do a test with XMLHttpRequest and I get a 200 ok response code, but I get a response:

‘{“errors”:[{“message”:“No query string was present”}],“account_id”:xxxxxxx}’

I have read here in the forum some answers that indicate that the reason for receiving this error is because the query is probably badly formed, with the experience of escaping the cURL statement you think it should be something similar, then try to escape the query with sending using XMLHttpRequest?.

I appreciate your help and if I need to open a new topic please let me know.

Regards,
Javier

@jparada

Thank you for circling back with me! I’m glad to hear this is working as expected in cURL now.

Could you please provide the code you are using to send the XMLHttpRequest? It does sounds like something is missing when you format the query, so I’m wondering if we can pinpoint the issue after seeing the code in full context, as this would help us confirm the behavior.

Thanks so much for your patience and for sharing your solution with the community as well, I’m sure this will help someone in case they run into a similar behavior.

-Alex

Hi @AlexSavchuk

Basically this is how I’m sending the request

query = ’ “{”“query”":""{boards(ids: xxxxxxx){name views{name}}}""}" ’

BEGIN SEQUENCE WITH { |o| break(o) }
xmlhttp:Open( “POST”, cUrl, .F. )
xmlhttp:setRequestHeader( ‘Content-Type’, ‘application/json’ )
xmlhttp:setRequestHeader( ‘Accept’, ‘application/json’ )
xmlhttp:setRequestHeader( ‘Authorization’, cAuth )
xmlhttp:Send( hb_jsonEncode ( query ) )

? xmlhttp:status
? cReturn := hb_ValToExp( xmlhttp:ResponseText )

RECOVER USING oErr

? cReturn := “Error!” + hb_eol() + If ( ValType( oErr ) = ‘O’, oErr:Description, oErr )

END SEQUENCE

can you see something wrong?

Regards,
Javier

Hey @AlexSavchuk

don’t waste your time anymore, I was able to figure it out, it was my fault since I was sending encoded as json.

I appreciate your help.

Regards,
Javier

@jparada

Oh haha, I was just about to post the same thing :slight_smile: Glad you were able to figure it out on your own! Thanks for providing the solution to your issue as well, that’s really helpful.

-Alex

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.