Hello,
I am trying to integrate creating shipping labels in my Access application. I have good documentation from the carrier and I made the auth request work using the Postman software, as can be seen here:
https://i.imgur.com/9X93SgH.png
https://i.imgur.com/cTcPyWU.png
https://i.imgur.com/bKyv2b1.png
I am trying to replicate this using VBA in Access, with this code:
Code:
Public Sub PPLAuth()
Dim HTTPreq As Object
Dim URL As String
Dim strBody As String
Dim JSON As Object
Set HTTPreq = CreateObject("WinHttp.WinHttpRequest.5.1")
URL = "https://api-dev.dhl.com/ecs/ppl/myapi2/login/getAccessToken"
HTTPreq.Open "POST", URL, False
HTTPreq.SetRequestHeader "content-type", "application/x-www-form-urlencoded"
HTTPreq.SetRequestHeader "user-agent", "PostmanRuntime/7.32.2"
HTTPreq.SetRequestHeader "accept", "*/*"
HTTPreq.SetRequestHeader "cache-control", "no-cache"
HTTPreq.SetRequestHeader "postman-token", "52edacc2-5d59-41d4-beec-5f5448e5f92e"
HTTPreq.SetRequestHeader "host", "api-dev.dhl.com"
HTTPreq.SetRequestHeader "accept-encoding", "gzip, deflate, br"
HTTPreq.SetRequestHeader "connection", "keep-alive"
HTTPreq.SetRequestHeader "content-length", "109"
strBody = "{""grant_type"": ""client_credentials"", ""scope"": ""myapi2"", ""client_id"": ""zzzzzz"", ""client_secret"": ""xxxxxxx""}"
Debug.Print strBody
HTTPreq.send strBody
Set JSON = JsonConverter.ParseJson(HTTPreq.responseText)
Debug.Print HTTPreq.responseText
Set HTTPreq = Nothing
Set JSON = Nothing
End Sub
But unfortunately, here I don't get a 200 OK response. I get this:
Code:
{"status":400,"title":"Bad Request","detail":"One or more required form parameters are missing."}
Since it works in the Postman app, it must be something VBA related that I am not formatting correctly. Can you please help me which part is incorrect in VBA?
Thanks!
Tomas