How to open a new conversation from a user to a teammate via API

Let's say you want to open a conversation to notify your customer support or sales team about a new form submission this is how you can accomplish it. 


First of all, you will need to create a bridge file to communicate with our APIs. 


In this file, depending on your environment you will need to access our public API endpoint https://api.customerly.io/v1/messages


For more info check out here the API docs.


For example, we will use PHP to show you how to create a function to open a new conversation from a lead to an account.


In the send_message function below you have three fields to pass:

  • $from_email the lead email
  • $message the actual message to deliver to the account
  • $account_id the account id you can find in teammates page in your project settings.


Remember to get a Customerly API Key from your Project settings as well.


static function send_message($from_email, $account_id, $message)
{
    $ch = curl_init();
    $payload = array(
        "from" => array(
            "type" => "lead",
            "email" => $from_email
        ),
        "to" => array(
            "type" => "admin",
            "id" => $account_id,
        ),
        "content" => $message,
    )
    curl_setopt($ch, CURLOPT_URL, "https://api.customerly.io/v1/messages");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);

    curl_setopt($ch, CURLOPT_POST, TRUE);

    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));

    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        "Authentication: AccessToken: " . CUSTOMERLY_API_KEY
    ));

    $response = curl_exec($ch);
    curl_close($ch);

    return $response;


}