# Read API

Toute la plateforme Captain Metrics est construite sur une API. N'hésitez pas à nous contacter si certains endpoints ne sont pas documentés.

## Authentification & format

Toutes les requêtes API doivent être authentifiées avec un token de "Service Account" via une entête HTTP `Authorization` . Les données sont échangées au format JSON.

```
Authorization: Bearer SERVICE_ACCOUNT_TOKEN
```

## users.list

Liste de tous les utilisateurs (anonymes & authentifiés).

```
GET https://api.captainmetrics.com/v2/users.list
```

<table><thead><tr><th>Paramètre</th><th width="221.33333333333331">Type &#x26; requis</th><th>Description</th></tr></thead><tbody><tr><td>skip</td><td>integer - requis</td><td>Pagination</td></tr><tr><td>limit</td><td>integer - requis</td><td>Limite du nombre de résultats</td></tr><tr><td>segment</td><td>string</td><td>Filtrer par segment ID. <code>anonymous</code> , <code>authenticated</code> ou <code>segmentId</code>.</td></tr><tr><td>searchKey</td><td>string</td><td>Champ de recherche. <code>externalId</code> , <code>firstName</code>, <code>lastName</code>, <code>email</code>, <code>telephone</code>, <code>twitterUsername</code>, <code>facebookUsername</code> , <code>amazonBuyerEmail</code>, <code>websiteURL</code>, <code>linkedInURL</code></td></tr><tr><td>searchValue</td><td>string</td><td>Valeur du champ recherché.</td></tr></tbody></table>

Exemple de réponse

```json
{
  "code": 200,
  "users": [
    {
      "id": "45ca1d224fb0223c3ac72019ec9afe243d11e029",
      "externalId": "1573",
      "isMerged": false,
      "lastIP": "209.199.20.101",
      "isAuthenticated": true,
      "createdAt": "2021-10-30T14:14:49Z",
      "updatedAt": "2021-10-30T14:14:49Z",
      "firstSeenAt": "2021-10-30T22:05:37Z",
      "lastSeenAt": "2021-10-30T22:05:37Z",
      "latitude": 43.85162,
      "longitude": -79.487554,
      "timezone": "America/Toronto",
      "language": "en",
      "country": "CA",
      "dbCreatedAt": "2021-10-30T14:14:49Z",
      "dbUpdatedAt": "2021-10-30T14:14:50Z",
      "signedUpAt": "2021-10-30T22:05:13Z",
      "firstName": "Arnaud",
      "lastName": "Harcourt",
      "gender": "male",
      "birthday": "1991-07-08T00:00:00Z",
      "photoURL": "https://randomuser.me/api/portraits/men/30.jpg",
      "email": "arnaud-harcourt@yopmail.com",
      "emailMd5": "9eba7237c3e3238617fc467f87cd5c31",
      "emailSha1": "bf93bd30e556926c01167d365cdf2b3bee2f5594",
      "emailSha256": "6941615997ddc90045ce8e7bf40f2df96aa3a967e72a32d1bf15adb8c188c3a3",
      "tags": [
        "vip"
      ],
      "telephone": "+10941202802",
      "newsletterConsent": true,
      "remarketingConsent": true,
      "addressLine1": "2528 argyle st",
      "city": "Cartwright",
      "postalCode": "62790",
      "state": "British Columbia",
      "properties": null,
      "cart": {
        "currency": "",
        "items": [],
        "updatedAt": "2021-10-30T22:05:37Z"
      },
      "cartItemsCount": 0,
      "cartUpdatedAt": "2021-10-30T22:05:37Z",
      "cartAbandoned": false,
      "wishList": {
        "currency": "",
        "items": null,
        "updatedAt": "0001-01-01T00:00:00Z"
      },
      "wishListItemsCount": 0,
      "wishListUpdatedAt": null,
      "clients": [
        {
          "id": "6ebff2c69e9bdbbd679ab5b43a72e6d77604646c",
          "externalId": "59024fa1-31d5-4646-9ecf-ee8149bd1027",
          "userId": "45ca1d224fb0223c3ac72019ec9afe243d11e029",
          "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36",
          "browserVersionMajor": 68,
          "browserVersionPatch": 3440,
          "vendor": "Google Inc.",
          "resolution": "1440x900",
          "resolutionAvailable": "1402x877",
          "timezone": "Asia/Manila",
          "timezoneOffset": -480,
          "doNotTrack": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36",
          "language": "fr-FR",
          "languages": "fr-FR~fr~en-US~en",
          "touchSupport": "0-false-false",
          "adBlock": false,
          "createdAt": "2021-10-30T14:14:49Z",
          "dbCreatedAt": "2021-10-30T14:14:49Z",
          "dbUpdatedAt": "2021-10-30T14:14:49Z",
          "browser": "Chrome",
          "os": "Mac OSX",
          "platform": "Mac",
          "device": "computer"
        }
      ],
      "segments": [
        {
          "userId": "45ca1d224fb0223c3ac72019ec9afe243d11e029",
          "segmentId": "auth",
          "enterAt": "2021-10-30T14:14:49Z"
        },
        {
          "userId": "45ca1d224fb0223c3ac72019ec9afe243d11e029",
          "segmentId": "vip-users",
          "enterAt": "2021-11-26T14:13:56Z"
        }
      ],
      "notificationTopics": []
    },
    ....
  ],
  "usersCount": 1000
}
```

