KBr
KBr

Reputation: 139

POST to get Trustpilot API access token challenges

I have the following script that seems to be fine but it returns the following

{"reason":"Unknown grant_type"}

http://apps.trustpilot.com/authentication

I used one of the public functions for generating the Base 64 encode and it appears to be working per the response.write noted below. From the documentation link referenced, do you see what I may be missing? I am confident I have the correct key, secret, username and password. Am I processing the grant type payload properly?

Here is VBScript code:

<%
Dim consumerKey,consumerSecret,EndPoint,Payload,myCstr,myAuth
consumerKey = "XXXX"
consumerSecret = "YYYY"
EndPoint = "https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/accesstoken"
Payload = "grant_type=password&[email protected]&password=pass28"
myCstr = Base64_Encode(consumerKey & ":" & consumerSecret)
myAuth = "Basic "&myCstr
response.write(Endpoint & "?" & Payload & "<br>")    
response.write(myAuth)
Dim xmlhttp 
Set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST",EndPoint & "?" & Payload,false    
'this code not sure if I need - xmlhttp.setRequestHeader "User-Agent","HTTP/1.1"
xmlhttp.setRequestHeader "Authorization", myAuth
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send
Response.write xmlhttp.responseText
%>

Upvotes: 2

Views: 3144

Answers (1)

KBr
KBr

Reputation: 139

Per comment made (thank you, I am a newbie), here is how I got it to work:

I had originally missed the xmlhttp.responsetext and prior to that was getting no response at all, figured I would share anyways at this point in case others run into issues like I spent hours figuring out!

<%
Dim consumerKey,consumerSecret,myCstr    
consumerKey = "XXXX"
consumerSecret = "YYYY"
EndPoint = "https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/accesstoken"
Payload = "grant_type=password&[email protected]&password=pass28"
myCstr = Base64_Encode(consumerKey & ":" & consumerSecret)
myAuth = "Basic "&myCstr
response.write(Endpoint & "?" & Payload & "<br>")    
response.write(myAuth)
Dim xmlhttp 
Set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST",EndPoint,false    
'xmlhttp.setRequestHeader "User-Agent","HTTP/1.1"
xmlhttp.setRequestHeader "Authorization", myAuth
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send(Payload)
Response.write xmlhttp.responseText
%>

Upvotes: 2

Related Questions