Reputation: 77
I'm struggling with this from last some hours.
I'm trying to receive an access token from the API of a partner via OAuth.
There's a small mistake in it that generates this error:
"error":"invalid_request","error_description":"Missing grant type"
Here is the VBA code I'm using in MS Access:
Public Function API_MyArrow_Artikel(artikelBez) As String
Dim objHTTP As Object
Dim strHead As String, strClientId As String, strClientSecret As String, strBody As String
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
strClientId = "xxx"
strClientSecret = "xxx"
strUrl1 = "https://my.arrow.com/api/security/oauth/token"
strHead = strClientId & ":" & strClientSecret
lngADRNR = 674
objHTTP.Open "POST", strUrl1, False
objHTTP.SetRequestHeader "application", "x-www-form-urlencoded"
objHTTP.SetRequestHeader "client_id", strClientId
objHTTP.SetRequestHeader "client_secret", strClientSecret
objHTTP.SetRequestHeader "Authorization", "Basic " + Base64Encode(strHead)
'objHTTP.setRequestHeader "grant_type", "client_credentials"
objHTTP.SetTimeouts 10000, 10000, 10000, 10000 'Timeout (in milliseconds) to wait for timeout in each request phase (Resolve, Connect, Send, Receive)
objHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.Send "grant_type=client_credentials"
API_MyArrow_Artikel = objHTTP.responseText
End Function
Any sort of suggestion to resolve is really appreciated as there are only some experts of OAuth 2.0 in here.
Thanks,
Upvotes: 1
Views: 1301
Reputation: 77
I found a solution to this.
There is some error in URL which needs to be fixed by adding below code to URL:
my.arrow.com/api/security/oauth/token?grant_type=client_credentials
And secondly replacing this:
objHTTP.SetRequestHeader "application", "x-www-form-urlencoded"
To this:
objHTTP.SetRequestHeader "content-type","application/x-www-form-urlencoded"
did the Job for me.
Upvotes: 1