{"id":3954,"date":"2020-04-20T12:40:07","date_gmt":"2020-04-20T11:40:07","guid":{"rendered":"https:\/\/help.cirrus-shield.com\/docs\/developer-guide\/rest-api\/data-action\/"},"modified":"2022-01-11T09:43:00","modified_gmt":"2022-01-11T08:43:00","slug":"data-action","status":"publish","type":"docs","link":"https:\/\/help.cirrus-shield.com\/en\/docs\/developer-guide\/rest-api\/data-action\/","title":{"rendered":"5. Data Action"},"content":{"rendered":"\n<ul class=\"wp-block-list\"><li><strong><u><span class=\"has-inline-color has-luminous-vivid-orange-color\">URL:<\/span><\/u> <\/strong><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\n\/RestApi\/DataAction\/&lt;objectName>?authToken=&lt;authToken>&amp;action=&lt;insert|update|upsert|delete>&amp;matchingFieldName=&lt;matchingFieldName>&amp;useExternalId=&lt;false|true>\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><span class=\"has-inline-color has-luminous-vivid-orange-color\"><u>Method:<\/u> <\/span><\/strong>POST<\/li><li><strong><u><span class=\"has-inline-color has-luminous-vivid-orange-color\">URL Params:<\/span><\/u><\/strong><ul><li>objectName [string] [Required]=the name of the object that the user wants to insert\/update\/upsert\/delete records from<\/li><li>authToken [string] [Required]=the authentication token<\/li><li>action [string] [Required]=the action that the user wants to apply (insert, update, upsert or delete)<\/li><li>matchingFieldName [string] [Required]=the name of the field that is considered to be the unique field in the sent records<\/li><li>The &#8220;useExternalId&#8221; parameter is optional. And if not sent in the URL it will take the default value which is \u201ctrue\u201d. <br>If &#8220;useExternalId&#8221;=true then when importing data through the Rest API, the lookup fields will have to be set to the value in the \u201cExternal Id\u201d field of the lookup record.<br><br>If &#8220;useExternalId&#8221;=false or there are no \u201cExternal Id\u201d field set on the parent object, then when importing data through the Rest API, the lookup fields will have to be set to the \u201cId\u201d field of the lookup record.<\/li><\/ul><\/li><\/ul>\n\n\n\n<p><span style=\"text-decoration: underline;\">Example:<\/span><br><br>If we want to import following Contact record through the Rest API (field \u201cAccount\u201d is a lookup field to the \u201cAccount\u201d parent object and the \u201cName\u201d field on the \u201cAccount\u201d object is an \u201cExternal Id\u201d field):<\/p>\n\n\n\n<p>1- If useExternalId is not set or set to \u201ctrue\u201d:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;Data&gt;&lt;Contact&gt;&lt;FirstName&gt;Sarah&lt;\/FirstName&gt;&lt;LastName&gt;Johnson&lt;\/LastName&gt;&lt;Account&gt;Test Account 1&lt;\/Account&gt;&lt;\/Contact&gt;&lt;\/Data&gt;<\/code><\/pre>\n\n\n\n<p>2- If useExternalId is set to \u201cfalse\u201d:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;Data&gt;&lt;Contact&gt;&lt;FirstName&gt;Sarah&lt;\/FirstName&gt;&lt;LastName&gt;Johnson&lt;\/LastName&gt;&lt;Account&gt;2458939956261816452&lt;\/Account&gt;&lt;\/Contact&gt;&lt;\/Data&gt;<\/code><\/pre>\n\n\n\n<p>where lookup record \u201cAccount\u201d is:<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td><strong>Id<\/strong><\/td><td><strong>Name<\/strong><\/td><\/tr><tr><td>2458939956261816452<\/td><td>Test Account 1<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><u><span class=\"has-inline-color has-luminous-vivid-orange-color\">Data Params:<\/span><\/u><\/strong><ul><li>xmlData [XML]=the data records to insert\/update\/upsert\/delete<\/li><\/ul><\/li><\/ul>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;Data&gt;\n&lt;Account&gt;\n&lt;Name&gt;\n\nAccount Test 1\n\n&lt;\/Name&gt;\n\n&lt;Address&gt;\n\nAddress Test 1\n\n&lt;\/Address&gt;\n&lt;\/Account&gt;\n\n&lt;Account&gt;\n&lt;Name&gt;\n\nAccount Test 2\n\n&lt;\/Name&gt;\n\n&lt;Address&gt;\n\nAddress Test 2\n\n&lt;\/Address&gt;\n&lt;\/Account&gt;\n&lt;\/Data&gt;<\/code><\/pre>\n\n\n\n<p>When sending data parameters from a php page and having a field of type \u00ab Datetime \u00bb, we must put this function urlencode() in order not to lose the \u201c+\u201d sign on the server side and to be saved correctly in the database.<\/p>\n\n\n\n<p>If the function is not used, the value will saved without the \u201c+\u201d sign like this &#8220;2017-06-12 15:40: 47 02 &#8221; instead of &#8220;2017-06-12 15:40: 47+02 &#8220;.<\/p>\n\n\n\n<p>Example of using urlencode() :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ xmlData =  urlencode (\n\"&lt;Data&gt;\"\n\n\"&lt;Campaign&gt;\"\n\n\"&lt;Name&gt; Campagne-\". $ CampaignID. \"&lt;\/Name&gt;\"\n\n\"&lt;Campaign_ID&gt;\". $ CampaignID. \"&lt;\/Campaign_ID&gt;\"\n\n\"&lt;TestDateTime&gt;\"2017-06-12 15: 40: 47 + 02\".\"&lt;\/TestDateTime&gt;\"\n\n\"&lt;OwnerId&gt;\".$ OwnerID. \"&lt;\/OwnerId&gt;\"\n\n\n\"&lt;Campaign&gt;\"\n\n\n\"&lt;Data&gt;\"\n\n\n);<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><u><span class=\"has-inline-color has-luminous-vivid-orange-color\">Success Response:<\/span><\/u><\/strong><ul><li>Status Code=200 (OK)<\/li><li>Returned Data [in XML or JSON]=a list of the data records sent in the HTTP Post Request body with 2 additional fields for each record (1- Success (to indicate if the operation (insert\/update\/upsert\/delete) applied on the corresponding record was successful or not), 2- ErrorMessage (to indicate what is the error that caused the operation applied on this record to fail (in case of unsuccessful operation)))<\/li><\/ul><\/li><\/ul>\n\n\n\n<p><strong>Example of returned data:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;Data&gt;\n&lt;Account&gt;\n&lt;Name&gt;\n\nAccount Test 1\n\n&lt;\/Name&gt;\n\n&lt;Address&gt;\n\nAddress Test 1\n\n&lt;\/Address&gt;\n\n&lt;Success&gt;\n\nFALSE\n\n&lt;\/Success&gt;\n\n&lt;ErrorMessage&gt;\n\nSome of the Lookup Fields contain invalid values\n\n&lt;\/ErrorMessage&gt;\n&lt;\/Account&gt;\n\n&lt;Account&gt;\n&lt;Name&gt;\n\nAccount Test 2\n\n&lt;\/Name&gt;\n\n&lt;Address&gt;\n\nAddress Test 2\n\n&lt;\/Address&gt;\n\n&lt;Success &gt;\n\nTRUE\n\n&lt;\/Success&gt;\n\n&lt;ErrorMessage \/&gt;\n&lt;\/Account&gt;\n&lt;\/Data&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><u><span class=\"has-inline-color has-luminous-vivid-orange-color\">Error Response:<\/span><\/u><\/strong><ul><li>Status Code=401 (Unauthorized) (in case of a wrong authentication token)<\/li><li>Or<\/li><li>Status Code=400 (BadRequest) (in case no object name was specified or no action was specified or there is an error in the xml data records sent in the HTTP Post Request body or if one record or more could not be inserted\/updated\/upserted\/deleted)<\/li><\/ul><\/li><\/ul>\n","protected":false},"author":12,"featured_media":0,"parent":944,"menu_order":4,"comment_status":"open","ping_status":"closed","template":"","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"doc_tag":[],"class_list":["post-3954","docs","type-docs","status-publish","hentry"],"comment_count":0,"_links":{"self":[{"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/3954","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\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/comments?post=3954"}],"version-history":[{"count":5,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/3954\/revisions"}],"predecessor-version":[{"id":6186,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/3954\/revisions\/6186"}],"up":[{"embeddable":true,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/944"}],"next":[{"title":"6. Upload File","link":"https:\/\/help.cirrus-shield.com\/en\/docs\/developer-guide\/rest-api\/upload-file\/","href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/3955"}],"prev":[{"title":"4. Query","link":"https:\/\/help.cirrus-shield.com\/en\/docs\/developer-guide\/rest-api\/query\/","href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/3952"}],"wp:attachment":[{"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/media?parent=3954"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/doc_tag?post=3954"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}