Rest API with AHK

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Bensley
Posts: 6
Joined: 18 Nov 2017, 06:18

Rest API with AHK

18 Nov 2017, 07:10

I need a huge favor.
I would like to try REST api (demo account) to my broker but having problems .
Does anybody know how to implement HTTP request with AHK?
On a broker page there is a tutorial for a very simple account info that goes like this:

***************************************************************************************************************************************
Examples
curl: Get Account list for current auth token

Request

Code: Select all

curl \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <AUTHENTICATION TOKEN>" \
  "https://api-fxpractice.oanda.com/v3/accounts"
Response Headers:

Code: Select all

HTTP/1.1 200 OK
Access-Control-Allow-Headers: Authorization, Content-Type, Accept-Datetime-Format
Content-Encoding: gzip
Transfer-Encoding: chunked
Server: openresty/1.7.0.1
Connection: keep-alive
Date: Wed, 22 Jun 2016 18:32:01 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: PUT, PATCH, POST, GET, OPTIONS, DELETE
Content-Type: application/json; charset=UTF-8

Response Body

Code: Select all

{
  "accounts": [
    {
      "id": "101-004-7193916-001", 
      "tags": []
    }
  ]
}
***************************************************************************************************************************************
Notice that there are already 3 inputs inserted there :
URL:https://api-fxpractice.oanda.com
Account id: 101-004-7193916-001
Security token:80b44ea9c302237f9178a137d9e86deb-20083fb12d9579469f24afa80816066b

Can anybody make working ahk script out of this, i just need that initial first step
to have any clue how to proceed with more complicated stuff than this.
teadrinker
Posts: 4326
Joined: 29 Mar 2015, 09:41
Contact:

Re: Rest API with AHK

18 Nov 2017, 10:22

Hi, Bensley,

Code: Select all

oWhr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
oWhr.Open("GET", "https://api-fxpractice.oanda.com/v3/accounts", false)
oWhr.SetRequestHeader("Content-Type", "application/json")
oWhr.SetRequestHeader("Authorization", "Bearer 80b44ea9c302237f9178a137d9e86deb-20083fb12d9579469f24afa80816066b")
oWhr.Send()
MsgBox, % oWhr.ResponseText
Bensley
Posts: 6
Joined: 18 Nov 2017, 06:18

Re: Rest API with AHK

18 Nov 2017, 14:37

Wow thank you teadrinker, you are a lifesaver. :bravo:
It works and also with the little adjusting a lot of other Api calls are possible to me now.
I even manage to send (POST) orders :dance:
loumizhu
Posts: 27
Joined: 18 Aug 2016, 22:07

Re: Rest API with AHK

02 Nov 2019, 06:36

teadrinker: thank youuu
quentin
Posts: 1
Joined: 01 Oct 2022, 08:58

Re: Rest API with AHK

01 Oct 2022, 09:06

teadrinker wrote:
18 Nov 2017, 10:22
Hi, Bensley,

Code: Select all

oWhr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
oWhr.Open("GET", "https://api-fxpractice.oanda.com/v3/accounts", false)
oWhr.SetRequestHeader("Content-Type", "application/json")
oWhr.SetRequestHeader("Authorization", "Bearer 80b44ea9c302237f9178a137d9e86deb-20083fb12d9579469f24afa80816066b")
oWhr.Send()
MsgBox, % oWhr.ResponseText
Hi there teadrinker,

I just wanted to send thanks for this. I have an OpenHAB automation setup which allows curl post requests (with an Authorization Bearer for authentication), so I've been looking for a way to have my AHK script update certain dummy switches for statuses. In my case one is to toggle Nvidia Broadcast on and off, I created an AKH script to open the program (if not already running) and toggle the status and keep an always-on-top window as a reminder it's active, the same button combo will activate the window, check the color of the button (in case I toggled it off manually) and update the status.

With your bit of code, I was successfully able to pass the on/off status back to OpenHAB so I can do some extra fancy things like toggle certain lighting on, or do other automation things whenever I'm on a call on my PC. (Planning on an RGB LED strip outside my office door that turns to slow fading on/off Red when I'm on a call or have an AHK key detect when SteamVR is running to do the same idea as well.)

Anyway, your bit of code does exactly what I needed, minus the MsgBox as I don't need a status update so that ended up getting commented out. :)

Cheers!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 311 guests