Help

Re: Patch Request from google apps script

Solved
Jump to Solution
2575 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Lee_Thomas
6 - Interface Innovator
6 - Interface Innovator

I just can’t find the right way to format my request. I’m trying to update a single field in a single record. but keep hitting - INVALID_REQUEST_MISSING_FIELDS",“message”:"Could not find field “fields” in the request body

Getting data is fine.

After a few hours trying different things I’m asking for help what am I missing? Any help appreciated

API and Base ID Blanked out

function apiCall(){

var API_KEY = ‘XXXXXXXXX’;
var root = ‘https://api.airtable.com/v0’;

var baseId = ‘XXXXXXXXXXXX’;
var tableName = encodeURIComponent(‘Travels’);
var recordId = “recSaJTXSBu1g8CBd”
var endpoint = ‘/’ + baseId + ‘/’ + tableName + ‘/’ + recordId;

var params = {
‘method’: ‘PATCH’,
‘muteHttpExceptions’: true,
‘Content-Type’: ‘application/json’,
‘headers’: {
‘Authorization’: 'Bearer ’ + API_KEY
},

    "fields" : {
      "Declaration link": "https://docs.google.com/spreadsheets/d/13V8gO7511yJ0830IpiKXtfYfKeuVVSJ8uqbXR-9Ne8w/edit#gid=0"
     }

};

var response = UrlFetchApp.fetch(root + endpoint, params);
Logger.log(response.getContentText());
}

1 Solution

Accepted Solutions
Lee_Thomas
6 - Interface Innovator
6 - Interface Innovator

Thanks Bill , I did have the record id but the code is not super readable on the forum. Also I had tried with the payload also but I was getting the same error. But your code helped me see what I think was the mistake. The content type was stored outside of the headers in my params.

for others working code below.

Screenshot 2021-02-23 at 16.51.37

See Solution in Thread

3 Replies 3

I think you have at least two issues:

  1. The API requires a record ID to tell it which record should be patched.
  2. The fields element is freely floating in the params object but should be contained in a payload element and stringified. (see example)

image

Lee_Thomas
6 - Interface Innovator
6 - Interface Innovator

Thanks Bill , I did have the record id but the code is not super readable on the forum. Also I had tried with the payload also but I was getting the same error. But your code helped me see what I think was the mistake. The content type was stored outside of the headers in my params.

for others working code below.

Screenshot 2021-02-23 at 16.51.37

Use the preformatted text styler in the editor toolbar to format the code for easier reading. For multi-line code snippets, wrap the code in pairs of graves triplets → ```

Example:

```
// This is some code
let something = “Something”;
```

…becomes…

// This is some code
let something = "Something";