This article assumes you have checked the introduction article and the GET request article. If not, please do so first.
Adding data
It is possible to add new data via the REST API. To do so, you need to use a POST request. The URL for the request should call the object type without the ID.
Example: HTTPS POST https://lynx.a-dato.com/api/projects
The next step is to include a body in your request, with the ID being "-1". The "-1" ID indicates that the object is a new object. The object is in JSON format, and you are required to include all fields of the object. You can therefore copy the schema from the Swagger documentation, or use a get request and copy the body of an existing object.
You can create multiple objects at a time (in bulk) using a POST request. Make sure to pass a JSON array containing multiple objects of the same type.
Please note: make sure to use a unique negative ID for each separate object used in a bulk create action. For example, Object 1 has ID "-1", Object 2 has ID "-2", etc.
Please note: you do not need to specify an ID when creating a new object as one is automatically generated when the object is created.
Modifying Data
You can modify existing data by editing the values of properties of objects. Below we describe two ways of doing so. It is important to know that you can only modify one object at a time.
To edit an existing object, you need to specify the object's ID in the URL of the request.
Example: HTTPS PATCH https://lynx.a-dato.com/api/projects/123
For both PUT and PATCH requests, you need to include a body in your request. This body is the data of the object in JSON format. You can check the Swagger documentation for the object schemas.
Each object has a version associated with it. This is the value from which the server keeps track of the history of the updates. You need to make sure the version is the latest version in the server or a higher verion, otherwise the request will fail. You can see the version as a property in the object, for example: "Version": 32746687.
Please note: The custom fields are included in the object at the end. It is important to note that you can only change the value of the field.
Please note: It might be required to check in LYNX which custom field / units of measure the IDs refer to in the custom fields / units of measure settings in the configuration.
Please note: For PUT and PATCH requests, you are only able to send one object at a time.
Using PUT request
For the PUT request, the body of the request needs to be the full object, with the values of the specific properties under fields modified as desired.
All the fields before the fields tab in an object are base properties. These properties must always be included and are not from the objects itself. Under the fields property is a list of the properties of the object itself whose values can be modified.
The layout of the object is as follows:
{
"id": 0,
"luid": "string",
"containsData": true,
"isExternal": true,
"rights": 0,
"version": 0,
"info": {
"state": "None",
"failed": true,
"isRestUpdate": true,
"newID": 0,
"extraInfo": "string"
},
"Fields": {
etc..
}
}
Using PATCH request
For the PATCH request, you do not need to include the full object, but only the fields that are needed to modify. You are required to keep some information in the base properties of the object, namely:
- ObjectType: The type of the object, for example "Task".
- ID: The ID of the object you want to modify.
- Version: This is to check if you are editing the latest version in the server.
- Fields: Here you can include the properties you want to modify with their values.
For example:
{
"ObjectType": "ADato.Service.Task",
"ID": 7185663,
"Version": 79565052,
"fields": {
"Description": "I like sheep alot, because they are cute"
}
}
Comments
0 comments
Please sign in to leave a comment.