{
  "openapi": "3.1.0",
  "info": {
    "title": "Segmentify Contacts API",
    "version": "2.0",
    "description": "Import contacts into Segmentify and export their consent (permission) data."
  },
  "servers": [
    {
      "url": "https://trapi.segmentify.com"
    }
  ],
  "tags": [
    {
      "name": "Authorization"
    },
    {
      "name": "Contacts"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/oauth2/token": {
      "post": {
        "tags": [
          "Authorization"
        ],
        "operationId": "getToken",
        "summary": "Authorization token",
        "security": [],
        "description": "Get a token with the account credentials you use to log in to the Segmentify panel.\n\nAccess token: valid for 2 hours.\n\nRefresh token: valid for 4 hours.\n\nWhen the 2-hour access token has expired, get a new token with the refresh token, without sending your credentials again.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "type": "object",
                    "required": [
                      "username",
                      "password"
                    ],
                    "properties": {
                      "username": {
                        "type": "string"
                      },
                      "password": {
                        "type": "string",
                        "format": "password"
                      }
                    }
                  },
                  {
                    "type": "object",
                    "required": [
                      "grantType",
                      "refreshToken"
                    ],
                    "properties": {
                      "grantType": {
                        "type": "string",
                        "enum": [
                          "REFRESH_TOKEN"
                        ]
                      },
                      "refreshToken": {
                        "type": "string"
                      }
                    }
                  }
                ]
              },
              "examples": {
                "credentials": {
                  "summary": "Authorization Token",
                  "value": {
                    "username": "accountUser",
                    "password": "accountPassword"
                  }
                },
                "refresh": {
                  "summary": "Authorization Refresh Token",
                  "value": {
                    "grantType": "REFRESH_TOKEN",
                    "refreshToken": "REFRESH_TOKEN"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Token pair.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TokenPair"
                },
                "example": {
                  "accessToken": "ACCESS_TOKEN",
                  "refreshToken": "REFRESH_TOKEN",
                  "accessExpiresInTime": 7200,
                  "refreshExpiresInTime": 14400
                }
              }
            }
          }
        }
      }
    },
    "/contacts/import": {
      "post": {
        "tags": [
          "Contacts"
        ],
        "operationId": "importContacts",
        "summary": "Import contacts",
        "description": "**successRecord**: the number of records that were saved.\n\n**errors**: the fields that were rejected, with the format each one is expected in.\n\n- **userId** is optional. When it is empty, the email address is used as the user ID.\n- **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`.\n\nRequests are rate limited. One request can carry 1000 records, and 100 successful requests are allowed per hour. Requests beyond the limit return an error.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "maxItems": 1000,
                "items": {
                  "$ref": "#/components/schemas/Contact"
                }
              },
              "examples": {
                "success": {
                  "summary": "Contacts-Import-Successfully",
                  "value": [
                    {
                      "fullName": "test sgm",
                      "email": "test-sgm@segmentify.com",
                      "isEmailOpt": true,
                      "iysEnabled": true,
                      "mobilePhone": "05551234567",
                      "gender": "E",
                      "location": "Ankara",
                      "customSegments": [
                        "Futbol",
                        "Basketbol"
                      ],
                      "paramsMap": {
                        "takim": "besiktas"
                      }
                    }
                  ]
                },
                "failed": {
                  "summary": "Contacts-Import-Failed",
                  "value": [
                    {
                      "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"
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Import result.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImportResult"
                },
                "example": {
                  "errors": [],
                  "successRecord": 1
                }
              }
            }
          },
          "400": {
            "description": "Validation errors.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImportResult"
                },
                "example": {
                  "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
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded.",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                },
                "examples": {
                  "contacts-api-too-many-request": {
                    "summary": "Contacts-Api-Too-Many-Request",
                    "value": "Your request has been blocked. You have too many requests, try again later."
                  },
                  "contacts-api-too-many-bad-request": {
                    "summary": "Contacts-Api-Too-Many-Bad-Request",
                    "value": "Your request has been blocked. You have too many bad requests, try again later."
                  }
                }
              }
            }
          }
        }
      }
    },
    "/contacts/v2/export": {
      "post": {
        "tags": [
          "Contacts"
        ],
        "operationId": "exportContacts",
        "summary": "Export contacts",
        "description": "- **unsubscribed**: when `true`, the result includes contacts whose consent is rejected.\n- **subscribed**: when `true`, the result includes contacts whose consent is approved.\n- **startDate** and **endDate**: return the consent data of that date range. Without them, the result covers the consent changes of the last day.\n- **includeUserDetails**: when `true`, each contact comes with its user details.\n- **includeIysField**: when `true`, the response is returned in İYS format.\n\nUse the `page` parameter to get the next page. Each page holds 1000 records.\n\nRequest pages according to `totalPages` and `currentPage` in the response.",
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "unsubscribed": {
                    "type": "boolean"
                  },
                  "subscribed": {
                    "type": "boolean"
                  },
                  "startDate": {
                    "type": "string",
                    "format": "date"
                  },
                  "endDate": {
                    "type": "string",
                    "format": "date"
                  },
                  "includeUserDetails": {
                    "type": "boolean"
                  },
                  "includeIysField": {
                    "type": "boolean"
                  }
                }
              },
              "examples": {
                "contacts-api-v2-export-api-successfully": {
                  "summary": "Contacts-Api-V2-Export-Api Successfully",
                  "value": {
                    "unsubscribed": true,
                    "subscribed": true
                  }
                },
                "contacts-api-v2-export-api-include-user": {
                  "summary": "Contacts-Api-V2-Export-Api Include-User",
                  "value": {
                    "unsubscribed": true,
                    "subscribed": true,
                    "includeUserDetails": true
                  }
                },
                "contacts-api-v2-export-api-include-iys": {
                  "summary": "Contacts-Api-v2-Export-Api-Include-Iys",
                  "value": {
                    "unsubscribed": true,
                    "subscribed": true,
                    "includeIysField": true,
                    "includeUserDetails": true
                  }
                },
                "contacts-v2-export-pagination": {
                  "summary": "Contacts-v2-Export-Pagination",
                  "value": {
                    "unsubscribed": true,
                    "subscribed": true,
                    "startDate": "2023-06-01",
                    "endDate": "2024-03-27"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "One page of contacts.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ExportResult"
                },
                "examples": {
                  "contacts-api-v2-export-api-successfully": {
                    "summary": "Contacts-Api-V2-Export-Api Successfully",
                    "value": {
                      "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": {
                    "summary": "Contacts-Api-V2-Export-Api Include-User",
                    "value": {
                      "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": {
                    "summary": "Contacts-Api-v2-Export-Api-Include-Iys",
                    "value": {
                      "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": {
                    "summary": "Contacts-v2-Export-Pagination",
                    "value": {
                      "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"
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "The error returned when the requested page does not exist.",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                },
                "example": "Please check the page parameter, currentPage not be greater than totalPage it seems to be invalid"
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded.",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                },
                "examples": {
                  "contacts-api-too-many-bad-request": {
                    "summary": "Contacts-Api-Too-Many-Bad-Request",
                    "value": "Your request has been blocked. You have too many bad requests, try again later."
                  }
                }
              }
            }
          }
        }
      }
    },
    "/contacts/v2/get/user-data": {
      "post": {
        "tags": [
          "Contacts"
        ],
        "operationId": "getUserData",
        "summary": "Get user data",
        "description": "Look up a user by user ID or email address.",
        "parameters": [
          {
            "name": "userId",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "test-sgm@segmentify.com"
          }
        ],
        "responses": {
          "200": {
            "description": "The contact.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                },
                "example": {
                  "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"
                    ]
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Access token returned by `POST /oauth2/token`."
      }
    },
    "schemas": {
      "TokenPair": {
        "type": "object",
        "properties": {
          "accessToken": {
            "type": "string"
          },
          "refreshToken": {
            "type": "string"
          },
          "accessExpiresInTime": {
            "type": "integer",
            "description": "Access token lifetime in seconds."
          },
          "refreshExpiresInTime": {
            "type": "integer",
            "description": "Refresh token lifetime in seconds."
          }
        }
      },
      "Contact": {
        "type": "object",
        "required": [
          "email"
        ],
        "properties": {
          "userId": {
            "type": "string",
            "description": "Optional. When empty, the email address is used as the user ID."
          },
          "fullName": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "isEmailOpt": {
            "type": "boolean"
          },
          "iysEnabled": {
            "type": "boolean",
            "description": "`true` sends the user data to the İYS integration."
          },
          "mobilePhone": {
            "type": "string"
          },
          "gender": {
            "type": "string",
            "examples": [
              "E"
            ]
          },
          "birthDate": {
            "type": "string",
            "description": "`DD.MM.YYYY`"
          },
          "memberShipDate": {
            "type": "string",
            "description": "`DD.MM.YYYY`"
          },
          "location": {
            "type": "string"
          },
          "customSegments": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "paramsMap": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "ImportResult": {
        "type": "object",
        "properties": {
          "successRecord": {
            "type": "integer"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "index": {
                  "type": "integer"
                },
                "value": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "ExportResult": {
        "type": "object",
        "properties": {
          "totalCount": {
            "type": "integer"
          },
          "totalPages": {
            "type": "integer"
          },
          "currentPage": {
            "type": "integer"
          },
          "list": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          }
        }
      }
    }
  }
}