troubleshooting Question

curl to HTTP request VBA

Avatar of Gontran Harvey
Gontran Harvey asked on
JSONVBA
4 Comments1 Solution2720 ViewsLast Modified:
Hi, I have a curl that I want to send to API. (ACT! CRM).
The GET request work's with the code below:

Here the curl:
curl -X GET --header 'Accept: application/json' --header 'Authorization: Bearer xxxxxxxxxxxx' 'http://pc-gontran/Act.Web.API/api/Contacts'
Here the code:
'*********************************************************************************
    oXMLHTTP.Open "GET", "http://pc-gontran/Act.Web.API/api/Contacts", False
   oXMLHTTP.setRequestHeader "Content-Type: ", "application/json" ''Content-Type: application/json'
   oXMLHTTP.setRequestHeader "Accept: ", "application/json"
   oXMLHTTP.setRequestHeader "Authorization: ", "Bearer " & strBearer
   
    oXMLHTTP.Send
Do Until oXMLHTTP.ReadyState = 4
        DoEvents
    Loop
   
    Me.txt_Status = oXMLHTTP.Status
    If oXMLHTTP.Status = 200 Then
        strHTML = oXMLHTTP.ResponseText
        Me.txt_Response = strHTML
    End If
'*********************************************************************************

Now when I try the same whit this curl:
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Bearer xxxxxxxxxxxxxxx' -d '{}' 'http://pc-gontran/Act.Web.API/api/Contacts'

Whit this code:
'*********************************************************************************
    oXMLHTTP.Open "POST", "http://pc-gontran/Act.Web.API/api/Contacts", False
   oXMLHTTP.setRequestHeader "Content-Type: ", "application/json" ''Content-Type: application/json'
   oXMLHTTP.setRequestHeader "Accept: ", "application/json"
   oXMLHTTP.setRequestHeader "Authorization: ", "Bearer " & strBearer
   
    oXMLHTTP.Send ("'{}'")
Do Until oXMLHTTP.ReadyState = 4
        DoEvents
    Loop
   
    Me.txt_Status = oXMLHTTP.Status
    If oXMLHTTP.Status = 200 Then
        strHTML = oXMLHTTP.ResponseText
        Me.txt_Response = strHTML
    End If
'*********************************************************************************
When I try the curl in the API UI, it's working, but not in VBA (i'm in Access buy the way), I received a 400 error (bad server request).

Do you know what i,m doing wong?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros