Connecting to an IE window to send API calls (XMLHTTP Requests)

In the below AutoHotkey Podcast we discussed how to send API calls from an active IE window.  A subscriber asked me to share the code so below is the example code I mentioned in the recording

Connecting to active IE window and sending an API call

Payload={"filter":{"acctId":"44XXXX","serviceId":[],"msgFormat":[],"status":[1,2,192],"received":{"From":"1970-01-01T00:00:00.000Z","To":"1970-01-01T00:00:00.000Z"},"modified":{"From":"1970-01-01T00:00:00.000Z","To":"1970-01-01T00:00:00.000Z"},"originator":"","threadId":[],"eTo":[],"excludeMessages":[],"extraSql":"AND msg.thread_id IS NULL"},"options":{"doNotCallFlag":true,"contactId":true,"deepContactIdSearch":true,"offset":0,"limit":0,"orderColumn":"\"tdsReceived\"","orderDirection":"DESC"}}

oWindow := ComObject(9, ComObjQuery(WBGet(), "{332C4427-26CB-11D0-B483-00C04FD90119}", "{332C4427-26CB-11D0-B483-00C04FD90119}"), 1)
MsgBox % IsObject(oWindow)

msgbox % oWindow.title
xhr := oWindow.XMLHttpRequest()
xhr.open("POST", "https://800link.com/WebService/SSL/I800LinkVmMsgs.asmx/Load",1)
xhr.setRequestHeader("Content-Type", "application/json")
xhr.send(Payload)
while(xhr.ReadyState!=4) ;Wait for it to complete
  Sleep,50
msgbox % "response: " xhr.response
msgbox % "body: " xhr.responseBody
msgbox % "status: " xhr.Status

 

Comments are closed.