Back to Collection Items
#include <C_CkHttpW.h>
#include <C_CkXmlW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkHttpResponseW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
HCkXmlW xml;
HCkStringBuilderW sbRequestBody;
HCkHttpResponseW resp;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
// Use this online tool to generate code from sample XML: Generate Code to Create XML
// The following XML is sent in the request body.
// <?xml version="1.0" encoding="utf-8"?>
// <task>
// <title>Updatetitle Task for a project</title>
// <description>Learning Tasks update API</description>
// <start-date>2021-11-22T00:00:00-08:00</start-date>
// <percentage>0</percentage>
// <linkable-id>15</linkable-id>
// <linkable-type>Project</linkable-type>
// <linkable>
// <id>15</id>
// </linkable>
// </task>
//
xml = CkXmlW_Create();
CkXmlW_putTag(xml,L"task");
CkXmlW_UpdateChildContent(xml,L"title",L"Updatetitle Task for a project");
CkXmlW_UpdateChildContent(xml,L"description",L"Learning Tasks update API");
CkXmlW_UpdateChildContent(xml,L"start-date",L"2021-11-22T00:00:00-08:00");
CkXmlW_UpdateChildContentInt(xml,L"percentage",0);
CkXmlW_UpdateChildContentInt(xml,L"linkable-id",15);
CkXmlW_UpdateChildContent(xml,L"linkable-type",L"Project");
CkXmlW_UpdateChildContentInt(xml,L"linkable|id",15);
// Adds the "Authorization: Bearer <access_token>" header.
CkHttpW_putAuthToken(http,L"<access_token>");
sbRequestBody = CkStringBuilderW_Create();
CkXmlW_GetXmlSb(xml,sbRequestBody);
resp = CkHttpW_PTextSb(http,L"PUT",L"[\"id\"]}]",sbRequestBody,L"utf-8",L"application/xml",FALSE,FALSE);
if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkXmlW_Dispose(xml);
CkStringBuilderW_Dispose(sbRequestBody);
return;
}
wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
CkHttpResponseW_Dispose(resp);
CkHttpW_Dispose(http);
CkXmlW_Dispose(xml);
CkStringBuilderW_Dispose(sbRequestBody);
}
Curl Command
curl -X PUT
-H "Authorization: Bearer <access_token>"
-d '<task>
<title>Updatetitle Task for a project</title>
<description>Learning Tasks update API</description>
<start-date>2021-11-22T00:00:00-08:00</start-date>
<percentage>0</percentage>
<linkable-id>15</linkable-id>
<linkable-type>Project</linkable-type>
<linkable>
<id>15</id>
</linkable>
</task>'
https://domain.com/projects/:project_id/tasks/:task_id?fields=["id","created_at","updated_at","title","description","status","owner_id","due_date","start_date","duration","percentage","linkable_type","linkable_id",{ "owner": [ "id"]},{ "resolved_by": [ "id"]},{ "linkable": ["id","created_at","updated_at","name","active","open","description","mention_name","start_date","external_reference_number","end_date","commodity_id","status",{"template_group":["id","name",{"custom_fields": {}}]},{"category": ["id","name",{"custom_fields": {}}]},{"department":["id","name",{"custom_fields": {}}]},{"users": ["id","email",{"custom_fields": {}}]},{"commodity":["id","name",{"custom_fields": {}}]},{"custom_fields": {}}]},{ "created_by": [ "id"]},{ "updated_by": ["id"]}]
Postman Collection Item JSON
{
"name": "Update existing Task",
"request": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "<task>\n <title>Updatetitle Task for a project</title>\n <description>Learning Tasks update API</description>\n <start-date>2021-11-22T00:00:00-08:00</start-date>\n <percentage>0</percentage>\n <linkable-id>15</linkable-id>\n <linkable-type>Project</linkable-type>\n <linkable>\n <id>15</id>\n </linkable>\n</task>",
"options": {
"raw": {
"language": "xml"
}
}
},
"url": {
"raw": "{{URL}}/projects/:project_id/tasks/:task_id?fields=[\"id\",\"created_at\",\"updated_at\",\"title\",\"description\",\"status\",\"owner_id\",\"due_date\",\"start_date\",\"duration\",\"percentage\",\"linkable_type\",\"linkable_id\",{ \"owner\": [ \"id\"]},{ \"resolved_by\": [ \"id\"]},{ \"linkable\": [\"id\",\"created_at\",\"updated_at\",\"name\",\"active\",\"open\",\"description\",\"mention_name\",\"start_date\",\"external_reference_number\",\"end_date\",\"commodity_id\",\"status\",{\"template_group\":[\"id\",\"name\",{\"custom_fields\": {}}]},{\"category\": [\"id\",\"name\",{\"custom_fields\": {}}]},{\"department\":[\"id\",\"name\",{\"custom_fields\": {}}]},{\"users\": [\"id\",\"email\",{\"custom_fields\": {}}]},{\"commodity\":[\"id\",\"name\",{\"custom_fields\": {}}]},{\"custom_fields\": {}}]},{ \"created_by\": [ \"id\"]},{ \"updated_by\": [\"id\"]}]",
"host": [
"{{URL}}"
],
"path": [
"projects",
":project_id",
"tasks",
":task_id"
],
"query": [
{
"key": "fields",
"value": "[\"id\",\"created_at\",\"updated_at\",\"title\",\"description\",\"status\",\"owner_id\",\"due_date\",\"start_date\",\"duration\",\"percentage\",\"linkable_type\",\"linkable_id\",{ \"owner\": [ \"id\"]},{ \"resolved_by\": [ \"id\"]},{ \"linkable\": [\"id\",\"created_at\",\"updated_at\",\"name\",\"active\",\"open\",\"description\",\"mention_name\",\"start_date\",\"external_reference_number\",\"end_date\",\"commodity_id\",\"status\",{\"template_group\":[\"id\",\"name\",{\"custom_fields\": {}}]},{\"category\": [\"id\",\"name\",{\"custom_fields\": {}}]},{\"department\":[\"id\",\"name\",{\"custom_fields\": {}}]},{\"users\": [\"id\",\"email\",{\"custom_fields\": {}}]},{\"commodity\":[\"id\",\"name\",{\"custom_fields\": {}}]},{\"custom_fields\": {}}]},{ \"created_by\": [ \"id\"]},{ \"updated_by\": [\"id\"]}]"
}
],
"variable": [
{
"key": "project_id",
"value": "15"
},
{
"key": "task_id",
"value": "845"
}
]
}
},
"response": [
]
}