Back to Collection Items
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
-- 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>New Task for a project</title>
-- <description>Learning Tasks API</description>
-- <start-date>2021-11-23T00:00:00-08:00</start-date>
-- <percentage>10</percentage>
-- <linkable-id>15</linkable-id>
-- <linkable-type>Project</linkable-type>
-- <linkable>
-- <id>15</id>
-- </linkable>
-- </task>
--
DECLARE @xml int
-- Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Xml', @xml OUT
EXEC sp_OASetProperty @xml, 'Tag', 'task'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'title', 'New Task for a project'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'description', 'Learning Tasks API'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'start-date', '2021-11-23T00:00:00-08:00'
EXEC sp_OAMethod @xml, 'UpdateChildContentInt', NULL, 'percentage', 10
EXEC sp_OAMethod @xml, 'UpdateChildContentInt', NULL, 'linkable-id', 15
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'linkable-type', 'Project'
EXEC sp_OAMethod @xml, 'UpdateChildContentInt', NULL, 'linkable|id', 15
-- Adds the "Authorization: Bearer <access_token>" header.
EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'
DECLARE @sbRequestBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbRequestBody OUT
EXEC sp_OAMethod @xml, 'GetXmlSb', @success OUT, @sbRequestBody
DECLARE @resp int
EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'POST', '["id"]}]', @sbRequestBody, 'utf-8', 'application/xml', 0, 0
EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @xml
EXEC @hr = sp_OADestroy @sbRequestBody
RETURN
END
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
PRINT @iTmp0
EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @xml
EXEC @hr = sp_OADestroy @sbRequestBody
END
GO
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-d '<task>
<title>New Task for a project</title>
<description>Learning Tasks API</description>
<start-date>2021-11-23T00:00:00-08:00</start-date>
<percentage>10</percentage>
<linkable-id>15</linkable-id>
<linkable-type>Project</linkable-type>
<linkable>
<id>15</id>
</linkable>
</task>'
https://domain.com/projects/:project_id/tasks?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": "Create a Task against existing Project",
"request": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "<task>\n <title>New Task for a project</title>\n <description>Learning Tasks API</description>\n <start-date>2021-11-23T00:00:00-08:00</start-date>\n <percentage>10</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?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"
],
"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"
}
]
}
},
"response": [
]
}