Autohotkey to AirTable API (read and write data to cloud) Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
labrint
Posts: 379
Joined: 14 Jun 2017, 05:06
Location: Malta

Autohotkey to AirTable API (read and write data to cloud)

20 Jan 2019, 05:50

Hi Guys,

Airtable offers users the possibility of storing data on the cloud in spreadsheets via API calls, but so far I have not figured out how to do this using an autohotkey function.

Can any experienced user help me?

https://airtable.com/api

This is the API call written in CURL

Code: Select all

$ curl -v -XPOST **URL** \
-H "Authorization: Bearer **YOUR_API_KEY**" \
-H "Content-Type: application/json" \
 -d '{
  "fields": {
    "Field1": "Test",
    "Field2": "18101",
    "Field3": "123231"
  }
}'
Airtable provides a solution for cloud data logging in your AHK scripts in a spreadsheet format and has reasonably high limits for free users as well as cheap monthly rates for those using AHK for business. It can store a variety of data including attachments in its fields.

Let's get AHK connected with Airtable!

Thanks in advance!
User avatar
TheDewd
Posts: 1510
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Autohotkey to AirTable API (read and write data to cloud)

21 Jan 2019, 12:57

This should help you retrieve data:

Code: Select all

#SingleInstance, Force

; API_Key: Your personal API key generated from the account page (https://airtable.com/account)

; API_Base: The ID of your Base. Try hovering your mouse cursor over the Base name from the AirTables homepage to see the Base ID in the statusbar's URL text. It should look similar to https://airtable.com/appQWERTYUIOPASDF

;API_Table: The name of your table. You may use spaces.


API_Key := "keyPRIVATE"
API_Base := "appDWSRTkUCunNKAD"
API_Table := "MyTable"

WinHttp := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WinHttp.Open("GET", "https://api.airtable.com/v0/" API_Base "/" API_Table, false)
WinHttp.SetRequestHeader("Content-Type", "application/json")
WinHttp.SetRequestHeader("Authorization", "Bearer " API_Key)
WinHttp.Send()

MsgBox, % WinHttp.ResponseText
User avatar
labrint
Posts: 379
Joined: 14 Jun 2017, 05:06
Location: Malta

Re: Autohotkey to AirTable API (read and write data to cloud)

22 Jan 2019, 13:52

Works well TheDewd, do you know how to set up the "POST" method for creating records, please?
User avatar
TheDewd
Posts: 1510
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Autohotkey to AirTable API (read and write data to cloud)  Topic is solved

22 Jan 2019, 14:16

Here's an example to create a new record on an existing Table.

In my table, I have a column created using "Name" as the column name. "MySampleText" is the text to be inserted in the "Name" column.

Code: Select all

#SingleInstance, Force

API_Key := "keyXXXXXXXXXXXXXX"
API_Base := "appXXXXXXXXXXXXXX"
API_Table := "MyTableName"

Data = {"fields":{"Name":"MySampleText"}}

WinHttp := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WinHttp.Open("POST", "https://api.airtable.com/v0/" API_Base "/" API_Table, false)
WinHttp.SetRequestHeader("Content-Type", "application/json")
WinHttp.SetRequestHeader("Authorization", "Bearer " API_Key)
WinHttp.Send(Data)

MsgBox, % WinHttp.ResponseText
I would like to use Google Sheets instead, but the oAuth authentication is too difficult for me to implement. Retrieving data is easy for public files using API key only, but editing files requires oAuth :(
AitTables is nice because it's simple.
User avatar
labrint
Posts: 379
Joined: 14 Jun 2017, 05:06
Location: Malta

Re: Autohotkey to AirTable API (read and write data to cloud)

23 Jan 2019, 05:16

Thank you TheDewd, works like a charm!!
User avatar
labrint
Posts: 379
Joined: 14 Jun 2017, 05:06
Location: Malta

Re: Autohotkey to AirTable API (read and write data to cloud)

30 Jan 2019, 14:37

Anything else apart from airtable? It's good but limited to 2500 records per base.
scriptomundo
Posts: 44
Joined: 08 Nov 2021, 23:40

Re: Autohotkey to AirTable API (read and write data to cloud)

27 Aug 2022, 02:13

TheDewd wrote:
21 Jan 2019, 12:57
This should help you retrieve data:

Code: Select all

#SingleInstance, Force

; API_Key: Your personal API key generated from the account page (https://airtable.com/account)

; API_Base: The ID of your Base. Try hovering your mouse cursor over the Base name from the AirTables homepage to see the Base ID in the statusbar's URL text. It should look similar to https://airtable.com/appQWERTYUIOPASDF

;API_Table: The name of your table. You may use spaces.


API_Key := "keyPRIVATE"
API_Base := "appDWSRTkUCunNKAD"
API_Table := "MyTable"

WinHttp := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WinHttp.Open("GET", "https://api.airtable.com/v0/" API_Base "/" API_Table, false)
WinHttp.SetRequestHeader("Content-Type", "application/json")
WinHttp.SetRequestHeader("Authorization", "Bearer " API_Key)
WinHttp.Send()

MsgBox, % WinHttp.ResponseText
Thanks TheDewd!!

Do you know if its possible to modify existing cell value? I tried to alter the code but I'm getting invalid parameter responses. :evil:
#SingleInstance, Force

Code: Select all

API_Key := "xxx"
API_Base := "xxx"
API_Table := "xxx"


Data = {"id":"recsQnlDRRYEYee5q","fields":{"Name":"Main","Message":"newvaluetest"}}

WinHttp := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WinHttp.Open("PATCH", "https://api.airtable.com/v0/" API_Base "/" API_Table, false)
WinHttp.SetRequestHeader("Content-Type", "application/json")
WinHttp.SetRequestHeader("Authorization", "Bearer " API_Key)
WinHttp.Send(Data)

MsgBox, % WinHttp.ResponseText

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mapcarter, Marium0505, Rohwedder and 371 guests