# Contacts API overview

> Token, contact import, consent export and rate limits of the Segmentify Contacts API.

Base URL: `https://trapi.segmentify.com`. Every contacts request needs the access token as a Bearer token: `Authorization: Bearer <accessToken>`.

## Authorization Token

`POST /oauth2/token`

Get a token with the account credentials you use to log in to the Segmentify panel.

Access token: valid for 2 hours.

Refresh token: valid for 4 hours.

**Request**

```json
{
  "username": "accountUser",
  "password": "accountPassword"
}
```

**Response** (200)

```json
{
  "accessToken": "ACCESS_TOKEN",
  "refreshToken": "REFRESH_TOKEN",
  "accessExpiresInTime": 7200,
  "refreshExpiresInTime": 14400
}
```

## Authorization Refresh Token

`POST /oauth2/token`

When the 2-hour access token has expired, get a new token with the refresh token, without sending your credentials again.

**Request**

```json
{
  "grantType": "REFRESH_TOKEN",
  "refreshToken": "REFRESH_TOKEN"
}
```

**Response** (200)

```json
{
  "accessToken": "ACCESS_TOKEN",
  "refreshToken": "REFRESH_TOKEN",
  "accessExpiresInTime": 7200,
  "refreshExpiresInTime": 14400
}
```

## Contacts-Import-Failed

`POST /contacts/import`

**successRecord**: the number of records that were saved.

**errors**: the fields that were rejected, with the format each one is expected in.

- **userId** is optional. When it is empty, the email address is used as the user ID.
- **iysEnabled**: when `true`, the user data is sent to the İYS integration. To keep it from being sent, leave the field out or send `"iysEnabled": false`.

**Request**

```json
[
  {
    "userId": "test.test@segmentify.com",
    "fullName": "Test",
    "email": "test.testç@segmentify.com",
    "isEmailOpt": true,
    "iysEnabled": true,
    "mobilePhone": "05551234567",
    "gender": "E",
    "location": "Ankara",
    "customSegments": [
      "Futbol",
      "Basketbol"
    ],
    "paramsMap": {
      "takim": "besiktas"
    }
  },
  {
    "fullName": "Test test2",
    "email": "test.test2@segmentify.com",
    "isEmailOpt": true,
    "iysEnabled": true,
    "mobilePhone": "05551234567",
    "gender": "E",
    "birthDate": "1985.10.03",
    "memberShipDate": "2023.01.01",
    "location": "Ankara",
    "customSegments": [
      "Futbol",
      "Basketbol"
    ],
    "paramsMap": {
      "takim": "fenerbahce"
    }
  }
]
```

**Response** (400)

```json
{
  "errors": [
    {
      "index": 0,
      "value": "test.testç@segmentify.com",
      "message": "Please check the email address format, it seems to be invalid"
    },
    {
      "index": 1,
      "value": "1985.10.03",
      "message": "The birthDate should be sent in DD.MM.YYYY format. Please check it"
    },
    {
      "index": 1,
      "value": "2023.01.01",
      "message": "The memberShipDate should be sent in DD.MM.YYYY format. Please check it"
    }
  ],
  "successRecord": 0
}
```

## Contacts-Import-Successfully

`POST /contacts/import`

**successRecord**: the number of records that were saved.

**errors**: the fields that were rejected, with the format each one is expected in.

- **userId** is optional. When it is empty, the email address is used as the user ID.
- **iysEnabled**: when `true`, the user data is sent to the İYS integration. To keep it from being sent, leave the field out or send `"iysEnabled": false`.

**Request**

```json
[
  {
    "fullName": "test sgm",
    "email": "test-sgm@segmentify.com",
    "isEmailOpt": true,
    "iysEnabled": true,
    "mobilePhone": "05551234567",
    "gender": "E",
    "location": "Ankara",
    "customSegments": [
      "Futbol",
      "Basketbol"
    ],
    "paramsMap": {
      "takim": "besiktas"
    }
  }
]
```

**Response** (200)

```json
{
  "errors": [],
  "successRecord": 1
}
```

## Contacts-Api-V2-Export-Api Successfully

