---
openapi: 3.0.3
info:
  title: Braze REST API – Query invalid phone numbers
  description: |
    ## Prerequisites

    To use this endpoint, you'll need an [API key]({{site.baseurl}}/api/basics#rest-api-key-permissions) with the `sms.invalid_phone_numbers` 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:
  "/sms/invalid_phone_numbers":
    get:
      summary: Query invalid phone numbers
      operationId: get_sms_invalid_phone_numbers_get_query_invalid_numbers
      parameters:
        - name: start_date
          in: query
          required: false
          description: |
            Start date of the range to retrieve invalid phone numbers, must be earlier than `end_date`. This is treated as midnight in UTC time by the API.

            You must provide either a `start_date` and an `end_date` OR `phone_numbers`. If you provide all three, `start_date`, `end_date`, and `phone_numbers`, we prioritize the given phone numbers and disregard the date range.
          schema:
            type: string
            format: date
          example: "2019-01-01"
        - name: end_date
          in: query
          required: false
          description: |
            End date of the range to retrieve invalid phone numbers. This is treated as midnight in UTC time by the API. Results include invalid numbers detected through the end of this calendar day in UTC (inclusive).

            You must provide either a `start_date` and an `end_date` OR `phone_numbers`. If you provide all three, `start_date`, `end_date`, and `phone_numbers`, we prioritize the given phone numbers and disregard the date range.
          schema:
            type: string
            format: date
          example: "2019-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: 100
        - name: offset
          in: query
          required: false
          description: |
            Optional beginning point in the list to retrieve from.

            If your date range has more than the `limit` number of invalid phone numbers, you will need to make multiple API calls with increasing the `offset` each time until a call returns either fewer than `limit` or zero results.
          schema:
            type: integer
            minimum: 0
            default: 0
          example: 1
        - name: phone_numbers[]
          in: query
          required: false
          description: |
            If provided, Braze returns the phone number if it has been found to be invalid.

            You must provide either a `start_date` and an `end_date` OR `phone_numbers`. If you provide all three, `start_date`, `end_date`, and `phone_numbers`, we prioritize the given phone numbers and disregard the date range.
          schema:
            type: array
            maxItems: 50
            items:
              type: string
              description: Phone number in e.164 format.
          example:
            - "+15555550100"
        - name: reason
          in: query
          required: false
          description: Available values are `provider_error` (the provider indicates the phone cannot receive SMS), `deactivated` (the phone number has been deactivated), or `invalid_format` (the number failed formatting validation, such as a non-E.164 value). If omitted, all reasons are returned.
          schema:
            type: string
            enum: [provider_error, deactivated, invalid_format]
          example: provider_error
      responses:
        "200":
          description: |
            The request succeeded and the response body lists the invalid phone numbers. No action needed.

            Entries are listed in ascending order.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/QueryInvalidNumbersResponse'
              examples:
                success:
                  summary: Invalid phone numbers
                  value:
                    sms:
                      - phone: "+15555550100"
                        invalid_detected_at: "2019-01-20T15:42:07Z"
                        reason: provider_error
                      - phone: "+15555550101"
                        invalid_detected_at: "2019-01-12T09:15:30Z"
                        reason: deactivated
                      - phone: "+15555550102"
                        invalid_detected_at: "2019-01-05T18:03:11Z"
                        reason: invalid_format
                    message: success
        "400":
          description: |
            Bad request. To resolve it:

            - **Neither a phone number nor a `start_date`/`end_date` pair was provided:** Include `phone_numbers`, or both `start_date` and `end_date`.
            - **The `start_date` or `end_date` isn't formatted as `YYYY-MM-DD`:** Format `start_date` and `end_date` as `YYYY-MM-DD`.
            - **The `start_date` is after the `end_date`:** Set `start_date` earlier than `end_date`.
            - **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 negative:** Pass an `offset` of 0 or greater.
            - **The `reason` isn't an allowed value:** Set `reason` to `provider_error`, `deactivated`, or `invalid_format`.
            - **The `phone_numbers` value isn't an array:** Pass `phone_numbers` as an array of e.164 strings.
            - **More than 50 phone numbers were provided:** Send 50 or fewer phone numbers per request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                missing_phone_numbers_or_dates:
                  summary: Neither phone numbers nor a date range
                  value:
                    message: You must provide either a phone number or a start_date and end_date
                bad_date_format:
                  summary: A date isn't in YYYY-MM-DD format
                  value:
                    message: Start date and end date must be in the format YYYY-MM-DD
                start_date_after_end_date:
                  summary: The start date is after the end date
                  value:
                    message: The start date must be before the end date
                limit_too_low:
                  summary: The limit is less than 1
                  value:
                    message: Limit must be >= 1
                limit_too_high:
                  summary: The limit is greater than 500
                  value:
                    message: You cannot set a limit to over 500
                negative_offset:
                  summary: The offset is negative
                  value:
                    message: Offset must be >= 0
                invalid_reason:
                  summary: The reason isn't an allowed value
                  value:
                    message: 'Reason must be one of: invalid_format, deactivated, provider_error'
                phone_numbers_not_array:
                  summary: The phone_numbers value isn't an array
                  value:
                    message: Phone numbers have to be in an array
                too_many_phone_numbers:
                  summary: More than 50 phone numbers
                  value:
                    message: You can only pass in up to 50 phone numbers at a time.
        "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 `sms.invalid_phone_numbers` 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 `sms.invalid_phone_numbers` permission.
        Pass the key as `Authorization: Bearer YOUR_REST_API_KEY`.
  schemas:
    InvalidPhoneNumber:
      title: Invalid phone number
      type: object
      properties:
        phone:
          type: string
          description: Phone number in e.164 format.
          example: "+15555550100"
        invalid_detected_at:
          type: string
          description: The time the invalid number was detected in ISO 8601.
          example: "2019-01-20T15:42:07Z"
        reason:
          type: string
          enum: [provider_error, deactivated, invalid_format]
          description: Why the phone number was marked invalid.
          example: provider_error
    QueryInvalidNumbersResponse:
      title: Query invalid phone numbers response
      type: object
      required: [sms, message]
      properties:
        sms:
          type: array
          items:
            $ref: '#/components/schemas/InvalidPhoneNumber'
        message:
          type: string
          description: Returns `success` when the request completes without errors.
          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.