## leads.list

Liste des leads, retournés avec leur dernier état connu (`stageId`).

```
GET https://api.captainmetrics.com/v2/leads.list
```

| Paramètre        | Type - requis   | Description                                           |
| ---------------- | --------------- | ----------------------------------------------------- |
| sortKey          | string - requis | Champ de tri. `createdAt` ou `externalId` .           |
| sortOrder        | string - requis | Ordre de tri. `descend` ou `ascend`.                  |
| conversionRuleId | string          | Filtrer par ID de la règle de conversion.             |
| domainId         | string          | Filtrer par ID du domaine.                            |
| externalId       | string          | Filtrer par ID externe du lead.                       |
| stageId          | string          | Filtrer par ID de l'état.                             |
| userId           | string          | Filtrer par ID (de Captain Metrics) de l'utilisateur. |
| skip             | integer         | Pagination.                                           |
| limit            | integer         | Limite le nombre de résultat. 30 par défaut.          |

Exemple de réponse

```json
{
  "code": 200,
  "leads": [
    {
      "id": "8d6f8fe9c4cdd43da7c95fd58991f5e9749e77ba",
      "kind": "lead",
      "createdAt": "2022-01-15T13:47:28Z",
      "timezoneOffset": 0,
      "userId": "98ca013ab910cc8e9f8aa59da53ec2a217fa0e00",
      "level": 1,
      "parentId": "bbce4a566d723545f8a521f4bc6d38560969cad5",
      "dbCreatedAt": "2022-01-23T16:15:59Z",
      "dbUpdatedAt": "2022-01-23T16:15:59Z",
      "domainId": "localhost",
      "country": "FR",
      "props": {
        "mynumber": 999,
        "mystring": "abc_v2"
      },
      "conversionRuleId": "leads",
      "conversionExternalId": "lead_external_id",
      "isFirstConversion": true,
      "publicUrl": "https://lead.fr/leadId=xxx",
      "timeToConversion": 0,
      "revenue": 358,
      "revenueSource": 300,
      "currency": "GBP",
      "stageId": "lost",
      "status": "lost",
      "tags": [
        "a",
        "b",
        "c"
      ],
      "user": {
        "id": "98ca013ab910cc8e9f8aa59da53ec2a217fa0e00",
        "externalId": "user_lead",
        "isMerged": false,
        "isAuthenticated": true,
        "createdAt": "2022-01-15T13:47:28Z",
        "updatedAt": "2022-01-15T13:47:28Z",
        "firstSeenAt": "2022-01-15T13:47:28Z",
        "lastSeenAt": "2022-01-15T13:47:28Z",
        "timezone": "Europe/Paris",
        "language": "en",
        "country": "FR",
        "dbCreatedAt": "2022-01-23T16:15:55Z",
        "dbUpdatedAt": "2022-01-23T16:15:55Z",
        "signedUpAt": "2022-01-15T13:47:28Z",
        "firstName": "John Lead",
        "lastName": "Doe Lead",
        "gender": "male",
        "birthday": "1980-12-31T00:00:00Z",
        "photoURL": "https://website.com/photo.jpg",
        "email": "lead@gmail.com",
        "emailMd5": "b02d3b5218c0c2cc617c53c1f8ca518a",
        "emailSha1": "1ecbab741511e7faaf5829367e8caaa1435c2e84",
        "emailSha256": "4566fe559a1f93466829269aae7d1bbcead5eaf08180d0aa356b8dbcb5d48d77",
        "tags": [],
        "newsletterConsent": false,
        "remarketingConsent": false,
        "properties": null,
        "cart": {
          "currency": "",
          "items": null,
          "updatedAt": "0001-01-01T00:00:00Z"
        },
        "cartItemsCount": 0,
        "cartUpdatedAt": null,
        "cartAbandoned": false,
        "wishList": {
          "currency": "",
          "items": null,
          "updatedAt": "0001-01-01T00:00:00Z"
        },
        "wishListItemsCount": 0,
        "wishListUpdatedAt": null,
        "clients": [
          {
            "id": "ec01363cb13ef2ba0b3f4bb02e2256b775554509",
            "externalId": "client_lead_ext_id",
            "userId": "98ca013ab910cc8e9f8aa59da53ec2a217fa0e00",
            "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:89.0) Gecko/20100101 Firefox/89.0",
            "browserVersionMajor": 89,
            "resolution": "1920x1080",
            "resolutionAvailable": "1840x970",
            "timezone": "Europe/Paris",
            "timezoneOffset": -120,
            "doNotTrack": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:89.0) Gecko/20100101 Firefox/89.0",
            "language": "fr",
            "languages": "fr~en",
            "adBlock": true,
            "createdAt": "2022-01-15T13:47:28Z",
            "dbCreatedAt": "2022-01-23T16:15:56Z",
            "dbUpdatedAt": "2022-01-23T16:15:56Z",
            "browser": "Firefox",
            "os": "Mac OSX",
            "platform": "Mac",
            "device": "computer"
          }
        ],
        "segments": [
          {
            "userId": "98ca013ab910cc8e9f8aa59da53ec2a217fa0e00",
            "segmentId": "auth",
            "enterAt": "2022-01-23T16:16:00Z"
          }
        ],
        "notificationTopics": []
      }
    },
    ...
  ],
  "leadsCount": 1000
}
```