`POST /contacts/v2/export`

- **unsubscribed**: when `true`, the result includes contacts whose consent is rejected.
- **subscribed**: when `true`, the result includes contacts whose consent is approved.
- **startDate** and **endDate**: return the consent data of that date range. Without them, the result covers the consent changes of the last day.
- **includeUserDetails**: when `true`, each contact comes with its user details.

**Request**

```json
{
  "unsubscribed": true,
  "subscribed": true
}
```

**Response** (200)

```json
{
  "totalCount": 3,
  "totalPages": 1,
  "currentPage": 1,
  "list": [
    {
      "email": "test.test08@segmentify.com",
      "isEmailOpt": "false",
      "allowDate": "2024-03-27 11:25:21.448"
    },
    {
      "userId": "test-sgm@segmentify.com",
      "email": "test-sgm@segmentify.com",
      "isEmailOpt": "true",
      "allowDate": "2024-03-27 11:10:00.0"
    },
    {
      "userId": "test.test@segmentify.com",
      "email": "test.test@segmentify.com",
      "isEmailOpt": "true",
      "allowDate": "2024-03-27 11:50:00.0"
    }
  ]
}
```

## Contacts-Api-V2-Export-Api Include-User

`POST /contacts/v2/export`

- **unsubscribed**: when `true`, the result includes contacts whose consent is rejected.
- **subscribed**: when `true`, the result includes contacts whose consent is approved.
- **startDate** and **endDate**: return the consent data of that date range. Without them, the result covers the consent changes of the last day.
- **includeUserDetails**: when `true`, each contact comes with its user details.

**Request**

```json
{
  "unsubscribed": true,
  "subscribed": true,
  "includeUserDetails": true
}
```

**Response** (200)

```json
{
  "totalCount": 2,
  "totalPages": 1,
  "currentPage": 1,
  "list": [
    {
      "userId": "test-sgm@segmentify.com",
      "email": "test-sgm@segmentify.com",
      "isEmailOpt": "true",
      "allowDate": "2024-03-27 11:10:00.0",
      "userDetail": {
        "email": "test-sgm@segmentify.com",
        "fullName": "test sgm",
        "mobilePhone": "05551234567",
        "gender": "E",
        "location": "Ankara",
        "customSegments": [
          "Futbol",
          "Basketbol"
        ]
      }
    },
    {
      "userId": "test.test@segmentify.com",
      "email": "test.test@segmentify.com",
      "isEmailOpt": "true",
      "allowDate": "2024-03-27 11:50:00.0",
      "userDetail": {
        "email": "test.test@segmentify.com",
        "fullName": "Test",
        "mobilePhone": "05551234567",
        "gender": "E",
        "location": "Istanbul",
        "customSegments": [
          "Futbol",
          "Basketbol"
        ]
      }
    }
  ]
}
```

## Contacts-Api-v2-Export-Api-Include-Iys

`POST /contacts/v2/export`

- **unsubscribed**: when `true`, the result includes contacts whose consent is rejected.
- **subscribed**: when `true`, the result includes contacts whose consent is approved.
- **startDate** and **endDate**: return the consent data of that date range. Without them, the result covers the consent changes of the last day.
- **includeUserDetails**: when `true`, each contact comes with its user details.
- **includeIysField**: when `true`, the response is returned in İYS format.

**Request**

```json
{
  "unsubscribed": true,
  "subscribed": true,
  "includeIysField": true,
  "includeUserDetails": true
}
```

**Response** (200)

