Skip to content

Updating a Record ​

The postRecord() method can also be used to update an existing record. You can specify the record_id in the config object in order to do so.

postRecord() will overwrite the user's record data to a new data.

For record config parameters, you only need to include the parameters you want to update along with the record_id parameter. All other fields in the record will remain unchanged unless explicitly included in the method call.

TIP

The record_id parameter also accepts a Unique ID. If a record was created with a unique ID, you can pass that value as record_id to update the same record, without having to look up its system generated record_id first.

js
let config = {
  record_id: 'my_unique_id' // a Unique ID previously assigned to the record
};

skapi.postRecord({ newData: "Updated by Unique ID." }, config).then(record => {
  console.log(record);
});

WARNING

Users must be logged in to update a record.

js
let updatedData = {
  newData: "Overwritten with new data."
};

let config = {
  record_id: 'record_id_to_update',
  table: {
    name: 'new_table_name',
    access_group: 'private' // change access group to private
  }
};

skapi.postRecord(updatedData, config).then(record => {
  console.log(record);
});

Example above overwrites record data to a new data and updated to a new table name.

Moving a record into or out of private clears its private access grants

The examples on this page change the access group to private. If the record had private access granted to other users, those grants are removed by the change, in either direction. See Changing the Access Group Clears Private Access.

Only the record's owner can move it into or out of private, or change anything on it while it is private. See Only the Owner Can Cross the Private Boundary for what a project owner or admin account can change on another user's record.

TIP

To update only the config of the record with data untouched, you can leave the first argument data to undefined. Then, only the config will be updated with the previous data untouched.

js
let new_config = {
  record_id: 'record_id_to_update',
  table: {
    name: 'new_table_name',
    access_group: 'private' // change access group to private
  }
};

skapi.postRecord(undefined, new_config).then(record => {
  console.log(record);
});

DANGER

Always use undefined if you want to update only the record configurations. If null is used instead of undefined, the record data will be overwritten to value null.

:::

INFO

Only the owner of the record can update it. The project owner and admins in access group 99 can also update other users' records, read-only ones included, and admins in access groups 90 ~ 98 can change only their subscription settings. Every admin and the project owner can also attach files to another user's record and delete its files, see Files on Records of Other Users. Nobody but the owner can update a private record or change its files. See Updating another user's record.

Readonly Record ​

You can let user upload a readonly record that is immutable once it is created. To create a readonly record, you can set the readonly parameter in the config object to true.

js
let data = {
  myData: "Hello World"
};

let config = {
  table: { name: 'my_collection', access_group: 'public' },
  readonly: true
};

let read_only_record_id;
skapi.postRecord(data, config).then(record => {
  console.log(record);
  read_only_record_id = record.record_id;
});

When the record is created with readonly set to true, the user will not be able edit or delete the record anymore. The project owner and admins in access group 99 can still update it, and admins can delete it.

js
skapi.postRecord({ myData: "Can this be updated?" }, { record_id: read_only_record_id }).catch(err=>{
    alert(err.message); // Record is read only.
})