Help

Re: PATCH request to update field via API in table

3555 8
cancel
Showing results for 
Search instead for 
Did you mean: 
J_M1
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi,

I am using a program to push thru updates to a running database via API. So far, I have been able to search by Username using the filter to return the appropriate ID. I then need to use the ID to locate that record. I am having trouble updating the appropriate field. Can you please show me how I structure the link or the PATCH request? I have tried a variation of the following, to no avail. Please help.

‘{“fields”: { “<>”: “<>” } }’

12 Replies 12

You can check out Airtable’s excellent REST API documentation here, and it even gives you sample code based on your own data:

J_M1
5 - Automation Enthusiast
5 - Automation Enthusiast

Thanks I was using that to get as far as I did. However, it’s somewhat vague on how to target fields to update. I am not sure how to structure it. If someone could post an example specifically, that would be great, since their sample doesnt match my situation.

For example:

Your request body should include an array of up to 10 record objects. Each of these objects should have an id property representing the record ID and a fields property which contains all of your record’s cell values by field name. You can include all, some, or none of the field values.

…, Field 6, Field 7, Field 8, Field 9, Field 10, Field 11, Field 12, Field 13, Field 15, Field 16, Field 17 and Field 18 may contain “mention tokens”. A mention token corresponds to a “@mention” in Airtable’s user interface; here in the API it will look like <airtable:mention id="menE1i9oBaGX3DseR">@Alex</airtable:mention> . Mention tokens cannot be created via this API and should be left intact (or wholly removed) when updating long text fields.

Not sure what to do here…Do i include the whole argument there or just a piece? And where do i put the mention?What is the “@Alex” represent in this case?

Welcome to the Airtable community!

What is your level of coding experience? The Rest API documentation is written for developers, and expects the developers to be familiar with programming concepts such as “an array of objects” and “each object should have an id property and a fields property.” The Rest API documentation also includes examples using data from your base.

Do not worry about the “mention tokens” until after you are comfortable creating your API requests. The documentation refers to mention tokens because long text fields can contain them, but they are not necessary. @Alex is just an example of a mention token, where someone tagged a collaborator with that name in the text field.

J_M1
5 - Automation Enthusiast
5 - Automation Enthusiast

Thanks! I code with frameworks but have very limited knowledge and tinker more than anything. Like I said, I got some progress haha but am hitting a snag on the fields piece. I don’t see the api docs referencing my use case.

For example, I have username | password fields

I filter and search using a username to locate the ID. Now, I use the ID to get the rows contents, however, I want to update the password for that ID, which is column 2. I don’t see where it shows how to patch column 2 in. I don’t understand what I need to type to get my tool to recognize the request body. It keeps saying csnt find fields.

There are 3 columns of information in the REST API documentation.

In the first column, choose “Update Records” for the table that you are trying to update.

Then, in the 3rd column, it will show you an “EXAMPLE REQUEST” of how you can format your request.

J_M1
5 - Automation Enthusiast
5 - Automation Enthusiast

Thank you for the help. I see that table and have tried that already, but given my inexperience, I have no clue how to incorporate the data into my framework to override the current data. I have tried several variations but cant get it. It returns {“error”:{“type”:“INVALID_REQUEST_MISSING_FIELDS”,“message”:“Could not find field “fields” in the request body”}}. These are the examples.

–data ‘{
“records”: [
{
“id”: “recRjh1G2jgs3aiU8”,
“fields”: {
“Email”: “----”,
“PW”: “----”
}
},
{
“id”: “recs0tubWSin27dop”,
“fields”: {
“Email”: “----”,
“PW”: “-----”
}
}
]
}’

What app are you using to send the information? You haven’t explained how you’re trying to send this information to Airtable.

You typically don’t send the word “—data”, and you typically don’t use the opening and closing quotation marks around the entire data. That is the raw CURL data that you would use if you were pasting into the command line terminal of your computer.

But instead of using the command line terminal of your computer which can be extremely confusing, I would highly recommend that you download an HTTP/API client such as Postman, Paw, or Insomnia, and work on building your API requests there. All 3 of them also allow you to import the raw CURL data.

J_M1
5 - Automation Enthusiast
5 - Automation Enthusiast

