Add a Record
Learn how to add a Record to a Table with Morph API.
Overview
You need to define several parameters to build the request to the Create Record endpoint.
These parameters are:
teamSlug
,databaseId
andtableSlug
as well asAPI Key
.- The
values
array of the body parameter.
This guide will focus on explaining how to the define the values
array.
The steps to obtain
teamSlug
,databaseId
andtableSlug
as well as theAPI Key
are detailed in the Quickstart.
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 a Field. -
The
value
property is the value that you wish to define for that given Field.
The data type of the
value
must match the data type of the corresponding Field.
To build the values
array in the body parameter, you will need to:
- Find the name of each Field in that Table, to define the
key
property. - Define the values for each of the Fields, to define the
value
property.
Example for this guide
We will go through all the steps to add a Record to a Table with an example.
First, we will retrieve the name of each Field for the employees
Table (from the Quickstart).
Then, we will add a new Record to this employees
Table using the Create Record endpoint of Morph API.
Terminology
Before we dive in, a brief note on terminology.
If at any point in this guide, you start to feel confused about what the terms "name of the Field", "Field Name" or "Field Slug" are referring to, please come back to this note.
In the first section of this guide, we will show how to find the "name of the Field" to be able to define the key
property for each Field.
Yet, the "name of the Field" are not exactly displayed in the same way in the Morph and in the Developer Mode.
In Morph, you will see the the terms Field Name
or Field Slug
in the Edit settings
of a Field. In the case of Morph, the "name of the Field" we will want is the value of the Field Slug
.
However, in the Developer Mode, the terms "Field Name" or "Field Slug" do not exist. In the Developer Mode, the "name of the Field" is defined as the name
entry (or property) in the Structure
view.
Find the name of each Field
The first step is to find the name for all the Fields of the employees
Table.
How to find the name of each Field?
To find the name of each Field in a Table, you have these options:
- Manually in Morph.
- Manually in the Developer Mode.
- Programmatically with Morph API.
Each option is detailed in the Find the name of each Field article.
Add a Record
To add a Record using Morph API, you call the Create Record endpoint.
We will make an API request to the Create Record endpoint for the employees
Table.
Build the request
To build the request, you will need the following parameters.
Headers
- authorisation 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?
Body parameter
In the first section, we have found the names of each Field. Each names is the value of key
. What's left is for you to define the value of each value
for the corresponding key
(or Field).
Look at the sample Table for simple example.
{
"fixedValue":[],
"values": [
{
"key": "employee_id",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "full_name",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "job_title",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "department",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "business_unit",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "gender",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "ethnicity",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "age",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "hire_date",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "annual_salary",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "bonus",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "country",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "city",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "exit_date",
"value": "" // FOR YOU TO DEFINE
}
]
}
Here is example:
{
"fixedValue":[],
"values": [
{
"key": "employee_id",
"value": "E12345"
},
{
"key": "full_name",
"value": "Alan Turing"
},
{
"key": "job_title",
"value": "Chief Computer Scientist"
},
{
"key": "department",
"value": "IT"
},
{
"key": "business_unit",
"value": "Research & Development"
},
{
"key": "gender",
"value": "Male"
},
{
"key": "ethnicity",
"value": "Caucasian"
},
{
"key": "age",
"value": "41"
},
{
"key": "hire_date",
"value": "2020-05-15"
},
{
"key": "annual_salary",
"value": "195000"
},
{
"key": "bonus",
"value": "50000"
},
{
"key": "country",
"value": "United Kingdom"
},
{
"key": "city",
"value": "London"
},
{
"key": "exit_date",
"value": ""
}
]
}
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 thex-api-key
- In the URL:
- 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}/create" \
--header "Content-Type: application/json" \
--header "client-type: widget" \
--header "x-api-key: {YOUR_API_KEY}"
--data '{
"fixedValue":[],
"values": [
{
"key": "employee_id",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "full_name",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "job_title",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "department",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "business_unit",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "gender",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "ethnicity",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "age",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "hire_date",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "annual_salary",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "bonus",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "country",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "city",
"value": "" // FOR YOU TO DEFINE
},
{
"key": "exit_date",
"value": "" // FOR YOU TO DEFINE
}
]
}
Example with mock values:
curl --X POST "https://42d54rt5-d389-845a-6lkq-34z563gtu872.api.morphdb.io/v0/record/dw5g1h89-2637-253k-452b-7803j4x7e3vi/employee_csv_demo/create" \
--header "Content-Type: application/json" \
--header "client-type: widget" \
--header "x-api-key: ms5sCDEOVNuIw92MNA3qLKih4xzY25D9PQY6D7Az2"
--data '{
"fixedValue":[],
"values": [
{
"key": "employee_id",
"value": "E12345"
},
{
"key": "full_name",
"value": "Alan Turing"
},
{
"key": "job_title",
"value": "Chief Computer Scientist"
},
{
"key": "department",
"value": "IT"
},
{
"key": "business_unit",
"value": "Research & Development"
},
{
"key": "gender",
"value": "Male"
},
{
"key": "ethnicity",
"value": "Caucasian"
},
{
"key": "age",
"value": "41"
},
{
"key": "hire_date",
"value": "2020-05-15"
},
{
"key": "annual_salary",
"value": "195000"
},
{
"key": "bonus",
"value": "50000"
},
{
"key": "country",
"value": "United Kingdom"
},
{
"key": "city",
"value": "London"
},
{
"key": "exit_date",
"value": ""
}
]
}'
Response
The new Record has been added to your Table.
You should see the following successful response in your Terminal:
{
"message": "ok"
}
In Morph and Developer Mode
You can view it in Morph and in the Developer Mode.
In Morph:
![Add a Record in the [Sample] Employees Table as seen in Morph.](https://files.readme.io/2e31db7-Morph_-_Add_a_Record_-_Alan_Turing.png)
Add a Record in the [Sample] Employees Table as seen in Morph.
In the Developer Mode:
![Add a Record in the [Sample] Employees Table as seen in the Developer Mode.](https://files.readme.io/26b10cc-Morph_Developer_-_Add_a_Record_-_Alan_Turing.png)
Add a Record in the [Sample] Employees Table as seen in the Developer Mode.
Debugging
Not seeing the new Record?
Follow the debugging steps detailed in the Quickstart. While there are for a different endpoint, there debugging principles and steps are generic.
Summary
You have learned how to:
-
Add a Record to a Table with the Create Record endpoint of Morph API.
-
Find and define the
key
andvalue
properties of thevalues
array to build the body parameter. -
Find the name of each Field in a Table, with these 3 options:
- Manually in Morph.
- Manually in the Developer Mode.
- Programmatically with Morph API.
Next steps
Learn how to Create a Record in simple, straightforward language using the AI capabilities integrated within Morph, using the Create Record with prompt endpoint.
Resources
Resources mentioned in this page by order of appearance:
- Create Record endpoint of Morph API.
- How to find teamSlug, databaseId and tableSlug.
- Sample Table and body parameter sample Table in the Create Record endpoint of Morph API.
- Get List of Fields endpoint of Morph API.
- How to Create an API Key.
- Simple Field object definition.
- Debugging suggestions if you do not obtain the expected response.
Links to Morph applications:
- Morph: https://app.morphdb.io
- Developer Mode: https://developer.morphdb.io
Updated 2 months ago