Need help to make a API Soap script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
PerGerner
Posts: 1
Joined: 28 May 2022, 07:56

Need help to make a API Soap script

Post by PerGerner » 28 May 2022, 08:49

Is there anyone who can help me create an AHK script that connect via API SOAP. I can do well via REST, but I have never tried SOAP and am new to API.

There is good documentation at the Provider, but since I am new, I need help.

https://www.e-conomic.com/developer/documentation

I would be very grateful with help for an example of GET, and one on POST in SOAP API for this provider.

examples:
https://api.e-conomic.com/secure/api1/EconomicWebService.asmx?op=Project_GetAll

https://api.e-conomic.com/secure/api1/EconomicWebService.asmx?op=Project_Create

WSDL:
https://api.e-conomic.com/secure/api1/E ... -UEALw_wcB

Code: Select all

#SingleInstance,Force
FileEncoding, UTF-8

;MsgBox %A_Language% %the_language%  ; Display the language name.



;**************************************


API_Secret:="demo"
API_GrantToken:="demo"




; put your key value pairs in this object & it will take care of prepending ? and & for you
;QS:=QueryString_Builder({<ConnectWithToken xmlns:"AutoHotkey","format":"xml","ia":"web"})

; put your key value pairs in this object & it will take care of prepending ? and & for you
QS:=QueryString_Builder({"Content-Type":"application/soap+xml"})

Msgbox QS= %QS%

;********************************************
Connect_With_Token =
(
<ConnectWithToken xmlns="http://e-conomic.com>
<token>%API_GrantToken%</token>
<appToken>%API_Secret%</appToken>
</ConnectWithToken>
)
Msgbox TOKEN= %Connect_With_Token%

;******************************



Endpoint:="https://api.e-conomic.com//secure/api1/EconomicWebService.asmx HTTP/1.1"

Msgbox Endpoint= %Endpoint%

HTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1") ;Create COM Object
HTTP.Open("POST", Endpoint  Connect_With_Token QS) ;GET & POST are most frequent, Make sure you UPPERCASE

;***********Provide Headers*******************
;;HTTP.SetRequestHeader("X-AppSecretToken",API_Secret) ;Authorization in the form of a Bearer token
;;HTTP.SetRequestHeader("X-AgreementGrantToken",API_GrantToken) ;Authorization in the form of a Bearer token
;;HTTP.SetRequestHeader("Content-Type","application/soap+xml")

;********************QueryString Builder Function***********************************
QueryString_Builder(kvp){
for key, value in kvp
  queryString.=((A_Index="1")?(url "?"):("&")) key "=" value
return queryString
}


Payload =
( 
<?xml version="1.0" encoding="utf-8"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <Account_GetAll xmlns="http://e-conomic.com"/>
    </Body>
</Envelope>
)


Msgbox %Payload%


HTTP.Send(Payload) 

HTTP.WaitForResponse() ;Wait for response before moving forward.  Use with SetTimeouts above ;https://www.autohotkey.com/boards/viewtopic.php?f=74&t=9136
Msgbox % HTTP.ResponseText
Attachments
soaptest_2.ahk
(2.13 KiB) Downloaded 12 times

Return to “Ask for Help (v1)”