I appreciate it! Sorry, I am using browser automation studio (BAS) that has a HTTP Client (I figured most are unfamiliar with BAS). It works well very and simply, likely similar to the ones you posted above. This is how it looks. And honestly, I thank you for actually replying. I know it can be frustrating.

In the URL i enter: https://api.airtable.com/v0/REDACTED/Sheet1/[[ID OF THE RECORD}}
Header: KEY
POST DATA: This is the section I have issues with. I dont know what to put to PATCH the password into the proper field.

image

That doesn’t look like a very user-friendly app, since it’s just giving you big text boxes to type everything into.

Since you’re just getting started with APIs for the first time, I would highly recommend one of the ones that I recommended above, which helps to guide you through the process better by breaking everything down into smaller pieces.

Import the CURL (or Javascript) from Airtable into one of the apps that I told you about, and it will break it down for you automatically.

J_M1
5 - Automation Enthusiast
5 - Automation Enthusiast

OK i will try that out. Thank you so much!!!

ep_eric
4 - Data Explorer
4 - Data Explorer

Hi all,

===
EDIT 2: Problem persists (original post follows Edit 1)
I was able to perform this request only with a static text string. Replacing the static text (eg. "Help me out!") with an object from the JSON (in n8n) causes this to fail with error ERROR: The data in "Body Parameters" is no valid JSON. Set Body Content Type to "RAW/Custom" for XML or other types of payloads, a native n8n error.

Parameters are in JSON/RAW and Response format is JSON.

Setting Body content type to RAW/custom yields this error {"error":{"type":"INVALID_REQUEST_MISSING_FIELDS","message":"Could not find field \"fields\" in the request body"}}, which is likely an error native to Airtable.

Does Airtable's Long text field have specific input requirements?

===
EDIT 1: Solved-ish
Somehow I was able to get the following to update the field "My Long Text".

 

 

 

{
  "fields": {
    "My Long Text": "Help me out!"
  }
}

 

 

 

From Postman, suddenly one of my PATCH requests worked (raw / JSON). From there I went back to my automation software and now this same request worked too. Previously, "My Long Text" field was not showing up in GET requests because it had an empty value; perhaps that plays a role in not being able to initialize from API? Although Postman eventually got this to work.

I say "solved-ish" because I can't identify the problem before; only that I now have the solution. Also because I'm using the API key method which will be deprecated beginning of next year, so not the long-term solution either.
===

I'm in a similar situation as OP here, cannot for the life of me figure out the correct JSON body to send in the request to UPDATE a field in a record.

I can GET records so it's not an access issue, although my custom field "My Long Text" is not included in the returned JSON body - I confirm this field is not "hidden" on the base. I'm using API key to connect (via n8n). I was also able to APPEND records, albeit not correctly. I was able to send UPDATE request for a record without an error, but the body returned does not include my update to the field in the record (the JSON once again excludes my custom field "My Long Text"). It's just not included in the JSON, and no change is made on the base.

I have tried sending body of request as the following (with a variety of errors, of course):

 

 

{
    "records": [
      {
        "fields": {
            "My Long Text": "Here's some content"
        }
      }
    ]
}

 

 

*Note I am only trying to update one record, so rec ID would be included in the URL and thus I wouldn't need to include "records" in the body, according to the docs, but want to make it clear that I also tried this approach.

 

 

{
  "fields": [ {
    "My Long Text": "Here's some content"
  }
 ]
}

 

 

 

 

{
  "fields": {
    "My Long Text": "Here's some content"
  }
}

 

 

 

 

{
    "My Long Text": "Here's some content"
}

 

 

I also found the Field ID for "My Long Text" and tried that in place of the name string, with and without quotations.

Any help is appreciated. I'm here because I already exhausted all personal research options, including this vid that shows very specifically the GET and POST request bodies, which I have tried verbatim.

Having worked with many APIs, I have to say this one is baffling for sure. I just need to update a field in a record. Seems basic enough. Anyone see what I'm doing wrong?

Thanks,

Eric

 

 

Did you ever solve this? Would love to know your JSON body that enabled you to update a field in a record.

Thanks.

Eric