Help

Re: Looking for EXCEL VBA example using Rest API PATCH command

3209 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Greg_Witkamp
6 - Interface Innovator
6 - Interface Innovator

I’m looking for a simple example for updating one or more fields of existing records thru excel vba. I’ve found several example of using GET, a few for POST & PUT, but almost nothing for using PATCH. I really only need to update one field of a record, but many records to update.

Thanks,

3 Replies 3

You can find PATCH examples that are already handcrafted & custom-tailored for your particular base by going to REST API - Airtable, and then choosing your base name, then choosing the table name (in the left margin), then choosing “Update Records” (in the left margin).

Hi Scott,

That’s what I’m referencing, but I’m struggling translating that into VBA for excel. I’m a novice developer at best, and I pull most of what I need from examples.

I’m trying to update a single field of a single record just to I can understand how it works to plug it into a tool I’m working on.

I get this error:
{"error":{"type":"INVALID_REQUEST_MISSING_FIELDS","message":"Could not find field \"fields\" in the request body"}}

I don’t know if my string is formatted incorrectly for what needs updated and/or if I don’t have the right parts of the request. I started with a working example for a GET request.

Sub REST_PATCH()

Dim objRequest As Object
Dim strUrl As String
Dim blnAsync As Boolean
Dim strResponse As String
Dim str As String


Set objRequest = CreateObject("MSXML2.XMLHTTP")
strUrl = "https://api.airtable.com/v0/appeIRMxD05xIau1C/VENDOR%20ITEMS/recjJhV29c8NiwY0t?api_key=keyxxxxxxxxxxxx"
blnAsync = True

str = "'{ ""records"": [ { ""id"": ""recjJhV29c8NiwY0t"", ""fields"": {""DESC"": ""TEST PATCH\n""] }'"

With objRequest
    .Open "PATCH", strUrl, blnAsync
    .SetRequestHeader "Content-Type", "application/json-patch"
    .Send str
    'spin wheels whilst waiting for response
    While objRequest.readyState <> 4
        DoEvents
    Wend
    strResponse = .ResponseText
End With

Debug.Print strResponse

End Sub

Thanks for the help,

Greg

Sorry, I don’t know VBA for Excel.