BAsic Oauth2 API call?

peskywinnets

Registered User.
Local time
Today, 12:55
Joined
Feb 4, 2014
Messages
578
Does anyone have the 'chops' to be able to arrange the following short snippet of code into VBA...


POST /auth/connect/token HTTP/1.1
Host: sandbox.parcel2go.com
User-Agent: insomnia/5.14.6
Content-Type: application/x-www-form-urlencoded
Accept: */*
grant_type=client_credentials
&scope=public-api%20payment
&client_id=<client_id>
&client_secret=<client_secret>



...I have my clientID & Secret key, but struggling to deploy. The response (once a successful call is made should be a token)...


{
"access_token": "435435435345SDFS...",
"expires_in": 7200,
"token_type": "Bearer"
}



Reference - https://www.parcel2go.com/api/docs/articles/quickstart.html

Many thanks in anticipation :)[/code]
 
Did you try to use the HttpRequest Class object?
 
Did you try to use the HttpRequest Class object?

I've got several APIs working in access, but the headers & string formation is always a challenge ...every time I'm faced with a new one, same issues...and no examples for VBA,
 
What do you have? setting headers is simple:
Code:
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
req.setRequestHeader "User-Agent", "insomnia/5.14.6"
req.setRequestHeader "Host", "sandbox.parcel2go.com"

(Before sending)
 
Actually, I got lucky, within about 30 mins of trying different permutations, this code actually works...

Public Sub Parcel2Go_GetAccessToken()

Set XMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")
ClientID = "aaabbbcccdddeeeff" ' this isn't my real ClientID :-)
ClientSecret = "xxyyxzz" ' this isn't my real ClientSecret :-)

XMLHTTP.Open "POST", "https://sandbox.Parcel2Go.com/auth/connect/token"
XMLHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
XMLHTTP.setRequestHeader "Authorization", "Basic "
body = "&grant_type=client_credentials&scope=public-api%20payment&client_id=" & ClientID & "&client_secret=" & ClientSecret & ""

XMLHTTP.send body

Debug.Print XMLHTTP.responseText

end sub



this above code/call returns this...

{"access_token":"zp4Rjlbc0jaRySzRbdKb1sPJdqZWpx6s8SBgbeGrR5o","expires_in":7200,"token_type":"Bearer","scope":"payment public-api"} ' (access_token string has been edited by me for security)


...the reason I asked initially, is sometimes I've spent several evenings trying to get the right permutations, so 30 mins is a result :-)
 

Users who are viewing this thread

Back
Top Bottom