Answers.Body: <p>Please, do not put the api_key nor key into the get parameter, to they don't end up in logs and other places, they are better as a post param.</p>
  
  <p>As for your question, you can have json="{'id':2..."} as a param, ie json encode the whole contact and put as as a string param into a (post) json param</p>
  
  <p>You might be safer to return only the modified param, as some are likely to be ignored (eg. the modification_date) or might expect a different format when modified than read (less and less a problem, but you might bump into edge cases still)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-27T15:09:30.947Z
Answers.LastActivityDate: 2015-07-27T15:09:30.947Z
Answers.UserDisplayName: Xavier
Body: <p>We are trying to update a contact via the REST API. But instead of submitting the changed values as separate post parameters (e.g. &quot;nick_name&quot;)</p>
  <pre><code>http://d46.demo.civicrm.org/sites/all/modules/civicrm/extern/rest.php?api_key=myscretapikey&amp;key=sitekey&amp;json=1&amp;version=3&amp;contact_id=2&amp;entity=Contact&amp;action=create&amp;nick_name=Kathy
  </code></pre>
  <p>we want to submit the <strong>whole contact</strong> JSON object with its changed values as part of the <strong>request body</strong>:</p>
  <pre><code>POST http://d46.demo.civicrm.org/sites/all/modules/civicrm/extern/rest.php?api_key=myscretapikey&amp;key=sitekey&amp;json=1&amp;version=3&amp;contact_id=2&amp;entity=Contact&amp;action=create
  Content-Type: application/json 
  { &quot;id&quot;:&quot;2&quot;, &quot;contact_type&quot;:&quot;Individual&quot;, &quot;contact_sub_type&quot;:&quot;&quot;, &quot;do_not_email&quot;:&quot;0&quot;, &quot;do_not_phone&quot;:&quot;0&quot;, &quot;do_not_mail&quot;:&quot;0&quot;, &quot;do_not_sms&quot;:&quot;0&quot;, &quot;do_not_trade&quot;:&quot;0&quot;, &quot;is_opt_out&quot;:&quot;0&quot;, &quot;legal_identifier&quot;:&quot;&quot;, &quot;external_identifier&quot;:&quot;&quot;, &quot;sort_name&quot;:&quot;Adams, Kathleen&quot;, &quot;display_name&quot;:&quot;Kathleen Adams&quot;, &quot;nick_name&quot;:&quot;Kathy&quot;, &quot;legal_name&quot;:&quot;&quot;, &quot;image_URL&quot;:&quot;&quot;, &quot;preferred_communication_method&quot;:[&quot;3&quot;], &quot;preferred_language&quot;:&quot;&quot;, &quot;preferred_mail_format&quot;:&quot;Both&quot;, &quot;hash&quot;:&quot;163700750&quot;, &quot;api_key&quot;:&quot;&quot;, &quot;first_name&quot;:&quot;Kathleen&quot;, &quot;middle_name&quot;:&quot;&quot;, &quot;last_name&quot;:&quot;Adams&quot;, &quot;prefix_id&quot;:&quot;&quot;, &quot;suffix_id&quot;:&quot;&quot;, &quot;formal_title&quot;:&quot;&quot;, &quot;communication_style_id&quot;:&quot;&quot;, &quot;email_greeting_id&quot;:&quot;1&quot;, &quot;email_greeting_custom&quot;:&quot;&quot;, &quot;email_greeting_display&quot;:&quot;Dear Kathleen&quot;, &quot;postal_greeting_id&quot;:&quot;1&quot;, &quot;postal_greeting_custom&quot;:&quot;&quot;, &quot;postal_greeting_display&quot;:&quot;Dear Kathleen&quot;, &quot;addressee_id&quot;:&quot;1&quot;, &quot;addressee_custom&quot;:&quot;&quot;, &quot;addressee_display&quot;:&quot;Kathleen Adams&quot;, &quot;job_title&quot;:&quot;&quot;, &quot;gender_id&quot;:&quot;1&quot;, &quot;birth_date&quot;:&quot;1979-03-17&quot;, &quot;is_deceased&quot;:&quot;0&quot;, &quot;deceased_date&quot;:&quot;&quot;, &quot;household_name&quot;:&quot;&quot;, &quot;primary_contact_id&quot;:&quot;&quot;, &quot;organization_name&quot;:&quot;&quot;, &quot;sic_code&quot;:&quot;&quot;, &quot;user_unique_id&quot;:&quot;&quot;, &quot;created_date&quot;:&quot;&quot;, &quot;modified_date&quot;:&quot;2015-05-14 06:03:56&quot;}
  </code></pre>
  <p>Mostly this seems to work, but we have some issues. Is this an official way to update a contact? And if not, which would be a better one?</p>
  
Tags: <contacts><api><rest>
Title: Update contact via REST and JSON request body
ThreadText: # Update contact via REST and JSON request body
  
  (Asked by: username_0 on 2015-07-27)
  
  We are trying to update a contact via the REST API. But instead of submitting the changed values as separate post parameters (e.g. "nick\_name")
  
  ```
  http://d46.demo.civicrm.org/sites/all/modules/civicrm/extern/rest.php?api_key=myscretapikey&key=sitekey&json=1&version=3&contact_id=2&entity=Contact&action=create&nick_name=Kathy
  
  ```
  
  we want to submit the **whole contact** JSON object with its changed values as part of the **request body**:
  
  ```
  POST http://d46.demo.civicrm.org/sites/all/modules/civicrm/extern/rest.php?api_key=myscretapikey&key=sitekey&json=1&version=3&contact_id=2&entity=Contact&action=create
  Content-Type: application/json 
  { "id":"2", "contact_type":"Individual", "contact_sub_type":"", "do_not_email":"0", "do_not_phone":"0", "do_not_mail":"0", "do_not_sms":"0", "do_not_trade":"0", "is_opt_out":"0", "legal_identifier":"", "external_identifier":"", "sort_name":"Adams, Kathleen", "display_name":"Kathleen Adams", "nick_name":"Kathy", "legal_name":"", "image_URL":"", "preferred_communication_method":["3"], "preferred_language":"", "preferred_mail_format":"Both", "hash":"163700750", "api_key":"", "first_name":"Kathleen", "middle_name":"", "last_name":"Adams", "prefix_id":"", "suffix_id":"", "formal_title":"", "communication_style_id":"", "email_greeting_id":"1", "email_greeting_custom":"", "email_greeting_display":"Dear Kathleen", "postal_greeting_id":"1", "postal_greeting_custom":"", "postal_greeting_display":"Dear Kathleen", "addressee_id":"1", "addressee_custom":"", "addressee_display":"Kathleen Adams", "job_title":"", "gender_id":"1", "birth_date":"1979-03-17", "is_deceased":"0", "deceased_date":"", "household_name":"", "primary_contact_id":"", "organization_name":"", "sic_code":"", "user_unique_id":"", "created_date":"", "modified_date":"2015-05-14 06:03:56"}
  
  ```
  
  Mostly this seems to work, but we have some issues. Is this an official way to update a contact? And if not, which would be a better one?
  
  **Tags:** contacts, api, rest
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-07-27. Score: 5 | Accepted answer
  
  Please, do not put the api\_key nor key into the get parameter, to they don't end up in logs and other places, they are better as a post param.
  
  As for your question, you can have json="{'id':2..."} as a param, ie json encode the whole contact and put as as a string param into a (post) json param
  
  You might be safer to return only the modified param, as some are likely to be ignored (eg. the modification\_date) or might expect a different format when modified than read (less and less a problem, but you might bump into edge cases still)
  
  
  ---
  
  