2

I have the following JSON POST sample code which I am trying to convert to VBA for Excel:

POST /services/shipper/orders HTTP/1.1
Content-Type: application/json
User-Agent: Mozilla 5.0
Host: qa.etowertech.com
X-WallTech-Date: Tue, 06 Jan 2018 21:20:27 GMT
Authorization: WallTech test5AdbzO5OEeOpvgAVXUFE0A:79db9e5OEeOpvgAVXUFWSD

Here is the code I came up with:

With JsonHTTP
             .Open "POST", "http://qa.towertech.com/services/shipper/orders", False
             .setRequestHeader "RequestName", "application/json"
             .setRequestHeader "Accept", "application/json"
             .setRequestHeader "User-Agent", "Mozilla 5.0"
             .setRequestHeader "Host", "qa.etowertech.com"
             .setRequestHeader "X-WallTech-Date", "Tue, 06 Jan 2018 21:20:27 GMT"
             .setRequestHeader "Authorization", "WallTech test5AdbzO5OEeOpvgAVXUFE0A:79db9e5OEeOpvgAVXUFWSD"
             .send (body)
End With

I wasn't sure where the POST /services/shipper/orders HTTP/1.1 input should go

I keep getting this response:

{
  "status": "Failed",
  "errors": [
    {
      "code": 100004,
      "message": "System internal error"
    }
  ],
  "data": null
}

EDIT:

The current response I'm getting:

{
  "status": "Failed",
  "errors": [
    {
      "code": 401,
      "message": "Authorization information is invalid."
    }
  ],
  "data": null
}

I just figured I missed out on the Signature (see below instruction) but wasn't sure how to render it and where it goes exactly in the request?

X-WallTech-Date

EEE, dd MMM yyyy HH:mm:ss zzz

Authorization

WallTech <Access Token>:<Base64 Encoded HMAC SHA-1 Hash>

Signature String

<HTTP Verb> + "\0x000A" + <X-WallTech-Date Header> + "\0x000A" + <Full URL>
13
  • Check if this line .setRequestHeader "RequestName", "application/json" be: .setRequestHeader "Content-Type", "application/json" -- and if the request needs to be sent via HTTPS, not just HTTP --- and if Authorisation header you're sending is correct (server might be expecting the string after WallTech to be base64 encoded). I think /services/shipper/orders should go in the URL (as you've done) so that's the correct, but you should also check if the JSON you're sending in request's body is valid.
    – chillin
    Commented Jan 7, 2018 at 8:47
  • I would also comment out or delete this line from your code/the request you're sending: X-WallTech-Date: Tue, 06 Jan 2018 21:20:27 GMT
    – chillin
    Commented Jan 7, 2018 at 8:49
  • body is not shown being defined or created.
    – S Meaden
    Commented Jan 7, 2018 at 11:30
  • @chillin That worked out! I did miscopy the Content-Type for RequestName. Thank you!
    – Dan
    Commented Jan 8, 2018 at 12:19
  • 1
    @omegastripes Yes surely, just posted the answer, hope it makes it all clear!
    – Dan
    Commented Mar 14, 2018 at 11:29

1 Answer 1

1

Here's the solution:

url = "http://qa.towertech.com/services/shipper/orders"
token = "xxxxxx" ' API token goes here
auth = Base64_HMACSHA1("POST" & Chr(10) & timestamp & Chr(10) & url, key)

With JsonHTTP
             .Open "POST", url, False
             .setRequestHeader "RequestName", "application/json"
             .setRequestHeader "Accept", "application/json"
             .setRequestHeader "User-Agent", "Mozilla 5.0"
             .setRequestHeader "Host", "qa.etowertech.com"
             .setRequestHeader "X-WallTech-Date", timestamp
             .setRequestHeader "Authorization", "Walltech " & token & ":" & auth
             .send (body)
End With

The problem was the secret key was missing from the Base64 function so the auth string was incorrectly encoded

Hope this helps anyone else having the same!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.