Answers.Body: <p>It doesn't quite feel right to me on the empty vs null front - playing around with the API explorer in 4.7.15, but what I can say is if I do an api call for a contact ID (say, 3) with nickname IS NULL as follows:</p>
  
  <pre><code>CRM.api3('Contact', 'get', {
    "sequential": 1,
    "id": 3,
    "nick_name": {"IS NULL":1}
  })
  </code></pre>
  
  <p>I come up with the result for cid 3 including <code>"nick_name": "",</code> (which would say to me that it's <em>empty</em> instead of IS NULL... but comes up with the previous api call anyways.</p>
  
  <p>Then I run the following test by adding a nickname:</p>
  
  <pre><code>CRM.api3('Contact', 'create', {
    "sequential": 1,
    "contact_type": "Individual",
    "id": 3,
    "nick_name": "nickname"
  })
  </code></pre>
  
  <p>and run the same GET query as above, and get no results as follows:</p>
  
  <pre><code>{
      "is_error": 0,
      "version": 3,
      "count": 0,
      "values": []
  }
  </code></pre>
  
  <p>If I then run:</p>
  
  <pre><code>CRM.api3('Contact', 'create', {
    "sequential": 1,
    "contact_type": "Individual",
    "id": 3,
    "nick_name": ""
  })
  </code></pre>
  
  <p>and run the first GET query... I come up with the same result as the beginning again... which appears to be a contact with nickname empty ("") rather than null.</p>
  
  <p><strong>TLDR;</strong> It looks like you can use </p>
  
  <pre><code>CRM.api3('Contact', 'create', {
    "sequential": 1,
    "contact_type": "Individual",
    "id": 3,
    "nick_name": ""
  })
  </code></pre>
  
  <p>even though it doesn't feel quite right... if you're trying to pull that contact up with "nickname IS NULL" searches using the api.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-28T20:09:37.603Z
Answers.Text: This is cool. To my surprise, supplying an empty string for the field value, actually does set the field to `NULL`, and it works for other non-string field types like `int` and `datetime`.
Answers.UserDisplayName: Sean
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-28T20:28:39.883Z
Answers.Text: Sounds like it's a feature! Thanks for confirming :)
Answers.UserDisplayName: Eli Lisseck
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-28T19:38:01.650Z
Answers.LastActivityDate: 2017-03-28T19:38:01.650Z
Answers.UserDisplayName: Eli Lisseck
Body: <p>Let's say I have a contact which exists and has <code>id = 12345</code>. I can use the API like this...</p>
  
  
  
  <pre><code>CRM.api3('Contact', 'create', {"id": 12345, "nick_name": "Bob"});
  </code></pre>
  
  <p>to change the contact's nick name. Cool. </p>
  
  <hr>
  
  <p>But when I try this...</p>
  
  
  
  <pre><code>CRM.api3('Contact', 'create', {"id": 12345, "nick_name": null});
  </code></pre>
  
  <p>the call completes with success but does <em>not</em> set the <code>nick_name</code> field to <code>NULL</code> as I'd expect. Why? Is there some other way I can do it?</p>
  
Tags: <api>
Title: How can I use the API to set a field to NULL on an existing record?
ThreadText: # How can I use the API to set a field to NULL on an existing record?
  
  (Asked by: username_0 on 2017-03-28)
  
  Let's say I have a contact which exists and has id = 12345. I can use the API like this...
  CRM.api3('Contact', 'create', {"id": 12345, "nick_name": "Bob"});
  
  to change the contact's nick name. Cool. 
  
  But when I try this...
  CRM.api3('Contact', 'create', {"id": 12345, "nick_name": null});
  
  the call completes with success but does not set the nick_name field to NULL as I'd expect. Why? Is there some other way I can do it?
  
  **Tags:** api
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-03-28. Score: 3 | Accepted answer
  
  It doesn't quite feel right to me on the empty vs null front - playing around with the API explorer in 4.7.15, but what I can say is if I do an api call for a contact ID (say, 3) with nickname IS NULL as follows:
  CRM.api3('Contact', 'get', {
    "sequential": 1,
    "id": 3,
    "nick_name": {"IS NULL":1}
  })
  
  I come up with the result for cid 3 including "nick_name": "", (which would say to me that it's empty instead of IS NULL... but comes up with the previous api call anyways.
  Then I run the following test by adding a nickname:
  CRM.api3('Contact', 'create', {
    "sequential": 1,
    "contact_type": "Individual",
    "id": 3,
    "nick_name": "nickname"
  })
  
  and run the same GET query as above, and get no results as follows:
  {
      "is_error": 0,
      "version": 3,
      "count": 0,
      "values": []
  }
  
  If I then run:
  CRM.api3('Contact', 'create', {
    "sequential": 1,
    "contact_type": "Individual",
    "id": 3,
    "nick_name": ""
  })
  
  and run the first GET query... I come up with the same result as the beginning again... which appears to be a contact with nickname empty ("") rather than null.
  TLDR; It looks like you can use 
  CRM.api3('Contact', 'create', {
    "sequential": 1,
    "contact_type": "Individual",
    "id": 3,
    "nick_name": ""
  })
  
  even though it doesn't feel quite right... if you're trying to pull that contact up with "nickname IS NULL" searches using the api.
  
  > **Comments:**
  > **username_0**: This is cool. To my surprise, supplying an empty string for the field value, actually does set the field to `NULL`, and it works for other non-string field types like `int` and `datetime`.  
  > **username_1**: Sounds like it's a feature! Thanks for confirming :)  
  
  ---
  
  