Writing API data

Previous Next

Adding a Record

Data is added to the API using the POST command. For example, to add a material category, use the following command from your add-in:

POST /api/materialcategory


with the following encoded in the request body:

{

   "code": "BAN",

   "name": "Banners"

   "dsrl": 30

   "default": false

}


which corresponds to the following curl command (using JSON) :


curl -u gdjks23wdfhhjjjf5655njcdjhd:x -H "Content-type:application/json" -i -d

'{ "code": "BAN" }, { "name": "Banners" }, { "dsrl": "30" }, { "default": "false" } }' https://yourco.tidywork.com/api/materialcategory


where -the -d specifies the data (and triggers the POST command), and -i causes the response to be echoed on the command line.

The response header for a command should contain a status of 201 (created), and the message body contains a URL you can use to retrieve the result (using GET) if you wish to check it:

HTTP/1.1 201 Created


9d87dd36-f6ea-48ef-b8e2-bf0995979039


Updating a Record

Update an existing record using the PUT command, e.g.

PUT /api/materialcategory/9dcf7d83-31de-488a-a105-b89cbc70bcd4


with something like the following encoded in the request body:

{

   "code": "BAN",

   "name": "Banners"

   "default": false

}


Note that one of the entity attributes ("dsrl") is omitted. These API methods may perform a partial update of the company entity. In this case, only the attributes required for this update need to be supplied (the others will be ignored). The attributes required for each call are specified in this documentation

The above corresponds to the following curl command to update the record:

curl -u gdjks23wdfhhjjjf5655njcdjhd:x -H "Content-type:application/xml" -i -X PUT -d '{ "code": "BAN" }, { "name": "Banners" }, { "default": "false" } }' https://yourco.tidywork.com/api/companyname/9dcf7d83-31de-488a-a105-b89cbc70bcd4


where the UID at the end of the command is the identifier for a particular company (obtained from a previous GET command). This will return the following response:

HTTP/1.1 200 OK

Deleting a Record

Delete an existing record using the DELETE command:

DELETE /api/materialcategory/9dcf7d83-31de-488a-a105-b89cbc70bcd4


where the UID at the end of the command is again the identifier for a particular company (obtained from a previous GET command). This will return the following response:

HTTP/1.1 200 OK