Generate OTP Codes
  • 26 Mar 2024
  • 2 Minutes to read

    Generate OTP Codes


      Article Summary

      Overview

      The Verify API enables you to generate, send, and verify OTP codes for the SMS channel. You can utilize this API to generate OTP codes as defined in the payloads. Integrating it into your own websites or apps, you can trigger it on login pages, payment pages, and more.

      After you create your channel for your brand and update the templates, you need to perform the generate action for your OTP.

      Endpoint and Headers

      POST https://verify.useinsider.com/v1/generate

      Headers

      HeaderSample ValueDescription
      X-INS-AUTH-KEY1a2b3c4d5e6fThis key is required to authorize your request. Refer to API Authentication Tokens to generate your token.
      Content-Typeapplication/jsonThis header specifies the media type of the resource.

      Body Parameters

      ParameterDescriptionData TypeRequiredRules
      channelChannel that you will send the OTP code.StringYesoneof:sms
      toSpecifies the destination phone number in E.164 format to which the OTP code will be sent.
      StringYese164
      localeDetermines the language/locale in which the OTP code message will be sent.
      StringNo (Default: en)
      oneof:de en es fr it ja nl pt ru tr
      ttlSpecifies the Time-To-Live (TTL) duration for the OTP code, i.e., the time window within which the OTP code is valid. Measured in seconds.
      Integer
      No (Default: 180)
      min:60 max:600
      code-lengthSpecifies the length of the OTP code to be generated. The code length must be between 4 and 8 digits.
      Integer
      No (Default: 4)
      min:4 max:8
      custom-codeIf provided, allows you to specify a custom OTP code instead of generating one.
      Integer
      Nomin:1000 max:99999999
      max-attemptsSets the maximum number of allowed OTP verification attempts. If the verification fails after reaching this limit, further attempts might be denied.
      Integer
      No (Default: 3)
      min:1 max:10

      Sample Example

      Sample Request

      Every request made to the request endpoint requires a request body formatted in JSON and containing your parameters. 

      Your title goes here
      Make sure to replace the sample values in the request header(s) and body where required before sending your request.
      curl --location 'https://verify.useinsider.com/v1/generate' \
      --header 'Content-Type: application/json' \
      --header 'x-ins-auth-key: 1a2b3c4d5e6f \
      --data '{
          "channel": "sms",
          "to": "+905XXXXXXXXX"
      }'

      Sample Responses

      202 Accepted

      This response indicates that your request was successfully completed.

      {
          "channel": "sms",
          "dateCreated": "2023-07-28T14:40:41Z",
          "dateUpdated": "2023-07-28T14:40:41Z",
          "locale": "en",
          "maxAttempts": 3,
          "ttl": 180
      }

      400 Bad Request

      {
          "errors": [
              {
                  "message": "invalid request payload"
              }
          ]
      }

      400 Bad Request

      {
          "errors": [
              {
                  "message": "channel information must be a valid phone number for sms",
                  "field": "to"
              }
          ]
      }

      401 Unauthorized

      {
          "errors": [
              {
                  "message": "unauthorized"
              }
          ]
      }

      429 Too Many Requests

      {
          "errors": [
              {
                  "message": "rate limit exceeded"
              }
          ]
      }

      500 Internal Server Error

      {
          "errors": [
              {
                  "message": "server error"
              }
          ]
      }

      Limitations

      • All functions must be executed with a simple HTTPS POST request.
      • The API Key should be provided as the authorization key on the request header. If the key is incorrect, the operation will not be executed and an authorization error will return in the response.

      Was this article helpful?


      ESC

      Eddy, a super-smart generative AI, opening up ways to have tailored queries and responses