PUT/PATCH - Update Rows

Created by Danny Chu, Modified on Tue, 26 Jul, 2022 at 2:39 PM by Danny Chu

PUT and PATCH requests are two ways of updating existing data in your Sheet.

You can update the data on your Sheet by sending PUT and PATCH requests, to this pattern: 

https://sheet.best/api/sheets/<api id>/<row number>.


Example: If your API URL is 

https://sheet.best/api/sheets/cf969697-682a-40e3-bad4-d54803eeeacf

make update calls to: 


https://sheet.best/api/sheets/cf969697-682a-40e3-bad4-d54803eeeacf/2

 

to update the third row from your Sheet (it is 0 indexes).

PUT - Overwriting all data from that row with the sent data

Sending a PUT request will overwrite all row data with the data you sent, columns that had not value assigned to it will be set as blank.

PATCH - Update only the data sent into the sheet

Sending a PATCH request will only update the data you've sent on the sent, this is good to update just the columns you've sent in the request.

Filtered Update

You can also make Filtered Updates to update rows that fits in a filter.

Let's say you have a table like this one:




If you want to update all rows that have "John" inside the "Name" column, you can make a PATCH or PUT request to:


https://sheet.best/api/sheets/cf969697-682a-40e3-bad4-d54803eeeacf/Name/*John*


For more Filtered Update options, check out our Filtering Data section, for more options, all options supported there are supported here.


-----


Shell


# Update first row setting the name to "Jack Doe"
curl 'https://sheet.best/api/sheets/cf969697-682a-40e3-bad4-d54803eeeacf/1' \
    -X PATCH \
    -H 'Content-Type: application/json' \
    -d '{"Name": "Jack Doe"}'

# Update the first row setting the name to "Jack Doe" and erasing other columns data
curl 'https://sheet.best/api/sheets/cf969697-682a-40e3-bad4-d54803eeeacf/1' \
    -X PUT \
    -H 'Content-Type: application/json' \
    -d '{"Name": "Jack Doe"}'

# Filtered Update
# Update all rows that have "John" inside the name column and change it to "Jack Doe"
curl 'https://sheet.best/api/sheets/cf969697-682a-40e3-bad4-d54803eeeacf/Name/*John*' \
    -X PATCH \
    -H 'Content-Type: application/json' \
    -d '{"Name": "Jack Doe"}'


Python


import requests

# Update first row setting the name to "Jack Doe"
requests.patch(
    "https://sheet.best/api/sheets/cf969697-682a-40e3-bad4-d54803eeeacf/1",
    json={
        'Name': 'Jack Doe',
    },
)

# Update the first row setting the name to "Jack Doe" and erasing other columns data
requests.put(
    "https://sheet.best/api/sheets/cf969697-682a-40e3-bad4-d54803eeeacf/1",
    json={
        'Name': 'Jack Doe',
    },
)

# Filtered Update
# Update all rows that have "John" inside the name column and change it to "Jack Doe"
requests.patch(
    "https://sheet.best/api/sheets/cf969697-682a-40e3-bad4-d54803eeeacf/Name/*John*",
    json={
        'Name': 'Jack Doe',
    },
)


Javascript


// Update first row setting the name to "Jack Doe"
fetch("https://sheet.best/api/sheets/cf969697-682a-40e3-bad4-d54803eeeacf/1", {
  method: "PATCH",
  mode: "cors",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    Name: "Jack Doe",
  }),
})
  .then((r) => r.json())
  .then(console.log)
  .catch(console.error);

// Update the first row setting the name to "Jack Doe" and erasing other columns data
fetch("https://sheet.best/api/sheets/cf969697-682a-40e3-bad4-d54803eeeacf/1", {
  method: "PUT",
  mode: "cors",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    Name: "Jack Doe",
  }),
})
  .then((r) => r.json())
  .then(console.log)
  .catch(console.error);

// Filtered Update
// Update all rows that have "John" inside the name column and change it to "Jack Doe"
fetch(
  "https://sheet.best/api/sheets/cf969697-682a-40e3-bad4-d54803eeeacf/Name/*John*",
  {
    method: "PATCH",
    mode: "cors",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      Name: "Jack Doe",
    }),
  }
)
  .then((r) => r.json())
  .then(console.log)
  .catch(console.error);

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article