First - I admit I'm in over my head on this. I know how do do SOAP calls, but this REST stuff is all new to me.
I have a Python script that calls our company CRM and it's working as it should. I need to convert this over to VB6 (or even VB .net), but I can't seem to figure out just how to get the thing to work. I know I'm talking to the CRM, but it keeps giving me an error (probably because I'm sending wrong data).
Here's the working Python Script (NOTE: the authtoken variable comes from another script that's working fine):
fetchurl = https://URL-TO-THE-REST-FUNCTION
searchheaders = {
'accept': 'application/json; charset=utf-8',
'Content-Type': 'application/json;charset=utf-8',
'Authorization': 'Bearer ' + authtoken
}
payloadstring = {
"request": {
"companyNumber": 1,
"operatorInit": "user",
"operatorPassword": "Password",
"inputString": "TEST_STRING"
}
}
payload = json.dumps(payloadstring)
fetchresponse = requests.post(fetchurl,
headers=searchheaders,
data=payload,
verify=False)
apiResponse = fetchresponse.content
print(json.loads(apiResponse))
And here's what I have so far in VB6
Dim sURL As String
Dim strXML As String
Dim xmlhttp As MSXML2.xmlhttp
Set xmlhttp = New xmlhttp
Open "D:\API\token.dat" For Input As #1
Line Input #1, token$
Close #1
Data$ = "'{" & Chr$(34) & "request" & Chr$(34) & ": {"
Data$ = Data$ & Chr$(34) & "companyNumber" & Chr$(34) & ": 1,"
Data$ = Data$ & Chr$(34) & "operatorInit" & Chr$(34) & ": " & Chr$(34) & "user" & Chr$(34) & ","
Data$ = Data$ & Chr$(34) & "operatorPassword" & Chr$(34) & ": " & Chr$(34) & "password" & Chr$(34) & ","
Data$ = Data$ & Chr$(34) & "inputString" & Chr$(34) & ": " & Chr$(34) & "Work, Damnit!" & Chr$(34) & "}}'"
sURL = "https://URL-TO-The-REST-FUNCTION"
strXML = Data$
xmlhttp.open "POST", sURL, True
xmlhttp.setRequestHeader "'accept':", "'application/json; charset=utf-8'"
xmlhttp.setRequestHeader "'Content-Type':", "'application/json;charset=utf-8'"
xmlhttp.setRequestHeader "'Authorization': 'Barer '", token$ & "'"
xmlhttp.send strXML
The Data$ looks like this:
'{"request": {"companyNumber": 1,"operatorInit": "user","operatorPassword": "password","inputString": "Work, Damnit!"}}'
I know I'm at least talking to the server, the returned header looks like this:
Date: Fri, 04 Mar 2022 20:28:03 GMT
Content-Type: application/json
Content-Length: 24
Connection: keep-alive
x-frame-options: SAMEORIGIN
x-transaction-id: 5dfcb31d-9d85-94ce-b6cd-81416aaab4c2
strict-transport-security: max-age=31536000; includeSubDomains
www-authenticate: Bearer realm="IONAPI"
server: ionapi-2022.02.00.995424
x-envoy-decorator-operation: ionapi_gateway
And the response I'm getting is
{"error":"Unauthorized"}
(I know the username/password I'm plugging in are good)
Any help would be appreciated. Thanks