---
openapi: 3.0.3
info:
  title: Braze REST API – Query list of unsubscribed email addresses
  description: |
    ## Prerequisites

    To use this endpoint, you'll need an [API key]({{site.baseurl}}/api/basics#rest-api-key-permissions) with the `email.unsubscribe` permission.

    ## Rate limit

    We apply the default Braze rate limit of 250,000 requests per hour to this endpoint, as documented in [API rate limits]({{site.baseurl}}/api/api_limits/).
  version: 1.0.0
  contact:
    name: Braze Support
    url: https://www.braze.com/docs/braze_support/
  license:
    name: Braze Documentation
    url: https://www.braze.com/docs/api/home/
servers:
  - url: https://rest.iad-01.braze.com
    description: US-01
  - url: https://rest.iad-02.braze.com
    description: US-02
  - url: https://rest.iad-03.braze.com
    description: US-03
  - url: https://rest.iad-04.braze.com
    description: US-04
  - url: https://rest.iad-05.braze.com
    description: US-05
  - url: https://rest.iad-06.braze.com
    description: US-06
  - url: https://rest.iad-07.braze.com
    description: US-07
  - url: https://rest.iad-08.braze.com
    description: US-08
  - url: https://rest.us-10.braze.com
    description: US-10
  - url: https://rest.fra-01.braze.eu
    description: EU-01
  - url: https://rest.fra-02.braze.eu
    description: EU-02
  - url: https://rest.au-01.braze.com
    description: AU-01
  - url: https://rest.id-01.braze.com
    description: ID-01
  - url: https://rest.jp-01.braze.com
    description: JP-01
  - url: https://rest.kr-01.braze.com
    description: KR-01
