Help

Re: Cannot Perform “PATCH” Request Using Google App Script

Solved
Jump to Solution
5297 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Dwayne_Hogan
5 - Automation Enthusiast
5 - Automation Enthusiast

When attempting to use the PATCH method in Google Apps Script , I get an error INVALID_REQUEST_UNKNOWN .

I’m able to do a POST and GET request. Tested my credentials using CURL and this worked. Tried the “HTTP Override” hack and that did not work.

function postToAirtable() {
  var url = 'https://api.airtable.com/v0/appxs9P0mXsqcXs5R/Outreach';
  var data = {
    'fields': {

      'Task': '<Task Name>',
      'Outreacher': '<Person>',
      'Month': 'May ',
      'Status': 'In Progress',
      'Go Live Date': '2016-03-01',
      'Copy Card Link': [
        'recONM5ul2oaG6yKi'
      ],
      'Label': 'DET'
    }
  };

  var headers = {'Authorization':'Bearer ' + '<API KEY>'};

  var options = {
    'contentType':'application/json',
    'method' : 'PATCH',
    'headers': headers,
    // Convert the JavaScript object to a JSON string.
    'payload' : JSON.stringify(data),
  };
  //Logger.log(options);   

  Logger.log(UrlFetchApp.fetch(url, options));


};
14 Replies 14

I’m not entirely sure what you mean by this question. Care to expand your idea a little more?

Google script use doGet function to load the htmlserver or the page. when the page was loaded, I want to load another page once i click the next button. Would it be possible?

Yes - this is simply a matter of constructing the first (home) page to link to other pages. The “other” pages it links to either have to exist as separately rendered pages through the same doGet() method or they must exist on the web somewhere in a web server.

Another more elegant approach is to use javascript on the client (home page) to update that page dynamically using the DOM (document object model).

Is it not possible to make a patch request using filterByFormula instead? I need to be able to make a patch request based on some other value in my table other than the record_ID…

The API specifically states that record ID is required to update any Airtable record, so - no - this is not possible.

What is possible is how you implement the patch process. I believe this is exactly what the Airtable.js SDK does, although I do not use it myself. As I recall, the SDK has a method to leverage filter-like processes to narrow down the table items to be updated.

Doing this without the SDK is relatively simple -

  1. Request the table records.
  2. Filter out the records that need patching (you now have the record IDs).
  3. Iterate across the filtered result; apply the patches.

To the best of my knowledge …

It’s unfortunate that the Airtable API requires us (all of us, even the SDK) to fetch all records from a table. Just because the SDK has a filterBy() method, it doesn’t mean the SDK is somehow more efficient than my described steps - it still needs to look at all the records before applying a patch.

I hope I am wholly misinformed about this and would rejoice in being wrong. :winking_face: