I would like to convert the following postman js script to julia http requests.
We will then translate to a vendor supplied programming language.
The Julia code would be used to validate the vendor supplied results
Thanks for any help
The following is a postman prerequest script (values changed)
var isoTime = new Date().toISOString();
var entitySecret = “ff26516ecb32b123456dd0f42aa5106f237a69c806”;
var partnerSecret = “77eb0f2ad699c123456cb8677452212fed9b61a3c231”;
var patientId = “1006”;
var digest = “POST\n/clinxxxx-yyyyyyy-zzzzzzzzzz/v1/resultservice/aaaaaaaaaaaaa\n”;
digest += “US\n”;
digest += isoTime + “\n”;
digest += pm.request.headers.get(“bbbb-Entity”) + “\n”;
digest += pm.request.headers.get(“bbbb-Partner”) + “\n”;
digest += pm.request.headers.get(“bbbb-Partner-Product”) + “\n”;
digest += pm.request.headers.get(“bbbb-User”) + “\n”;
digest += indtId + “\n”;
var hash = CryptoJS.HmacSHA256(digest, partnerSecret + entitySecret);
var hashHeader = CryptoJS.enc.Base64.stringify(hash);
Hey @bww00 - would you mind showing us what you have tried so far? i would suggest taking a look at the following packages to get started with:
Also, it appears that you have actual secret keys in your example code - is that an accident? With
Particularly, with HTTP.jl, check out the
post functions as well as the generic
request command. That should help get you started if you are unsure where to start.
The keys have been altered and are not the actual keys.
I will look deeper at Http.jl and JSON3.jl
For the crypto i found nettle.jl that had hmac functionality
I can connect to site and get 401 return.
Now I need to create the Hmacsha256 and base 64 encode the hash and add it to the headers as authorization
Hopefully verify the hmacsha256 and encode vs the postman example that works.
urla = “https://test12.services.xxxx.com/resultofservice/v1/resultservice/resultof”
response = HTTP.request(“POST”, urla,
[“Content-Type” => “application/json”
, “xxxX-Country” => “US”, “xxxX-Entity” => “br54976ac9c93863”,
“xxxX-zzzzzzz” => “br54903a686a9030”, “xxxX-User” => “testuser”,
“xxxX–zzzzzzz-Product” => “1.0”, “xxxX-Date” => “2021-10-13T17:52:21.527Z”,
“Authorization” => “xxxxxx”
response_text = String(response.body)
json_obj = JSON.parse()
Got it to work!!!
encoding issue was below that I found searching
For this you want to use Base64 from the standard library. First use hex2bytes to convert your string to a byte array, then base64encode to convert it back to a string:
bytes = hex2bytes(st)
Congrats @bww00 ! For posterity, may I suggest wrapping your code blocks on your comments in backticks (these things: ``) to make your code nicely formatted? This can help others who come after who might have the same question as you. Also, since you have found your solution, I’d suggest also marking your solution