{"id":6450,"date":"2022-01-05T01:40:37","date_gmt":"2022-01-05T00:40:37","guid":{"rendered":"https:\/\/help.cirrus-shield.com\/?post_type=docs&#038;p=6450"},"modified":"2026-09-24T09:35:31","modified_gmt":"2026-09-24T08:35:31","slug":"source-code-examples","status":"publish","type":"docs","link":"https:\/\/help.cirrus-shield.com\/en\/docs\/developer-guide\/rest-api\/source-code-examples\/","title":{"rendered":"Source code examples"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u26a0\ufe0f The <code>authToken<\/code> parameter below is part of the <strong>legacy authentication method<\/strong>. For new integrations, use <strong>OAuth 2.0<\/strong> instead and send the access token in the <code>Authorization: Bearer &lt;access_token&gt;<\/code> header rather than as a URL parameter. See <a href=\"https:\/\/help.cirrus-shield.com\/en\/docs\/developer-guide\/rest-api\/authtoken\/\">1. AuthToken \u2014 OAuth 2.0 Authentication<\/a> for the full documentation.<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">You will find on this page sample code source that interacts with the Cirrus Shield REST API. We grouped the examples by either tool or programming language. If you don&#8217;t know where to start, start with the Postman collection.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Postman<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Download the following Postman collection, it contains a various set of calls to the REST API of Cirrus Shield : <a href=\"https:\/\/help.cirrus-shield.com\/wp-content\/uploads\/2022\/01\/Cirrus-Shield-REST-API-Samples.postman_collection.json_.zip\">Download<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">.Net<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Here are some samples of using Cirrrus Shield&#8217;s REST API with .Net<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Authenticate (OAuth 2.0)<\/strong><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Use the Client Credentials flow to obtain an access token, then attach it to every call via the <code>Authorization: Bearer<\/code> header. See <a href=\"https:\/\/help.cirrus-shield.com\/en\/docs\/developer-guide\/rest-api\/authtoken\/\">1. AuthToken \u2014 OAuth 2.0 Authentication<\/a> for the full details and how to get a token.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var accessToken = await GetOAuthAccessTokenAsync(); \/\/ Client Credentials flow \u2014 see the OAuth 2.0 guide\nHttp.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(\"Bearer\", accessToken);<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Select a list of projects<\/strong><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>        public async Task&lt;List&lt;Project&gt;&gt; GetActiveProjects()\n        {\n            try\n            {\n                List&lt;Project&gt; listOfActiveProjects = new List&lt;Project&gt;();\n                var csProjectsStr = await Http.GetStringAsync(ServiceEndpoint + \"\/Query?selectQuery=Select+Id,Name+from+Project+where+Status='In+Progress'\");\n\n                XElement csProjectsXml = XElement.Parse(csProjectsStr);\n\n                foreach (XElement xe in csProjectsXml.Descendants(\"Project\"))\n                {\n                    Project prj = new Project() { Id = xe.Element(\"Id\").Value, Name = xe.Element(\"Name\").Value };\n                    listOfActiveProjects.Add(prj);\n                }\n                return listOfActiveProjects.OrderBy(o =&gt; o.Name).ToList();\n            }\n            catch (Exception e)\n            {\n                throw e;\n            }\n        }<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Create a record (object : Time) <\/strong><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>public async Task&lt;Time&gt; SaveTimeItem(Time timeItem)\n        {\n            try\n            {\n                var xmlData = new XElement(\"Data\", \"\");\n                var xmlTime = new XElement(\"Time\", \"\");\n                xmlTime.Add(new XElement(\"Id\", timeItem.Id));\n                if (string.IsNullOrEmpty(timeItem.Name))\n                    xmlTime.Add(new XElement(\"Name\", timeItem.Name));\n                xmlTime.Add(new XElement(\"OwnerId\", timeItem.OwnerId));\n                xmlTime.Add(new XElement(\"Work_Site\", timeItem.Work_Site));\n                xmlTime.Add(new XElement(\"Date\", timeItem.Date.ToString(\"yyyy-MM-dd\"))); \/\/ DateTime format: yyyy-MM-dd HH-mm-sszz\n                xmlTime.Add(new XElement(\"Description\", timeItem.Description));\n                xmlTime.Add(new XElement(\"Hours\", timeItem.Hours.ToString(System.Globalization.CultureInfo.CurrentCulture)));\n                xmlTime.Add(new XElement(\"Project\", timeItem.ProjectId));\n                xmlTime.Add(new XElement(\"Project_Budget\", timeItem.ProjectBudgetId));\n                xmlTime.Add(new XElement(\"Check_out_Date_Time\", timeItem.CheckOutDateTime.ToString(\"yyyy-MM-dd HH:mm:sszz\")));\n                xmlTime.Add(new XElement(\"Check_in_Date_Time\", timeItem.CheckInDateTime.ToString(\"yyyy-MM-dd HH:mm:sszz\")));\n\n                xmlData.Add(xmlTime);\n\n                var content = new StringContent(\"=\" + HttpUtility.UrlEncode(xmlData.ToString()), Encoding.UTF8, \"application\/x-www-form-urlencoded\"); \/\/ we could also use FormUrlEncodedContent\n                var response = await Http.PostAsync(ServiceEndpoint + \"\/DataAction\/Time?action=upsert&amp;matchingFieldName=id\", content);\n                var responseStatusCode = response.StatusCode;\n                var responseBody = await response.Content.ReadAsStringAsync();\n                var apiResponse = XElement.Parse(responseBody);\n                Console.WriteLine(\" ### Saving Time Item PAYLOAD \\n\" + apiResponse + \"\\n ### \");\n\n                timeItem.Id = apiResponse.Descendants(\"id\").First().Value;\n\n                if (string.IsNullOrEmpty(timeItem.Name))\n                    timeItem.Name = apiResponse.Descendants(\"name\").First().Value;\n\n                if ((responseStatusCode != System.Net.HttpStatusCode.OK) || (apiResponse.Descendants(\"Success\").First().Value == \"False\"))\n                {\n                    Console.WriteLine(\"ErrorMessage : \" + apiResponse.Descendants(\"ErrorMessage\").First().Value);\n                    Console.WriteLine(\"Response Body : \" + responseBody);\n                    throw new Exception (\"There was an issue saving this Time, the server replied with the following information -- Status code: \" + responseStatusCode + \" -- Error Message : \" + apiResponse.Descendants(\"ErrorMessage\").First().Value + \" -- Please contact your administrator\\n\");\n                }\n                return timeItem;\n            }\n            catch (Exception e)\n            {\n                throw e;\n            }\n        }<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Delete a record (object : Time)<\/strong><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>        public async Task&lt;bool&gt; DeleteTimeItem(Time timeItem)\n        {\n            try\n            {\n                var xmlData = new XElement(\"Data\", \"\");\n                var xmlTime = new XElement(\"Time\", \"\");\n                xmlTime.Add(new XElement(\"Id\", timeItem.Id));\n                xmlData.Add(xmlTime);\n\n                var content = new StringContent(\"=\" + HttpUtility.UrlEncode(xmlData.ToString()), Encoding.UTF8, \"application\/x-www-form-urlencoded\"); \/\/ we could also use FormUrlEncodedContent\n                var response = await Http.PostAsync(ServiceEndpoint + \"\/DataAction\/Time?action=delete&amp;matchingFieldName=id\", content);\n                Console.WriteLine(\"REST API DELETE call (careful with what you do on production data): \" + response);\n\n                var responseStatusCode = response.StatusCode;\n                var responseBody = await response.Content.ReadAsStringAsync();\n\n                if (responseStatusCode != System.Net.HttpStatusCode.OK)\n                {\n                    throw new Exception(\"There was an issue deleting this Time, the server replied with the following error -- Status code: \" + responseStatusCode + \" -- Response body : \" + responseBody + \" -- Please contact your administrator\\n\");\n                }\n\n                return true;\n            }\n            catch (Exception e)\n            {\n                throw e;\n            }\n        }<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">PHP<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Here are some samples of using the REST API with PHP.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Create an Opportunity<\/strong><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">This example previously used the legacy authToken flow. Authenticate now with OAuth 2.0 (Client Credentials flow) and include the access token in the <code>Authorization: Bearer &lt;access_token&gt;<\/code> header of each curl call (via <code>CURLOPT_HTTPHEADER<\/code>) rather than as a URL parameter. See <a href=\"https:\/\/help.cirrus-shield.com\/en\/docs\/developer-guide\/rest-api\/authtoken\/\">1. AuthToken \u2014 OAuth 2.0 Authentication<\/a> for a full example of obtaining the token.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Select a Lead<\/strong><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">This example previously used the legacy authToken flow. Authenticate now with OAuth 2.0 (Client Credentials flow) and include the access token in the <code>Authorization: Bearer &lt;access_token&gt;<\/code> header of each curl call (via <code>CURLOPT_HTTPHEADER<\/code>) rather than as a URL parameter. See <a href=\"https:\/\/help.cirrus-shield.com\/en\/docs\/developer-guide\/rest-api\/authtoken\/\">1. AuthToken \u2014 OAuth 2.0 Authentication<\/a> for a full example of obtaining the token.<\/p>\n\n","protected":false},"author":1,"featured_media":0,"parent":944,"menu_order":9,"comment_status":"open","ping_status":"closed","template":"","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_is_vendor_doc":"0","footnotes":""},"doc_tag":[],"class_list":["post-6450","docs","type-docs","status-publish","hentry"],"comment_count":0,"_links":{"self":[{"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/6450","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/comments?post=6450"}],"version-history":[{"count":4,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/6450\/revisions"}],"predecessor-version":[{"id":12251,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/6450\/revisions\/12251"}],"up":[{"embeddable":true,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/944"}],"next":[{"title":"Important Notes","link":"https:\/\/help.cirrus-shield.com\/en\/docs\/developer-guide\/rest-api\/important-notess\/","href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/6522"}],"prev":[{"title":"9. SendEmailWithAttachments","link":"https:\/\/help.cirrus-shield.com\/en\/docs\/developer-guide\/rest-api\/sendemailwithattachments\/","href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/6517"}],"wp:attachment":[{"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/media?parent=6450"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/doc_tag?post=6450"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}