Help

Re: "Could not find field \"fields\" in the request body"

1937 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Sankalp20
4 - Data Explorer
4 - Data Explorer

Hi everyone! I've recently started using Airtable and absolutely love it ❤️

However, I'm getting an error while trying to use the PATCH request to update a field in my table.

My code is shown below:

UrlFetchApp.fetch('https://api.airtable.com/v0/' + baseID + '/' + tableID + '/' + recordID, {
      method: 'PATCH',
      headers: {
        'Authorization': 'Bearer ' + api_key,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        "fields": {
          "OpenAI_key": userApiKey
          }
        })
      });

Error message:

Exception: Request failed for https://api.airtable.com returned code 422. Truncated server response: {"error":{"type":"INVALID_REQUEST_MISSING_FIELDS","message":"Could not find field \"fields\" in the request body"}} (use muteHttpExceptions option to examine full response)

Any help will be appreciated

Thanks!

3 Replies 3

Hm, I don't think I've done a PATCH like that before, actually

I usually do it with something like:

UrlFetchApp.fetch('https://api.airtable.com/v0/' + baseID + '/' + tableID + '/', {
      method: 'PATCH',
      headers: {
        'Authorization': 'Bearer ' + api_key,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
		  "records": [
		    {
		      "id": recordID,
		      "fields": {
		        "OpenAI_key": userApiKey
		      }
		    }
		  ]
      });

 

Hey @TheTimeSavingCo !

Thanks for the reply. I used this format you suggested but am getting the following error

Exception: Request failed for https://api.airtable.com returned code 422. Truncated server response: {"error":{"type":"INVALID_REQUEST_UNKNOWN","message":"Invalid request: parameter validation failed. Check your request data."}} (use muteHttpExceptions option to examine full response)

 

Hm, if you've verified that the data in the request is fine via Postman or something, then it might be down to something UrlFetchApp is doing?