Update Records

Learn how to update Records in a Table with Morph API.

Overview

You can update one or multiple Records in a Table using Morph API.

You need to define several parameters to build the request to the Update Record endpoint.

These parameters are:

  • teamSlug, databaseId and tableSlug as well as API Key.
  • The values and filter arrays of the body parameter.

This guide will focus on explaining how to the define the values and filter arrays.

📘

The steps to obtain teamSlug, databaseId and tableSlug as well as the API Key are detailed in the Quickstart.


The filter is your way to select (filter) only the records that you wish to update.

The values array is where you define the actual values that you wish to update for these Records.

You define both of these in the body parameter of the request.


🚧

The data type of the value must match the data type of the corresponding Field.


Example for this guide

We will see examples to:

  • Update a single Record
  • Update multiple Records (Bulk update)

Update a Record

To update a single Record using Morph API, you call the Update Record endpoint.

We will make an API request to the Update Record endpoint for the [Sample] Employees Table to update the job_title of the employee named Kai Lee (employee_id is E02002) from Controls Engineer to Manager.


Build the request

To build the request, you will need the following parameters.

Headers

  • authorization header: x-api-key: {YOUR_API_KEY}
  • client-type: widget
  • Content-Type: application/json

ℹ️

How to get my API Key?

Head to Create an API Key.


Path parameters

  • teamSlug
  • databaseId
  • tableSlug

ℹ️

Where can I find my teamSlug, databaseId and tableSlug?

Go to How to find teamSlug, databaseId and tableSlug.


Body parameter

As shown in the sample Table and body parameter, the values array is an array of objects, where each object has two properties: a key property and a value property.

  • The key property is the name of the Field.
  • The value property is the new value that you wish to update for that given Field.

With the filter you select the subset (filter) of records that you wish to update. The filter is an object Filter Object with its keys being either a RecordFilterConditionAnd or a RecordFilterConditionOr.

📘

Look at the sample Table for a simple example.

{
  "fixedValue": [],
  "values": [
    {
      "key": "{FIELD FOR WHICH YOU WISH TO UPDATE THE VALUE}",
      "value": "{NEW VALUE FOR THE RECORD YOU WISH TO UPDATE}"
    }
  ],
  "filter": {
    "and": [
      {
        "key": "{FIELD TO SELECT THE RECORDS TO UPDATE}",
        "operator": "{OPERATOR}",
        "value": "{VALUE TO SELECT THE RECORDS TO UPDATE}"
      }
    ]
  }
}

Here is example

{
  "fixedValue": [],
  "values": [
    {
      "key": "job_title",
      "value": "Manager"
    }
  ],
  "filter": {
    "and": [
      {
        "key": "employee_id",
        "operator": "equal",
        "value": "E02002"
      }
    ]
  }
}

Make the API request

cURL

To make the HTTP request directly using cURL:

  • Open a Terminal window.
  • Replace the following placeholders in the cURL template below with your own values.
    • In the URL:
      • {YOUR_TEAM_SLUG}
      • {YOUR_DATABASE_ID}
      • {YOUR_TABLE_SLUG}
    • In the headers:
      • {YOUR_API_KEY} for the x-api-key
  • Run the command in your Terminal.

Replace the placeholders with your own values

curl --X POST 'https://{YOUR_TEAM_SLUG}.api.morphdb.io/v0/record/{YOUR_DATABASE_ID}/{YOUR_TABLE_SLUG}/query' \
--header 'Content-Type: application/json' \
--header 'client-type: widget' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '{
  "fixedValue": [],
  "values": [
    {
      "key": "{FIELD FOR WHICH YOU WISH TO UPDATE THE VALUE}",
      "value": "{NEW VALUE FOR THE RECORD YOU WISH TO UPDATE}"
    }
  ],
  "filter": {
    "and": [
      {
        "key": "{FIELD TO SELECT THE RECORDS TO UPDATE}",
        "operator": "{OPERATOR}",
        "value": "{VALUE TO SELECT THE RECORDS TO UPDATE}"
      }
    ]
  }
}'

Example with mock values:

curl --X POST 'https://acme.api.morphdb.io/v0/record/dw5g1h89-2637-253k-452b-7803j4x7e3vi/employee/update' \
--header 'Content-Type: application/json' \
--header 'client-type: widget' \
--header 'x-api-key: ms5sCDEOVNuIw92MNA3qLKih4xzY25D9PQY6D7Az2' \
--data '{
  "fixedValue": [],
  "values": [
    {
      "key": "job_title",
      "value": "Manager"
    }
  ],
  "filter": {
    "and": [
      {
        "key": "employee_id",
        "operator": "equal",
        "value": "E02002"
      }
    ]
  }
}'

Response

The Record has been updated to your Table.

You should see the following successful response in your Terminal:

{
  "message": "ok"
}

You can view it in Morph and in the Developer Mode.

In Morph:

Record updated (Morph)

Record updated (Morph)


In the Developer Mode:

Record updated (Developer Mode)

Record updated (Developer Mode)


Debugging

📘

Not the expected result?

Try the following debugging steps.


Update multiple Records (Bulk update)


To update a multiple Records at once using Morph API, you call the Update Record endpoint.

We will make an API request to the Update Record endpoint for the [Sample] Employees Table.

Let's say three of your employees are moving from the United States to Japan to join your growing team in your Tokyo office.

At the moment these employees are based in three different cities in the US.

employee_idfull_name//...countrycity
E02003Robert PatelUnited StatesChicago
E02005Harper CastilloUnited StatesSeattle
E02006Harper DominguezUnited StatesAustin

We want to update their country and city to:

employee_idfull_name//...countrycity
E02003Robert PatelJapanTokyo
E02005Harper CastilloJapanTokyo
E02006Harper DominguezJapanTokyo