```json
{
  "totalCount": 2,
  "totalPages": 1,
  "currentPage": 1,
  "list": [
    {
      "userId": "test-sgm@segmentify.com",
      "email": "test-sgm@segmentify.com",
      "iysType": "EPOSTA",
      "iysSource": "HS_WEB",
      "iysStatus": "ONAY",
      "iysConsentDate": "2024-03-27 11:10:00.0",
      "iysReceiptType": "BIREYSEL",
      "userDetail": {
        "email": "test-sgm@segmentify.com",
        "fullName": "test sgm",
        "mobilePhone": "05551234567",
        "gender": "E",
        "location": "Ankara",
        "customSegments": [
          "Futbol",
          "Basketbol"
        ]
      }
    },
    {
      "userId": "test.test@segmentify.com",
      "email": "test.test@segmentify.com",
      "iysType": "EPOSTA",
      "iysSource": "HS_WEB",
      "iysStatus": "ONAY",
      "iysConsentDate": "2024-03-27 11:50:00.0",
      "iysReceiptType": "BIREYSEL",
      "userDetail": {
        "email": "test.test@segmentify.com",
        "fullName": "Test",
        "mobilePhone": "05551234567",
        "gender": "E",
        "location": "Istanbul",
        "customSegments": [
          "Futbol",
          "Basketbol"
        ]
      }
    }
  ]
}
```

## Contacts-v2-Export-Pagination

`POST /contacts/v2/export?page=2`

Use the `page` parameter to get the next page. Each page holds 1000 records.

Request pages according to `totalPages` and `currentPage` in the response.

**Request**

```json
{
  "unsubscribed": true,
  "subscribed": true,
  "startDate": "2023-06-01",
  "endDate": "2024-03-27"
}
```

**Response** (200)

```json
{
  "totalCount": 1003,
  "totalPages": 2,
  "currentPage": 2,
  "list": [
    {
      "email": "test.sgm2@segmentify.com",
      "isEmailOpt": "false",
      "allowDate": "2024-02-22 12:47:13.484"
    },
    {
      "userId": "test-sgm5@segmentify.com",
      "email": "test-sgm5@segmentify.com",
      "isEmailOpt": "true",
      "allowDate": "2024-02-29 16:05:00.0"
    },
    {
      "userId": "test-sgm2@segmentify.com",
      "email": "test-sgm2@segmentify.com",
      "isEmailOpt": "true",
      "allowDate": "2024-02-21 13:41:16.0"
    }
  ]
}
```

## Contacts-v2-Export-Pagination-Error

`POST /contacts/v2/export?page=5`

The error returned when the requested page does not exist.

Request pages according to `totalPages` and `currentPage` in the response.

**Request**

```json
{
  "unsubscribed": true,
  "subscribed": true
}
```

**Response** (400)

```text
Please check the page parameter, currentPage not be greater than totalPage it seems to be invalid
```

## Contacts-Api-Too-Many-Request

`POST /contacts/import`

Requests are rate limited. One request can carry 1000 records, and 100 successful requests are allowed per hour. Requests beyond the limit return an error.

**Request**

```json
[
  {
    "fullName": "Test",
    "email": "test.test@segmentify.com",
    "isEmailOpt": true,
    "mobilePhone": "05551234567",
    "gender": "E",
    "location": "Istanbul",
    "customSegments": [
      "Futbol",
      "Basketbol"
    ],
    "paramsMap": {
      "takim": "trabzon"
    }
  }
]
```

**Response** (429)

```text
Your request has been blocked. You have too many requests, try again later.
```

## Contacts-Api-Too-Many-Bad-Request

`POST /contacts/export?page=10`

More than 100 failed requests in one hour block you for one hour. You can send requests again when the block is lifted.

**Request**

```json
{
  "unsubscribed": true,
  "subscribed": true
}
```

**Response** (429)

```text
Your request has been blocked. You have too many bad requests, try again later.
```

## Contacts-Api-v2-Get-User-Data

`POST /contacts/v2/get/user-data?userId=test-sgm@segmentify.com`

Look up a user by user ID or email address.

**Response** (200)

```json
{
  "userId": "test-sgm@segmentify.com",
  "email": "test-sgm@segmentify.com",
  "isEmailOpt": "true",
  "allowDate": "2024-03-27 11:10:00.0",
  "userDetail": {
    "email": "test-sgm@segmentify.com",
    "fullName": "test sgm",
    "mobilePhone": "05551234567",
    "gender": "E",
    "location": "Ankara",
    "customSegments": [
      "Futbol",
      "Basketbol"
    ]
  }
}
```

## API reference

Send these requests from the [Contacts API reference](/reference/contacts-api/).