security:
- BearerAuth: []
paths:
  "/email/unsubscribes":
    get:
      summary: Query list of unsubscribed email addresses
      operationId: get_email_unsubscribes_get_query_unsubscribed_email_addresses
      description: |
        ## Query by email or date range

        **Note:** You must provide an `email`, or a date pair `start_date` and `end_date`.

        If your date range has more than `limit` number of unsubscribes, you will need to make multiple API calls, each time increasing the `offset` until a call returns either fewer than `limit` or zero results.
      parameters:
        - name: start_date
          in: query
          required: false
          description: Required with `end_date` unless you provide `email`. This is the start date of the range to retrieve unsubscribes and must be earlier than `end_date`. This is treated as midnight in UTC time by the API.
          schema:
            type: string
            format: date
          example: "2020-01-01"
        - name: end_date
          in: query
          required: false
          description: Required with `start_date` unless you provide `email`. This is the end date of the range to retrieve unsubscribes. This is treated as midnight in UTC time by the API.
          schema:
            type: string
            format: date
          example: "2020-02-01"
        - name: limit
          in: query
          required: false
          description: Optional field to limit the number of results returned. Defaults to 100, maximum is 500.
          schema:
            type: integer
            minimum: 1
            maximum: 500
            default: 100
          example: 1
        - name: offset
          in: query
          required: false
          description: Optional beginning point in the list to retrieve from.
          schema:
            type: integer
            minimum: 0
          example: 1
        - name: sort_direction
          in: query
          required: false
          description: Pass in the value `asc` to sort unsubscribes from oldest to newest. Pass in `desc` to sort from newest to oldest. If `sort_direction` is not included, the default order is newest to oldest.
          schema:
            type: string
            enum: [asc, desc]
            default: desc
          example: desc
        - name: email
          in: query
          required: false
          description: Required unless you provide both `start_date` and `end_date`. If provided, we will return whether or not the user has unsubscribed.
          schema:
            type: string
          example: example@example.com
      responses:
        "200":
          description: |
            The request succeeded and the response body lists the unsubscribed email addresses. No action needed.

            Entries are listed in descending order.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/QueryUnsubscribedEmailAddressesResponse'
              examples:
                success:
                  summary: Unsubscribed emails
                  value:
                    emails:
                      - email: example1@example.com
                        unsubscribed_at: "2020-01-28T17:45:00Z"
                      - email: example2@example.com
                        unsubscribed_at: "2020-01-20T08:30:00Z"
                      - email: example3@example.com
                        unsubscribed_at: "2020-01-15T12:00:00Z"
                    message: success
        "400":
          description: |
            Bad request. To resolve it:

            - **Neither an `email` nor a `start_date` and `end_date` pair was provided:** Include an `email`, or both `start_date` and `end_date`.
            - **The `start_date` is after the `end_date`:** Set `start_date` on or before `end_date`.
            - **A date isn't in `YYYY-MM-DD` format:** Format `start_date` and `end_date` as `YYYY-MM-DD`.
            - **More than 50 email addresses were provided:** Send 50 or fewer email addresses per request.
            - **The `limit` is less than 1:** Pass a `limit` of 1 or greater.
            - **The `limit` is greater than 500:** Pass a `limit` of 500 or fewer.
            - **The `offset` is less than 0:** Pass an `offset` of 0 or greater.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                email_or_dates_missing:
                  summary: No email or date range
                  value:
                    message: You must provide either an email or a start_date and end_date
                start_after_end:
                  summary: Start date after end date
                  value:
                    message: The start date must be before the end date
                bad_date_format:
                  summary: Date not in YYYY-MM-DD format
                  value:
                    message: Start date and end date must be in the format YYYY-MM-DD
                too_many_emails:
                  summary: More than 50 email addresses
                  value:
                    message: You can only pass in 1 to 50 emails at a time.
                limit_too_low:
                  summary: Limit less than 1
                  value:
                    message: Limit must be >= 1
                limit_too_high:
                  summary: Limit greater than 500
                  value:
                    message: You cannot set a limit to over 500
                offset_too_low:
                  summary: Offset less than 0
                  value:
                    message: Offset must be >= 0
        "401":
          description: |
            Unauthorized. The REST API key is missing, malformed, or sent to the wrong REST endpoint. Send the key as `Authorization: Bearer YOUR_REST_API_KEY` to the correct [REST endpoint]({{site.baseurl}}/api/basics/#endpoints). For more causes, see [Errors and responses]({{site.baseurl}}/api/errors/#fatal-errors).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalid_api_key:
                  summary: Invalid API key
                  value:
                    message: 'Invalid API key: YOUR_REST_API_KEY'
        "403":
          description: Access denied. The REST API key doesn't have the required permission. Use a REST API key that has the `email.unsubscribe` permission.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                access_denied:
                  summary: Missing permission
                  value:
                    message: Access Denied
        "429":
          description: |
            Rate limited. You exceeded the rate limit for this endpoint. Slow your request rate and retry with exponential backoff. See [API rate limits]({{site.baseurl}}/api/api_limits/).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                over_rate_limit:
                  summary: Over rate limit
                  value:
                    message: You have exceeded your limit of 250000 requests per hour. Please contact your account executive to increase your limit. If you do not have their info, you may contact Braze directly at https://www.braze.com/contact/.
        5XX:
          description: |
            Internal server error. An unexpected error occurred on the Braze server. Retry with exponential backoff. If the error persists, contact [Support]({{site.baseurl}}/braze_support/).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: REST API key
      description: |
        REST API keys are created in the Braze dashboard at **Settings → APIs and
        Identifiers → API Keys**. The key must include the `email.unsubscribe` permission.
        Pass the key as `Authorization: Bearer YOUR_REST_API_KEY`.
  schemas:
    UnsubscribedEmail:
      title: Unsubscribed email
      type: object
      properties:
        email:
          type: string
          description: An email that has been unsubscribed.
          example: example1@example.com
        unsubscribed_at:
          type: string
          format: date-time
          description: The time the email was unsubscribed in ISO 8601.
          example: "2020-01-28T17:45:00Z"
    QueryUnsubscribedEmailAddressesResponse:
      title: Query unsubscribed email addresses response
      type: object
      properties:
        emails:
          type: array
          items:
            $ref: '#/components/schemas/UnsubscribedEmail'
        message:
          type: string
          example: success
    ErrorResponse:
      title: Error
      type: object
      properties:
        message:
          type: string
          description: The error message describing why the request failed.
        errors:
          type: array
          description: Non-fatal errors encountered while processing the request. Data unaffected by these errors is still processed.
          items:
            type: object
            properties:
              type:
                type: string
                description: The error type.
