VBA Authorization oauth2 API
Asked Answered
F

0

6

Been stuck on this for a few days now. Trying to obtain access token from an API with oauth2 authentication.

But I keep getting '401 Unauthorized', "Full authentication is required'

My gues is i'm doing something wrong with the

 .SetRequestHeder "Authorization", "basic " + (base64 encoded)

Here's the code so far: (worked with another API)

Username = "myusername"
Password = "myclientsecret"

PasswordnUsername = Password & ":" & Username

    argumentString = "?grant_type=password&username=myusername&password=mypassword"

Set xmlhttp = CreateObject("MSXML2.XMLHTTP.6.0")
    xmlhttp.Open "POST", "https://api.url/partner/oauth/token", False
    xmlhttp.SetRequestHeader "Authorization", "basic " + mdl_API_MB_ACCESS_TOKEN.Base64Encode(PasswordnUsername)
    xmlhttp.SetRequestHeader "x-api-key", "myxapicode"
    xmlhttp.Send (argumentString)
Fend answered 30/5, 2018 at 17:39 Comment(1)
Solved, api key provided by the supplier was wrong. eye-rollerFend

© 2022 - 2024 — McMap. All rights reserved.