Retrieving Checklist Items with Section

Here is another question I got today.

Q. I’m using Field Checklists API to retrieve Checklists. But I cannot seem to distinguish items under different sections.

A. First, please make sure you use APIs under /fieldapi/. /api/get_checklists is deprecated.

You can use the following two REST calls to retrieve checklists and their detailed data:

  • GET /fieldapi/checklists/v1 — this allows to retrieve a list of checklists for a given project.
  • GET /fieldapi/checklists/v1/:id — this allows to retrieve the detailed information of a given checklist, including a list of items and sections. Here, “:id” is a id of a checklist. “:id” is specified as URL segment as oppose to a “name=parameter” pair.

Images below show a simple sample data in UI, and corresponding response from /fieldapi/checklists/v1/:id. I’m using the minimum data to make it easier to read data. In the JSON response, you see “sections” attributes. Checklist items are stored under a parent section.

6a019b00bdedf0970b01b7c79bf2ed970b

A sample Checklists in UI. Using simple data to make it easy to find corresponding values in the response below. 

6a019b00bdedf0970b01b8d12559b9970c6a019b00bdedf0970b01b7c79bf25a970b

 A sample response from /fieldapi/checklists/v1/:id call. Compare the values with the UI above. 

Below is a sample code snippet of /fieldapi/checklists/v1/:id using RestSharp library. Notice that we are using AddUrlSegment() with this call.

ChecklistsV1Id()

        public static string ChecklistsV1Id(string ticket, string project_id, string id)
        {
            // (1) Build request
            var client = new RestClient();
            client.BaseUrl = new System.Uri(_baseUrl);

            // Set resource or end point
            var request = new RestRequest();
            request.Resource = “/fieldapi/checklists/v1/{id};
            request.Method = Method.GET;

            // Add parameters
            request.AddParameter(“ticket”, ticket);
            request.AddParameter(“project_id”, project_id);

            request.AddUrlSegment(“id”, id);

            // (2) Execute request and get response
            IRestResponse response = client.Execute(request);

            // (3) Parse the response in a way you want.
            // …

            return “OK”;
        }

 

Mikako

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s