How To Create Or Update A User Or Lead Via API

Luca Micheli
Written by Luca MicheliLast updated 3 years ago

If you want to synchronize your backend with Customerly you can by using our API. First of all, you will need an App Token to use Customerly API.

Once you have a personal App Token you can start communicating with our API.



<?php


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.customerly.io/v1/users');


//Method used to create a user is POST
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);


//Replace your Access Token here
curl_setopt($ch, CURLOPT_HTTPHEADER, [
  'Authentication: AccessToken: REPLACE_YOUR_ACCESSTOKEN',
  'Content-Type: application/json; charset=utf-8',
]);


//Build an array of users
$json_array = [
  'users' => [
    [
      'email' => 'email@company.com',  //Required. We use emails to identify a user
      'user_id' => '1',  // Not required
      'name' => 'luca',  // Not required
      //Use attributes to save custom data of a certain user
      'attributes' => [
        'attribute2_name' => 'attribute2_value',
        'attribute_name' => 'attribute_value'
      ],
// Add a list of tag you want to add to your users
   'tags' => [ 'purchased', 'remarketing' ]
] ] ];
$body = json_encode($json_array);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
$response = curl_exec($ch);


if (!$response) { die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch)); }
echo 'HTTP Status Code: ' . curl_getinfo($ch, CURLINFO_HTTP_CODE) . PHP_EOL;
echo 'Response Body: ' . $response . PHP_EOL;
//If everything goes well, it will return inserted = # of users passed.
curl_close($ch);


Did this article help you solve your issue?

Customerly Beta - Help Center

© 2025 Customerly Beta - Help Center. All rights reserved.

Knowledge Base Software by Customerly