# Contacts

You can add contacts directly to your account using the API.

They will appear in your group as if they were added manually using the dashboard at https://admin.sofy.fr. You will then be able to use these contacts in campains or automatic campaigns.



# Supported fields

Header name Description
contactEmailAddress Email address of the contact
contactPhoneNumber Phone number in E164 standard format (International format without leading 0 nor +)
contactFirstName First name of the contact
contactLastName Last name of the contact
contactSubscribed Wether the contact is opt-in or not
contactBirthday Birthday of the contact in ISO8601 format
any custom column index A value according to the correct type for this custom column

# Create a contact

# 1. Find the group Id

In order to add a contact, you need to find the correct group id in order to build the request url: POST /groups/{groupId}/contacts

To do so, you can call the operation GET /groups in order to retrieve a list of all your known groups. (You can also create a group using the api, see the Api explorer for more details)

[
	{
		"id": 1,
		"name": "Group 1",
		"createdAt": "1970-01-01T00:00:00.000Z",
		"updatedAt": "1970-01-01T00:00:00.000Z",
		"source": "user"
 	},
	{
		"id": 2,
		"name": "Group 2",
		"createdAt": "1970-01-01T00:00:00.000Z",
		"updatedAt": "1970-01-01T00:00:00.000Z",
		"source": "user"
 	},
	{
		"id": 3,
		"name": "Group N",
		"createdAt": "1970-01-01T00:00:00.000Z",
		"updatedAt": "1970-01-01T00:00:00.000Z",
		"source": "user"
 	},
  ...
]
# 2. Add the contact to the group

Once you have the group id, you are now able to build your request url. For example if you wanted to add a contact to group 1 the url would then be:

POST /groups/1/contacts

Of course with the associated payload:

{
  "contactEmailAddress": "[email protected]",
  "contactPhoneNumber": "123456",
  "contactFirstName": "John",
  "contactLastName": "Doe",
  "contactSubscribed": true,
  "contactBirthday": "1970-01-01T00:00:00.000Z"
}

# Custom columns

It's possible to retrieve a list of the custom columns available on your account using the request GET /customColumns. This returns a read-only list in the following format.

[
  {
    "id": 1,
    "venueId": 0,
    "userLabel": "Name given to the column",
    "type": "DOUBLE",
    "created_at": "1970-01-01T00:00:00.000Z",
    "updated_at": "1970-01-01T00:00:00.000Z",
    "deleted_at": null
  },
  ...
]

Please pay special attention to the columns "id" and "type".

The supported "type" values are:

  • DATETIME: A date time in ISO8601 format
  • CHAR: A string of characterd
  • DOUBLE: A number with or without decimals. Please note that these number will be treated as monetary euro values when processed in a campaign. (42.12343 will be rounded to 42.12)

# Example with custom column

Let's say you want to create a contact while specifying the custom column id 1 as described before. This would be the correct request:

{
  "contactEmailAddress": "[email protected]",
  "contactPhoneNumber": "123456",
  "contactFirstName": "John",
  "contactLastName": "Doe",
  "contactSubscribed": true,
  "contactBirthday": "1970-01-01T00:00:00.000Z",
  "1": 42
}

# Dive deeper

This guide is a short overview of contact management using the API. There are more operations not discussed here as they're pretty self-explainatory. Please see the Api Explorer for more details.


# Code examples

curl -X 'POST' \
  "https://api.sofy.fr/v1/groups/1/contacts" \
  -H "accept: application/json" \
  -H "X-API-KEY-ID: $SOFY_API_KEY_ID" \
  -H "X-API-KEY-SECRET: $SOFY_API_KEY_SECRET " \
  -H "Content-Type: application/json" \
	-d '{
    "contactEmailAddress": "[email protected]"
  }'
# Where SOFY_API_KEY_ID and SOFY_API_KEY_SECRET are environment variables containing your credentials
import axios from 'axios';
require('dotenv').config();

const myNumber = '590690112233';

axios.post(
  'https://api.sofy.fr/v1/groups/1/contacts',
  {
    contactEmailAddress: '[email protected]',
  },
  {
    headers: {
      'X-API-KEY-ID': process.env.SOFY_API_KEY_ID,
      'X-API-KEY-SECRET': process.env.SOFY_API_KEY_SECRET,
    },
  },
);
<?php

$ID = getenv('SOFY_API_KEY_ID');
$SECRET = getenv('SOFY_API_KEY_SECRET');


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sofy.fr/v1/groups/1/contacts");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "X-API-KEY-ID: " . $ID,
    "X-API-KEY-SECRET: " . $SECRET,
	"Content-Type: application/json"
));

$payload = json_encode(array("contactEmailAddress" => '[email protected]'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

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