Answers.Body: <p>The checkPermissions line should be outside the values array. You can use http://{your-site}/civicrm/api4 to use the explorer to construct the correct code.</p>
  <pre><code>        civicrm_api4('Contact', 'create', [
              'values' =&gt; [
                  'contact_type' =&gt; 'Individual',
                  'first_name' =&gt; $_POST['first_name'],
                  'last_name' =&gt; $_POST['last_name'],
                  'display_name' =&gt; $_POST['username'],
              ],
              'checkPermissions' =&gt; false,
          ]);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-18T18:38:12.453Z
Answers.LastActivityDate: 2021-06-18T18:38:12.453Z
Answers.UserDisplayName: Demerit
Body: <p>With this code I created contact, but only when I'm authorized.</p>
  <pre><code>        civicrm_api4('Contact', 'create', [
              'values' =&gt; [
                  'contact_type' =&gt; 'Individual',
                  'checkPermissions' =&gt; false,
                  'first_name' =&gt; $_POST['first_name'],
                  'last_name' =&gt; $_POST['last_name'],
                  'display_name' =&gt; $_POST['username'],
              ],
          ]);
  </code></pre>
  <p><strong>But when I'm logout:</strong></p>
  <p><a href="https://i.sstatic.net/RYrOc.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/RYrOc.png" alt="enter image description here" /></a></p>
  
Tags: <apiv4>
Title: API V4 - Uncaught Exception: Authorization failed
ThreadText: # API V4 - Uncaught Exception: Authorization failed
  
  (Asked by: username_0 on 2021-06-18)
  
  With this code I created contact, but only when I'm authorized.
          civicrm_api4('Contact', 'create', [
              'values' => [
                  'contact_type' => 'Individual',
                  'checkPermissions' => false,
                  'first_name' => $_POST['first_name'],
                  'last_name' => $_POST['last_name'],
                  'display_name' => $_POST['username'],
              ],
          ]);
  
  But when I'm logout:
  
  **Tags:** apiv4
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-06-18. Score: 1 | Accepted answer
  
  The checkPermissions line should be outside the values array. You can use http://{your-site}/civicrm/api4 to use the explorer to construct the correct code.
          civicrm_api4('Contact', 'create', [
              'values' => [
                  'contact_type' => 'Individual',
                  'first_name' => $_POST['first_name'],
                  'last_name' => $_POST['last_name'],
                  'display_name' => $_POST['username'],
              ],
              'checkPermissions' => false,
          ]);
  
  
  ---
  
  