openapi: 3.0.0
info:
    title: Instasent legacy API
    description: Instasent legacy API
    version: "1.0.0"
    contact:
        email: dev@instasent.com
        url: https://instasent.com
externalDocs:
    url: https://docs.instasent.com
servers:
    - url: https://api.instasent.com/
      description: Instasent legacy API
security:
    - BearerAuth: []
paths:
    # SMS
    /sms:
        get:
            description: Request SMS collection
            tags:
                - sms
            responses:
                '200':
                    description: Success
                    content:
                        application/json:
                            schema:
                                type: object
                                properties:
                                    entities:
                                        type: array
                                        items:
                                            $ref: '#/components/schemas/ResponseSmsItem'
                                required:
                                    - entities
                '400':
                    $ref: '#/components/responses/WrongRequestError'
                '401':
                    $ref: '#/components/responses/UnauthorizedError'
                '402':
                    $ref: '#/components/responses/NoFundsError'
                '429':
                    $ref: '#/components/responses/RateLimitError'
                '500':
                    $ref: '#/components/responses/InternalError'
        post:
            description: Create SMS
            tags:
                - sms
            requestBody:
                $ref: '#/components/requestBodies/SmsItemBody'
            responses:
                '201':
                    description: Success
                    content:
                        application/json:
                            schema:
                                type: object
                                properties:
                                    entity:
                                        $ref: '#/components/schemas/ResponseSmsItem'
                                required:
                                    - entity
                '400':
                    $ref: '#/components/responses/WrongRequestError'
                '401':
                    $ref: '#/components/responses/UnauthorizedError'
                '402':
                    $ref: '#/components/responses/NoFundsError'
                '413':
                    $ref: '#/components/responses/RequestTooLarge'
                '422':
                    $ref: '#/components/responses/ValidationError'
                '429':
                    $ref: '#/components/responses/RateLimitError'
                '500':
                    $ref: '#/components/responses/InternalError'

    /sms/{id}:
        get:
            description: Request single SMS
            tags:
                - sms
            parameters:
                - name: id
                  in: path
                  description: SMS identifier
                  required: true
                  schema:
                      type: string
            responses:
                '200':
                    description: Success
                    content:
                        application/json:
                            schema:
                                type: object
                                properties:
                                    entity:
                                        $ref: '#/components/schemas/ResponseSmsItem'
                                required:
                                    - entity
                '400':
                    $ref: '#/components/responses/WrongRequestError'
                '401':
                    $ref: '#/components/responses/UnauthorizedError'
                '402':
                    $ref: '#/components/responses/NoFundsError'
                '404':
                    $ref: '#/components/responses/NotFound'
                '429':
                    $ref: '#/components/responses/RateLimitError'
                '500':
                    $ref: '#/components/responses/InternalError'

    /sms/bulk:
        post:
            description: Create Sms collection
            tags:
                - sms
            requestBody:
                $ref: '#/components/requestBodies/SmsCollectionBody'
            responses:
                '201':
                    description: Success
                    content:
                        application/json:
                            schema:
                                type: object
                                properties:
                                    entities:
                                        type: array
                                        items:
                                            $ref: '#/components/schemas/ResponseSmsItem'
                                    errors:
                                        type: array
                                        items:
                                            type: object
                                            properties:
                                                fields:
                                                    type: object
                                                    properties:
                                                        to:
                                                            type: array
                                                            items:
                                                                type: string
                                required:
                                    - entities
                                    - errors
                '400':
                    $ref: '#/components/responses/WrongRequestError'
                '401':
                    $ref: '#/components/responses/UnauthorizedError'
                '402':
                    $ref: '#/components/responses/NoFundsError'
                '413':
                    $ref: '#/components/responses/RequestTooLarge'
                '429':
                    $ref: '#/components/responses/RateLimitError'
                '500':
                    $ref: '#/components/responses/InternalError'

    # Lookup
    /lookup:
        get:
            description: Request Lookup collection
            tags:
                - lookup
            responses:
                '200':
                    description: Success
                    content:
                        application/json:
                            schema:
                                type: object
                                properties:
                                    entities:
                                        type: array
                                        items:
                                            $ref: '#/components/schemas/ResponseLookupItem'
                                required:
                                    - entities
                '400':
                    $ref: '#/components/responses/WrongRequestError'
                '401':
                    $ref: '#/components/responses/UnauthorizedError'
                '402':
                    $ref: '#/components/responses/NoFundsError'
                '429':
                    $ref: '#/components/responses/RateLimitError'
                '500':
                    $ref: '#/components/responses/InternalError'
        post:
            description: Create Lookup
            tags:
                - lookup
            requestBody:
                $ref: '#/components/requestBodies/LookupItemBody'
            responses:
                '201':
                    description: Success
                    content:
                        application/json:
                            schema:
                                type: object
                                properties:
                                    entity:
                                        $ref: '#/components/schemas/ResponseLookupItem'
                                required:
                                    - entity
                '400':
                    $ref: '#/components/responses/WrongRequestError'
                '401':
                    $ref: '#/components/responses/UnauthorizedError'
                '402':
                    $ref: '#/components/responses/NoFundsError'
                '413':
                    $ref: '#/components/responses/RequestTooLarge'
                '422':
                    $ref: '#/components/responses/ValidationError'
                '429':
                    $ref: '#/components/responses/RateLimitError'
                '500':
                    $ref: '#/components/responses/InternalError'
    /lookup/{id}:
        get:
            description: Request single Lookup
            tags:
                - lookup
            parameters:
                - name: id
                  in: path
                  description: Lookup identifier
                  required: true
                  schema:
                      type: string
            responses:
                '201':
                    description: Success
                    content:
                        application/json:
                            schema:
                                type: object
                                properties:
                                    entity:
                                        $ref: '#/components/schemas/ResponseLookupItem'
                                required:
                                    - entity
                '400':
                    $ref: '#/components/responses/WrongRequestError'
                '401':
                    $ref: '#/components/responses/UnauthorizedError'
                '402':
                    $ref: '#/components/responses/NoFundsError'
                '404':
                    $ref: '#/components/responses/NotFound'
                '429':
                    $ref: '#/components/responses/RateLimitError'
                '500':
                    $ref: '#/components/responses/InternalError'

    # Organization
    /organization/account:
        get:
            description: Request organization balance
            tags:
                - account
            responses:
                '200':
                    description: Success
                    content:
                        application/json:
                            schema:
                                type: object
                                properties:
                                    entity:
                                        type: object
                                        properties:
                                            currency:
                                                type: string
                                            available:
                                                type: number
                                        required:
                                            - currency
                                            - available
                                required:
                                    - entity
                '400':
                    $ref: '#/components/responses/WrongRequestError'
                '401':
                    $ref: '#/components/responses/UnauthorizedError'
                '429':
                    $ref: '#/components/responses/RateLimitError'
                '500':
                    $ref: '#/components/responses/InternalError'

    # Prices
    /sms/price-profile/me/countries:
        get:
            description: Request Sms country prices
            tags:
                - sms
            responses:
                '200':
                    description: Success
                    content:
                        application/json:
                            schema:
                                type: object
                                properties:
                                    entities:
                                        type: array
                                        items:
                                            type: object
                                            properties:
                                                currency:
                                                    type: string
                                                price:
                                                    type: number
                                            required:
                                                - currency
                                                - price
                                required:
                                    - entities
                '400':
                    $ref: '#/components/responses/WrongRequestError'
                '401':
                    $ref: '#/components/responses/UnauthorizedError'
                '429':
                    $ref: '#/components/responses/RateLimitError'
                '500':
                    $ref: '#/components/responses/InternalError'

    /lookup/price-profile/me/countries:
        get:
            description: Request Lookup country prices
            tags:
                - lookup
            responses:
                '200':
                    description: Success
                    content:
                        application/json:
                            schema:
                                type: object
                                properties:
                                    entities:
                                        type: array
                                        items:
                                            type: object
                                            properties:
                                                currency:
                                                    type: string
                                                price:
                                                    type: number
                                            required:
                                                - currency
                                                - price
                                required:
                                    - entities
                '400':
                    $ref: '#/components/responses/WrongRequestError'
                '401':
                    $ref: '#/components/responses/UnauthorizedError'
                '429':
                    $ref: '#/components/responses/RateLimitError'
                '500':
                    $ref: '#/components/responses/InternalError'

