Passing a variable in a REST GET command Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jarhead
Posts: 149
Joined: 09 Sep 2020, 12:43

Passing a variable in a REST GET command

Post by jarhead » 26 Jan 2022, 15:23

The following works...

Code: Select all


req := ComObjCreate("Msxml2.XMLHTTP")
req.open("GET", "https://mysite/_api/Web/Lists/GetByTitle('My Title')/items?$select=id,Title,Facility,SSN,Last_Name,NewColumn1,Urgent ne '' and startswith(Title, '20211215-123019')", false)
req.SetRequestHeader("Content-Type", "application/json;odata=verbose")
req.send()
clipboard := req.ResponseText
ClipWait, 1

MsgBox % clipboard
When I attempt to pass 20211215-123019 as a variable, it fails...

I copy the number to the clipboard prior to running and confirm the number is indeed on my clipboard using a MsgBox.

Code: Select all


Ltitle := clipboard

req.open("GET", "https://mysite/_api/Web/Lists/GetByTitle('My Title')/items?$select=id,Title,Facility,SSN,Last_Name,NewColumn1,Urgent ne '' and startswith(Title, '%Ltitle%')", false)

I'm sure it has something to do with the '' and %% but I've tried adding additional " and ' with no luck. Thanks!

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: Passing a variable in a REST GET command

Post by amateur+ » 26 Jan 2022, 16:46

Code: Select all

req := ComObjCreate("Msxml2.XMLHTTP")
req.open("GET", "https://mysite/_api/Web/Lists/GetByTitle('My Title')/items?$select=id,Title,Facility,SSN,Last_Name,NewColumn1,Urgent ne '' and startswith(Title, '20211215-123019')", false)
req.SetRequestHeader("Content-Type", "application/json;odata=verbose")
req.send()
ResponseTimeMax := 4000
while ((Req.readyState != 4) && (A_index < ResponseTimeMax // 100))  
    sleep 100
clipboard := (Req.readyState = 4)   ; Ok
            ? Req.responseText ; Ok
            : "No answer in " . ResponseTimeMax . " ms."
ClipWait, 1
MsgBox % clipboard
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

jarhead
Posts: 149
Joined: 09 Sep 2020, 12:43

Re: Passing a variable in a REST GET command

Post by jarhead » 26 Jan 2022, 17:01

Thanks for the response checking addition. Any idea why the variable causes the GET request to fail?

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: Passing a variable in a REST GET command

Post by amateur+ » 26 Jan 2022, 17:12

Dunno. Maybe you need this: viewtopic.php?p=379780#p379780
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

jarhead
Posts: 149
Joined: 09 Sep 2020, 12:43

Re: Passing a variable in a REST GET command  Topic is solved

Post by jarhead » 27 Jan 2022, 14:36

Making it harder than I needed to... this works.

Code: Select all


Ltitle := clipboard

url := "https://mysite/_api/Web/Lists/GetByTitle('My Title')/items?$select=id,Title,Facility,SSN,Last_Name,NewColumn1,Urgent ne '' and startswith(Title, '" . Ltitle . "')"

req.open("GET", url, false)


amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: Passing a variable in a REST GET command

Post by amateur+ » 27 Jan 2022, 14:57

Oh, sorry, didn't noticed that bug to fix it. Congratulations!
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: Passing a variable in a REST GET command

Post by amateur+ » 27 Jan 2022, 15:06

Another way:

Code: Select all

 LTitle = 20211215-123019
 url = https://mysite/_api/Web/Lists/GetByTitle('My Title')/items?$select=id,Title,Facility,SSN,Last_Name,NewColumn1,Urgent ne '' and startswith(Title, '%Ltitle%')
 MsgBox, % url
 ; req.open("GET", url, false)
return
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

Post Reply

Return to “Ask for Help (v1)”