One of my service providers changed their APIs and I need to generate a key rather than using username and password. They allow the output to be in XML, but are requiring the credentials to be passed in Curl. It's easy enough in their dev environment, and here is what they tell me I need as a command:
curl -X POST "https://api.XXXXX.com/api/v1/users/login.xml" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"user\":{\"email\":\"XXXXX\",\"password\":\"XXXXX\",\"remember_me\":\"true\"}}"
I did a fair amount of research, and came up with passing information through either WinHTTP or MSXML2 server object. The GET works like a charm to return XML, but can't seem to pass information through the post. Here's what I've done so far:
szData="{\" & Chr(34) & "user\" & Chr(34) & ":{\" & Chr(34) & "email\" & Chr(34) & ":\" & Chr(34) & "XXXXXX\" & Chr(34) & ",\" & Chr(34) & "password\" & Chr(34) & ":\" & Chr(34) & "XXXXXX\" & Chr(34) & ",\" & Chr(34) & "remember_me\" & Chr(34) & ":\" & Chr(34) & "true\" & Chr(34) & "}}"
if bTest then fpTest.WriteLine(szData)
Set objToken = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
With objToken
Call .Open("POST", "https://api.XXXXXX.com/api/v1/users/login.xml", False)
Call .SetRequestHeader("accept", "application/json")
Call .SetRequestHeader("Content-Type", "application/json")
Call .Send(Chr(34) & szData & Chr(34))
End With
if bTest then fpTest.Write(objToken.responseText)
Here's what was written to the output file:
{\"user\":{\"email\":\"XXXXXX\",\"password\":\"XXXXXX\",\"remember_me\":\"true\"}}
<?xml version="1.0" encoding="UTF-8"?>
<Errors>
<user type="array">
<user>can't be blank</user>
</user>
</Errors>
Using the syntax using the Chr(34) for the quote marks got me in the door, but not sure how to get any further.
I am open to any suggestions. This is part of a large legacy system (about 20 years old), so I can't rewrite in PHP or do anything drastic. The good news is I have access to the web server (Windows Server 2012 R2).
Hoping for responses other than "you're screwed".
Rob Bristow
Classic Club Solutions, LLC