components:
    securitySchemes:
        BearerAuth:
            type: http
            scheme: bearer

    requestBodies:
        # SMS
        SmsItemBody:
            description: A single SMS item
            required: true
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/RequestSmsItem'
        SmsCollectionBody:
            description: A collection of SMS items
            required: true
            content:
                application/json:
                    schema:
                        type: array
                        items:
                            $ref: '#/components/schemas/RequestSmsItem'
                        minItems: 1
                        maxItems: 100

        # Lookup
        LookupItemBody:
            description: A single Lookup item
            required: true
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/RequestLookupItem'

    schemas:
        # SMS
        RequestSmsItem:
            type: object
            properties:
                clientId:
                    type: string
                    maxLength: 40
                    description: Must be unique per SMS
                from:
                    type: string
                    minLength: 3
                    maxLength: 14
                    description: Max 11 chars or 14 digits
                to:
                    type: string
                    maxLength: 15
                    description: E164 format
                text:
                    type: string
                allowUnicode:
                    type: boolean
                    default: false
            required:
                - from
                - to
                - text
        ResponseSmsItem:
            type: object
            properties:
                id:
                    type: string
                clientId:
                    type: string
                    default: null
                status:
                    type: string
                statusCode:
                    type: integer
                    default: null
                from:
                    type: string
                country:
                    type: string
                to:
                    type: string
                normalizedTo:
                    type: string
                charsCount:
                    type: integer
                text:
                    type: string
                deliveredText:
                    type: string
                messagesCount:
                    type: integer
                encoding:
                    type: string
                unicode:
                    type: boolean
                allowUnicode:
                    type: boolean
                charged:
                    type: boolean
                pricePerSms:
                    type: number
                priceUser:
                    type: number
                createdAt:
                    type: string
                chargedAt:
                    type: string
                    default: null
                scheduledAt:
                    type: string
                    default: null
                sentAt:
                    type: string
                    default: null
                deliveredAt:
                    type: string
                    default: null
            required:
                - id
                - clientId
                - status
                - from
                - country
                - to
                - normalizedTo
                - charsCount
                - text
                - deliveredText
                - messagesCount
                - encoding
                - unicode
                - allowUnicode
                - charged
                - createdAt

        # Lookup
        RequestLookupItem:
            type: object
            properties:
                to:
                    type: string
                    maxLength: 15
                    description: E164 format
            required:
                - to
        ResponseLookupItem:
            type: object
            properties:
                id:
                    type: string
                status:
                    type: string
                subscriberStatus:
                    type: string
                    default: null
                statusCode:
                    type: integer
                    default: null
                country:
                    type: string
                imsi:
                    type: string
                    default: null
                servingMsc:
                    type: string
                    default: null
                to:
                    type: string
                normalizedTo:
                    type: string
                ported:
                    type: boolean
                roaming:
                    type: boolean
                network:
                    type: string
                charged:
                    type: boolean
                pricePerSms:
                    type: number
                createdAt:
                    type: string
                deliveredAt:
                    type: string
                    default: null
            required:
                - id
                - status
                - country
                - to
                - normalizedTo

        # Errors
        ResponseErrorDetail:
            type: object
            properties:
                title:
                    type: string
                status:
                    type: integer
                detail:
                    type: string
            required:
                - title
                - status
                - detail
        ResponseErrorMessage:
            type: object
            properties:
                message:
                    type: string
                code:
                    type: integer
            required:
                - message
        ResponseErrorValidation:
            type: object
            properties:
                errors:
                    type: object
                    properties:
                        fields:
                            type: object
                            properties:
                                to:
                                    type: array
                                    items:
                                        type: string
                    required:
                        - fields
            required:
                - errors

    responses:
        # Errors
        WrongRequestError:
            description: You request body is malformed or something went wrong with your request
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/ResponseErrorDetail'
        UnauthorizedError:
            description: You are missing or using bad credentials
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/ResponseErrorMessage'
        NoFundsError:
            description: You're out of money
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/ResponseErrorDetail'
        NotFound:
            description: Resource can't be found
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/ResponseErrorDetail'
        RequestTooLarge:
            description: You are sending a large body in your request
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/ResponseErrorDetail'
        ValidationError:
            description: Some field of your request body is not valid
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/ResponseErrorValidation'
        RateLimitError:
            description: You reached your endpoint rate limit
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/ResponseErrorMessage'
        InternalError:
            description: Internal server error
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/ResponseErrorDetail'
