1

I need help to get authorization to connect to an API. The command line given is

curl -X GET "https://app.mysite.fr/api/v1/societe/11111111" -H "Authorization: Bearer 84dcc64aefabcdefghebcf7762752xx"

Below is my code written in VBA in ms-access

Function GetAuthorization()
    
    Dim objCurlHttp As Object
    Dim strResult As String
    Dim varReqToken As Variant
    Dim strWebServiceUrl As String
    Dim strOwnerKey As String
    Dim strQry As String
    
    strWebServiceUrl = "https://app.mysite.fr/api/v1/societe/11111111"
    strOwnerKey = "84dcc64aefabcdefghebcf776275xx"
    
    Set objCurlHttp = CreateObject("MSXML2.serverXMLHTTP")
                                                          
    
    With objCurlHttp
        .Open "GET", strWebServiceUrl, False
        
        .SetRequestHeader "cache-control", "no-cache"
        .SetRequestHeader "Content-type", "application/json"
        .SetRequestHeader "Content-type", "Accept"
        .SetRequestHeader "Authorization", "Bearer " + strOwnerKey
        .Send
        
        strResult = .ResponseText
        Debug.Print strResult
    End With
    
    Set objCurlHttp = Nothing
    
End Function

This result is

? GetAuthorization() Unauthorized

Thanks a lot in advance.

1
  • Why all the weird headers? The curl code doesn't have those. Try only setting the authorization header. And ideally, you'd switch to using WinHTTP, MSXML2.serverXMLHTTP has some oddities due to sharing config/cookies with Internet Explorer. Commented Jun 8, 2022 at 10:01

1 Answer 1

2

You don't reveal the documentation, but I seriously doubt that it states the Accept header as shown. So try:

        .Open "GET", strWebServiceUrl, False
        
        .SetRequestHeader "Content-type", "application/json"
        .SetRequestHeader "Accept", "application/json"
        .SetRequestHeader "Authorization", "Bearer " + strOwnerKey
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it woks i got the authorization, but it is HTML and not json

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.