Update Rows
You can update the values of specified rows in your sheet. Send a PUT
request with the row identifiers and the updated fields.
Structuring the JSON
Create a JSON string with the following keys: condition
, set
, and optionally limit
.
{
"condition": {"column": "value", ...},
"set": {"column": "updated value", ...},
"limit": INTEGER (optional)
}
The value of the condition
property is used to search for matching rows in the sheet. It behaves similar to the search param when searching for rows.
These matched rows are then updated according to the set
property. You do not need to specify values for all fields. Omitted fields will be left untouched.
The number of rows updates is limited as per the limit
option, if specified.
Performing the request
Let's update the title field of all posts by Shiven Sinha in the Blog Posts Sheet.
$ curl "https://api.steinhq.com/v1/storages/5cc158079ec99a2f484dcb40/Sheet1" \
-X PUT \
-H "Content-Type: application/json" \
-d '{"condition": {"author": "Shiven Sinha"}, "set": {"title": "Currently Unavailable"}}'
// Search Sheet1
const SteinStore = require("stein-js-client");
const store = new SteinStore(
"https://api.steinhq.com/v1/storages/5cc158079ec99a2f484dcb40"
);
store
.edit("Sheet1", {
search: { author: "Shiven Sinha" },
set: { title: "Currently Unavailable" }
})
.then(res => {
console.log(res);
});
<script src="https://unpkg.com/stein-js-client"></script>
<script>
const store = new SteinStore(
"https://api.steinhq.com/v1/storages/5cc158079ec99a2f484dcb40"
);
store
.edit("Sheet1", {
search: { author: "Shiven Sinha" },
set: { title: "Currently Unavailable" }
})
.then(res => {
console.log(res);
});
</script>
This updates the title of all posts by Shiven Sinha to Currently Unavailable.
Return value
The updated range of your sheet is returned. For example,
{ "updatedRange": "Sheet1!A6:D6" }