Answers.Body: <p>APIv3 does option-matching by default. APIv4 only does option-matching if you ask it to. The way to do that is by specifying what property of the option you are passing in. Typically <code>:name</code> for the machine name or <code>:label</code> for the localized label.</p>
  <p>Try this api call:</p>
  <pre><code>$ cv api4 Contact.update '{&quot;where&quot;:[[&quot;id&quot;,&quot;=&quot;,202]],&quot;values&quot;:{&quot;constituent_information.Marital_Status:label&quot;:&quot;Married&quot;}}'
  </code></pre>
  <p>Passing in an invalid option should fail.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-07T19:18:52.507Z
Answers.Text: Thanks - so `:name` and `:label` are more than just convenience: they determine whether error-checking is applied.  Using `constituent_information.Marital_Status` I can set any random invalid values, but using invalid values with `:label` does fail although with the rather cryptic "is not of type String".
Answers.UserDisplayName: Aidan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-06T20:26:24.027Z
Answers.LastActivityDate: 2020-12-06T20:26:24.027Z
Answers.UserDisplayName: Coleman
Body: <p>Is there a way to make APIv4 validate options when creating/updating?</p>
  <p>For example, using the demo data I can run:</p>
  <pre><code>$ cv api4 Contact.update '{&quot;where&quot;:[[&quot;id&quot;,&quot;=&quot;,202]],&quot;values&quot;:{&quot;constituent_information.Marital_Status&quot;:&quot;Junk&quot;}}'
  </code></pre>
  <p>and then verify the update took place with:</p>
  <pre><code>$ cv api4 Contact.get '{&quot;select&quot;:[&quot;constituent_information.Marital_Status&quot;],&quot;where&quot;:[[&quot;id&quot;,&quot;=&quot;,202]]}'
  </code></pre>
  <p>producing:</p>
  <pre><code>[
      {
          &quot;id&quot;: 202,
          &quot;constituent_information.Marital_Status&quot;: &quot;Junk&quot;
      }
  ]
  </code></pre>
  <p>So <code>Marital_Status</code> is set to <code>Junk</code> - even though that is not a valid option. When viewing this in the UI the field now shows as blank.</p>
  <p>I could use <code>getfields</code> to get the valid options and check them before doing the API call but an option (or default behaviour) on the API call to produce some sort of error or warning would be useful.</p>
  
Tags: <apiv4>
Title: Validating options in API4?
ThreadText: # Validating options in API4?
  
  (Asked by: username_0 on 2020-12-04)
  
  Is there a way to make APIv4 validate options when creating/updating?
  For example, using the demo data I can run:
  $ cv api4 Contact.update '{"where":[["id","=",202]],"values":{"constituent_information.Marital_Status":"Junk"}}'
  
  and then verify the update took place with:
  $ cv api4 Contact.get '{"select":["constituent_information.Marital_Status"],"where":[["id","=",202]]}'
  
  producing:
  [
      {
          "id": 202,
          "constituent_information.Marital_Status": "Junk"
      }
  ]
  
  So Marital_Status is set to Junk - even though that is not a valid option. When viewing this in the UI the field now shows as blank.
  I could use getfields to get the valid options and check them before doing the API call but an option (or default behaviour) on the API call to produce some sort of error or warning would be useful.
  
  **Tags:** apiv4
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-12-06. Score: 1
  
  APIv3 does option-matching by default. APIv4 only does option-matching if you ask it to. The way to do that is by specifying what property of the option you are passing in. Typically :name for the machine name or :label for the localized label.
  Try this api call:
  $ cv api4 Contact.update '{"where":[["id","=",202]],"values":{"constituent_information.Marital_Status:label":"Married"}}'
  
  Passing in an invalid option should fail.
  
  > **Comments:**
  > **username_0**: Thanks - so `:name` and `:label` are more than just convenience: they determine whether error-checking is applied.  Using `constituent_information.Marital_Status` I can set any random invalid values, but using invalid values with `:label` does fail although with the rather cryptic "is not of type String".  
  
  ---
  
  