Create ToDos
Create ToDo
- Hover over the “domino-restapi-todo” collection name and click on the ellipsis (three dots). Select “Add Request”.
- Name the request “create todo” and click “Save to domino-restapi-todo”.
- Change the method from “GET” to “POST”.
- Set the URL as “{{HOST}}/document?dataSource=todorest”.
- Set the headers for “Authorization” and “Content-Type”.
- On the Body tab change the type to “Raw”.
-
Set the request body content to:
{ "Form": "todo", "name": "Sample to do from rest", "description": "Create some To Dos", "duedate": "2021-06-07T08:00:00.000Z", "priority": "Medium" }
-
A future REST service will update the To Do. Instead of manually setting the UNID each time, JavaScript code can be run in a test to extract the UNID from the response and store it in a collection variable. On the Test tab add the following test:
pm.test("Status code is 200", function () { pm.response.to.have.status(200); }); pm.test("Create ToDo", function () { var jsonData = pm.response.json(); pm.expect(jsonData).to.have.property("@meta"); pm.expect(jsonData['@meta']).to.have.property("unid") pm.collectionVariables.set("UNID", jsonData["@meta"].unid); });
Lines 1 - 3 is a test to check whether the creation was successful and a 200 HTTP status returned. Lines 4 - 8 is a test to look for an @unid property in the returning JSON. Line 5 extracts that JSON from the response. Line 6 checks it has an @unid property. Line 7 stores the value into an UNID collection variable.
- Click “Send”.
The ToDo will be created and the created document returned back. Note that it now has “completed” set to “false” and an @unid.
Click on the “domino-restapi-todo” collection and click on the Variables tab. You will see UNID has now been set with a value.
Bad Requests
- Change the priority to “foo”.
- Click “Send” and note that the ToDo is created, but the priority set to “Low”, as defined by the “On Save Formula”.
- Save the request.
Mark Complete / Incomplete
- Hover over the “domino-restapi-todo” collection name and click on the ellipsis (three dots). Select “Add Request”.
- Name the request “change complete” and click “Save to domino-restapi-todo”.
- Change the method from “GET” to “PUT”.
- Set the URL as “{{HOST}}/document/{{UNID}}?dataSource=todorest&mode=change-complete”. The “create todo” request added a test that saved the UNID of the created document to the collection variables, so we can just reference that in the URL.
- Set the headers for “Authorization” and “Content-Type”.
- On the Body tab change the type to “Raw”.
- Set the request body content to:
{
"Form": "todo",
"completed": "true"
}
- Click “Send”.
- Save the request.
Bad Request
- Remove the “Form” element from the request body JSON object.
-
Click Send. A HTTP 400 status (Bad Request) will be returned, saying that the provided object shopuld contrain property Form.
- Add another field to the payload “foo” with the value “bar”.
- Click Send. The field “foo” will have been ignored.