Build the request

To build the request, you will need the following parameters.

Headers

  • authorization header: x-api-key: {YOUR_API_KEY}
  • client-type: widget
  • Content-Type: application/json

ℹ️

How to get my API Key?

Head to Create an API Key.


Path parameters

  • teamSlug
  • databaseId
  • tableSlug

ℹ️

Where can I find my teamSlug, databaseId and tableSlug?

Go to How to find teamSlug, databaseId and tableSlug.


Body parameter

As shown in the sample Table and body parameter, the values array is an array of objects, where each object has two properties: a key property and a value property.

  • The key property is the name of the Field.
  • The value property is the new value that you wish to update for that given Field.

With the filter you select the subset (filter) of records that you wish to update. The filter is an object Filter Object with its keys being either a RecordFilterConditionAnd or a RecordFilterConditionOr.

📘

Look at the sample Table for a simple example.


For our example, we use the or operator to only filter the records we wish to update:

{
  "fixedValue": [],
  "values": [
    {
      "key": "{FIELD FOR WHICH YOU WISH TO UPDATE THE VALUE}",
      "value": "{NEW VALUE FOR THE RECORD YOU WISH TO UPDATE}"
    },

    // ONE OR MULTIPLE
    
    {
      "key": "{FIELD FOR WHICH YOU WISH TO UPDATE THE VALUE}",
      "value": "{NEW VALUE FOR THE RECORD YOU WISH TO UPDATE}"
    }
  ],
  "filter": {
    "or": [ // choice of operators: `and`,`or`
      {
        "key": "{FIELD TO SELECT THE RECORDS TO UPDATE}",
        "operator": "{OPERATOR}",
        "value": "{VALUE TO SELECT THE RECORDS TO UPDATE}"
      },

      // ONE OR MULTIPLE CONDITIONS

      {
        "key": "{FIELD TO SELECT THE RECORDS TO UPDATE}",
        "operator": "{OPERATOR}",
        "value": "{VALUE TO SELECT THE RECORDS TO UPDATE}"
      },      
    ]
  }
}

With values:

{
  "fixedValue": [],
  "values": [
    {
      "key": "country",
      "value": "Japan"
    },
    {
      "key": "city",
      "value": "Tokyo"
    }
  ],
  "filter": {
    "or": [
      {
        "key": "employee_id",
        "operator": "equal",
        "value": "E02003"

      },
      {
        "key": "employee_id",
        "operator": "equal",
        "value": "E02005"
      },
      {
        "key": "employee_id",
        "operator": "equal",
        "value": "E02006"
      }
    ]
  }
}

Make the API request

cURL

To make the HTTP request directly using cURL:

  • Open a Terminal window.
  • Replace the following placeholders in the cURL template below with your own values.
    • In the URL:
      • {YOUR_TEAM_SLUG}
      • {YOUR_DATABASE_ID}
      • {YOUR_TABLE_SLUG}
    • In the headers:
      • {YOUR_API_KEY} for the x-api-key
  • Run the command in your Terminal.

Replace the placeholders with your own values

curl --X POST 'https://{YOUR_TEAM_SLUG}.api.morphdb.io/v0/record/{YOUR_DATABASE_ID}/{YOUR_TABLE_SLUG}/query' \
--header 'Content-Type: application/json' \
--header 'client-type: widget' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '{
  "fixedValue": [],
  "values": [
    {
      "key": "{FIELD FOR WHICH YOU WISH TO UPDATE THE VALUE}",
      "value": "{NEW VALUE FOR THE RECORD YOU WISH TO UPDATE}"
    },

    // ONE OR MULTIPLE
    
    {
      "key": "{FIELD FOR WHICH YOU WISH TO UPDATE THE VALUE}",
      "value": "{NEW VALUE FOR THE RECORD YOU WISH TO UPDATE}"
    }
  ],
  "filter": {
    "or": [ // choice of operators: `and`,`or`
      {
        "key": "{FIELD TO SELECT THE RECORDS TO UPDATE}",
        "operator": "{OPERATOR}",
        "value": "{VALUE TO SELECT THE RECORDS TO UPDATE}"
      },

      // ONE OR MULTIPLE CONDITIONS

      {
        "key": "{FIELD TO SELECT THE RECORDS TO UPDATE}",
        "operator": "{OPERATOR}",
        "value": "{VALUE TO SELECT THE RECORDS TO UPDATE}"
      },      
    ]
  }
}'

In our example:

curl --X POST 'https://acme.api.morphdb.io/v0/record/dw5g1h89-2637-253k-452b-7803j4x7e3vi/employee/update' \
--header 'Content-Type: application/json' \
--header 'client-type: widget' \
--header 'x-api-key: ms5sCDEOVNuIw92MNA3qLKih4xzY25D9PQY6D7Az2' \
--data '{
  "fixedValue": [],
  "values": [
    {
      "key": "country",
      "value": "Japan"
    },
    {
      "key": "city",
      "value": "Tokyo"
    }
  ],
  "filter": {
    "or": [
      {
        "key": "employee_id",
        "operator": "equal",
        "value": "E02003"

      },
      {
        "key": "employee_id",
        "operator": "equal",
        "value": "E02005"
      },
      {
        "key": "employee_id",
        "operator": "equal",
        "value": "E02006"
      }
    ]
  }
}'

Response

The Record has been updated to your Table.

You should see the following successful response in your Terminal:

{
  "message": "ok"
}

You can view it in Morph and in the Developer Mode.

In Morph:

Record updated (Morph)

Multiple records updated (Morph)


In the Developer Mode:

Record updated (Developer Mode)

Multiple records updated (Developer Mode)


Debugging

📘

Not the expected result?

Try the following debugging steps.