> ## Documentation Index
> Fetch the complete documentation index at: https://docs.crunchz.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Request - Code

> Generate and send One-Time Password (OTP) codes globally across multiple channels with intelligent channel randomization for optimal delivery success.

## Overview

This endpoint allows you to request a one-time password (OTP) code for global use. GLOBAL means the system will randomize the channel to send or receive the message from or to the user. This endpoint generates a One-Time Password (OTP) with customizable validation settings.

## Request Parameters

<ParamField body="contact_id" type="string" required>
  The contact ID to send the OTP code to. Format: `xxx@c.us`
</ParamField>

<ParamField body="length" type="number" required>
  Length of the OTP code. Maximum value is 6.
</ParamField>

<ParamField body="useLetter" type="boolean" required>
  Whether to include letters in the OTP code.
</ParamField>

<ParamField body="useNumber" type="boolean" required>
  Whether to include numbers in the OTP code.
</ParamField>

<ParamField body="allCapital" type="boolean" required>
  Whether to use uppercase letters for the OTP code.
</ParamField>

<ParamField body="name" type="string" required>
  Application name that will be displayed to the user.
</ParamField>

<ParamField body="expires" type="number" required>
  Expiration time in seconds. For example, 1800 seconds (30 minutes).
</ParamField>

## Response

<ResponseField name="success" type="boolean">
  Indicates whether the request was successful.
</ResponseField>

<ResponseField name="message" type="string">
  A message describing the result of the operation.
</ResponseField>

<ResponseField name="data" type="object">
  <Expandable title="Data Object">
    <ResponseField name="id" type="string">
      The ID of the message.
    </ResponseField>

    <ResponseField name="code" type="string">
      The OTP code sent to the phone.
    </ResponseField>

    <ResponseField name="chat_id" type="string">
      The chat ID.
    </ResponseField>

    <ResponseField name="message" type="string">
      The message.
    </ResponseField>

    <ResponseField name="expired_at" type="string">
      The time when the code expires.
    </ResponseField>

    <ResponseField name="timestamp" type="string">
      The timestamp when it was triggered.
    </ResponseField>
  </Expandable>
</ResponseField>

## Error Codes

<ResponseField name="403" type="object">
  Authorization Exception - Occurs when the request is not properly authorized.
</ResponseField>

<ResponseField name="422" type="object">
  Validation Exception - Occurs when the request parameters fail validation.
</ResponseField>


## OpenAPI

````yaml POST /otp/code/global
openapi: 3.1.0
info:
  title: CrunchzApp API Docs
  version: 1.0.0
  description: >-
    Comprehensive WhatsApp API for seamless messaging integration, automation,
    and customer communication in your applications.
servers:
  - url: https://api.crunchz.app/api
security:
  - http: []
paths:
  /otp/code/global:
    post:
      tags:
        - OTP Code
        - OtpCode
      summary: OTP Code (Global) - Request and Send Code
      description: >-
        Generate and send One-Time Password (OTP) codes globally across multiple
        channels with intelligent channel randomization for optimal delivery
        success.
      operationId: otpCode.globalRequestCode
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/StoreOtpCodeRequest'
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                anyOf:
                  - type: object
                  - $ref: '#/components/schemas/OtpCodeResource'
        '400':
          $ref: '#/components/responses/BadRequestException'
        '401':
          $ref: '#/components/responses/UnauthorizedException'
        '403':
          $ref: '#/components/responses/AuthorizationException'
        '422':
          $ref: '#/components/responses/ValidationException'
        '500':
          $ref: '#/components/responses/InternalServerErrorException'
components:
  schemas:
    StoreOtpCodeRequest:
      type: object
      properties:
        contact_id:
          type: string
          description: Contact ID .
          example: xxx@c.us
        length:
          type: number
          description: Length OTP Code.
          example: 4
          maximum: 6
        useLetter:
          type: boolean
          description: Using letter for Otp Code.
          example: false
        useNumber:
          type: boolean
          description: Using number for Otp Code.
          example: true
        allCapital:
          type: boolean
          description: Using uppercase for Otp Code.
          example: false
        name:
          type: string
          description: Application Name.
          example: Your Company Name
        expires:
          type: number
          description: Expire time in second ( e.g 30 Minute )
          example: 1800
      required:
        - contact_id
        - length
        - useLetter
        - useNumber
        - allCapital
        - name
        - expires
      title: StoreOtpCodeRequest
    OtpCodeResource:
      type: object
      properties:
        success:
          type: boolean
          description: The success status of response.
        message:
          type: string
          description: The message of response.
        data:
          type: object
          properties:
            id:
              type: string
              description: The ID of the message.
            code:
              type: string
              description: The otp code sent to phone.
            chat_id:
              type: string
              description: The chat id.
            message:
              type: string
              description: The message.
            expired_at:
              type: string
              description: The time when the code is expired.
            timestamp:
              type: string
              description: The timestamp when it triggered.
          required:
            - id
            - code
            - chat_id
            - message
            - expired_at
            - timestamp
      required:
        - success
        - message
        - data
      title: OtpCodeResource
  responses:
    BadRequestException:
      description: Bad request error
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Error overview.
            required:
              - message
    UnauthorizedException:
      description: Unauthorized error
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Error overview.
            required:
              - message
    AuthorizationException:
      description: Authorization error
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Error overview.
            required:
              - message
    ValidationException:
      description: Validation error
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Errors overview.
              errors:
                type: object
                description: A detailed description of each field that failed validation.
                additionalProperties:
                  type: array
                  items:
                    type: string
            required:
              - message
              - errors
    InternalServerErrorException:
      description: Internal server error
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Error overview.
            required:
              - message
  securitySchemes:
    http:
      type: http
      scheme: bearer
      bearerFormat: JWT

````