gosub, define_keys gosub, create_a_case gosub, get_template exitapp define_keys: API_key := "API_MAIN_KEY" gateway_url := "/v1/" protocol := "https://" host_URL := "rms-world-check-one-api-pilot.thomsonreuters.com" API_secret := "API_SECRET_KEY" return create_a_case: base_URL := protocol host_URL gateway_url . "cases" GMT_time := % getGMT(-2) body = ( { "secondaryFields": [], "entityType": "INDIVIDUAL", "customFields": [], "groupId":"0a3687cf-673a-134c-99f3-522b0000168a", "providerTypes": [ "WATCHLIST" ], "name": "sangala" } ) ;; or what-ever group ID is retrieved with top_lvl_call datatosign := "(request-target): post " gateway_url "cases`n" . "host: " host_URL "`n" . "date: " GMT_time " GMT`n" . "content-type: application/json`n" . "content-length: " strlen(body) "`n" . body HMAC := % calculate_HMAC_256_64base(datatosign,API_secret) H_authorisation := "Signature keyId=" Chr(34) API_key Chr(34) "\`,algorithm=" Chr(34) "hmac-sha256" Chr(34) "`,headers=" Chr(34) "(request-target) host date content-type content-length" Chr(34) "`,signature=" Chr(34) HMAC Chr(34) H_date := GMT_time " GMT" WinHTTP := ComObjCreate("WinHTTP.WinHttpRequest.5.1") WinHTTP.Open("POST", base_URL,false) WinHTTP.SetRequestHeader("Date",H_date) WinHTTP.SetRequestHeader("Authorization",H_authorisation) WinHTTP.SetRequestHeader("Content-Length",strlen(body)) ;WinHTTP.SetRequestHeader("Content-Type","application/json") ;; return error 415 WinHTTP.SetRequestHeader("Content-Type","application/x-www-form-urlencoded") WinHTTP.send(body) WinHTTP.waitforresponse(5) gosub, msgbox_full_response return ; RESPONSE // create_case /* BODY: STREAM: TEXT: STATUS: 400 STATUS TEXT: Bad Request HEADERS: Date: Fri, 18 Jan 2019 14:50:09 GMT Transfer-Encoding: chunked Server: "" X-Application-Context: application X-Cnection: close */ get_template: base_URL := protocol host_URL gateway_url "groups/" . "0a3687cf-673a-134c-99f3-522b0000168a" ;; or what-ever group ID is retrieved with top_lvl_call . "/CaseTemplate" GMT_time := % getGMT(-2) datatosign := "(request-target): get " gateway_url "groups/0a3687cf-673a-134c-99f3-522b0000168a/CaseTemplate`n" . "host: " host_URL "`n" . "date: " GMT_time " GMT" HMAC := % calculate_HMAC_256_64base(datatosign,API_secret) DQ := Chr(34) H_authorisation := "Signature keyId=" DQ API_key DQ "\`,algorithm=" DQ "hmac-sha256" DQ "`,headers=" DQ "(request-target) host date" DQ "`,signature=" DQ HMAC DQ H_date := GMT_time " GMT" WinHTTP := ComObjCreate("WinHTTP.WinHttpRequest.5.1") WinHTTP.Open("GET", base_URL,false) WinHTTP.SetRequestHeader("Date",H_date) WinHTTP.SetRequestHeader("Authorization",H_authorisation) WinHTTP.SetRequestHeader("Content-Type","application/x-www-form-urlencoded") WinHTTP.send() WinHTTP.waitforresponse(5) Result := WinHTTP.ResponseText Status := WinHTTP.Status gosub, msgbox_full_response return msgbox_full_response: v1 := WinHTTP.ResponseBody v2 := WinHTTP.ResponseStream v3 := WinHTTP.ResponseText v4 := WinHTTP.Status v5 := WinHTTP.StatusText v6 := WinHTTP.GetAllResponseHeaders msgbox % "BODY: " v1 "`nSTREAM: " v2 "`nTEXT: " v3 "`nSTATUS: " v4 "`nSTATUS TEXT: " v5 "`nHEADERS: " v6 return ; RESPONSE // get_template /* BODY: STREAM: TEXT: [] STATUS: 404 STATUS TEXT: Not Found HEADERS: Cache-Control: no-cache, no-store, max-age=0, must-revalidate Date: Tue, 15 Jan 2019 12:47:51 GMT Pragma: no-cache Transfer-Encoding: chunked Content-Type: application/json;charset=UTF-8 Expires: 0 Server: "" X-Application-Context: application X-XSS-Protection: 1; mode=block X-Frame-Options: DENY X-Content-Type-Options: nosniff */ ;Functions getGMT(deduct) { B_NOW := A_Now B_NOW += deduct,HH B_NOW += +1,seconds ;; because HMAC via powershell and clipboard is slow FormatTime, TimeString, %B_NOW%, ddd, dd MMM yyyy HH:mm:ss r := TimeString return r } calculate_HMAC_256_64base(input,key) { store_clip := clipboard raw_double_quote_ahk = `" raw_double_quote_PS = \" inp := regexreplace(input,"(" raw_double_quote_ahk ")","" raw_double_quote_PS "") ;; submitting script to powershell this way deletes double spaces, hence this regex.. inp := regexreplace(inp,A_Space,"A_SP8CE") clipboard := ps_script= ( $message = '%inp%' $message = $message.replace('A_SP8CE',' ') $secret = '%key%' $hmacsha = New-Object System.Security.Cryptography.HMACSHA256 $hmacsha.key = [Text.Encoding]::ASCII.GetBytes($secret) $signature = $hmacsha.ComputeHash([Text.Encoding]::ASCII.GetBytes($message)) $signature = [Convert]::ToBase64String($signature) | clip ) RunWait, PowerShell.exe %ps_Script%,,hide clipwait,1 r := clipboard r := regexreplace(r,"`n") ;; powershell is placing new line after output for some reason r := regexreplace(r,"`r") clipboard := store_clip return r }