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

# Initialize Widget

> Generates a signed session token to initialize the DollarPe embedded widget in your application.

<Prompt description="Initialize Widget" actions={["cursor"]}>
  Integrate the DollarPe Initialize Widget endpoint into my application.

  Endpoint: POST /widget/initialize
  Base URL: [https://api.dollarpe.in](https://api.dollarpe.in) (production) | [https://sandbox.dollarpe.in](https://sandbox.dollarpe.in) (sandbox)

  Auth headers required on every request:

  * X-API-KEY: your API key
  * X-TIMESTAMP: current Unix time in seconds
  * X-SIGNATURE: Base64(HMAC-SHA256(X-API-KEY + X-TIMESTAMP + sortedJSONBody, apiSecret))

  Task: Write a typed function that:

  1. Accepts customer\_id and widget configuration options (flow type, currency preferences)
  2. Builds the signed auth headers
  3. Calls POST /widget/initialize
  4. Returns the session token to pass to the client-side widget SDK
  5. Handles 400 (unverified customer, unsupported flow) and 500 errors

  Language: TypeScript
</Prompt>


## OpenAPI

````yaml POST /widget/initialize
openapi: 3.1.0
info:
  title: DollarPe API
  description: API for DollarPe - Customer, Payout, and Webhook services
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://sandbox.dollarpe.xyz/pos/api/v1
    description: Payout API Base URL
    variables:
      base_url:
        default: https://sandbox.dollarpe.xyz
  - url: https://sandbox.dollarpe.xyz/cms/api/v1
    description: Customer API Base URL
    variables:
      base_url:
        default: https://sandbox.dollarpe.xyz
security:
  - ApiKeyAuth: []
    TimestampAuth: []
    SignatureAuth: []
tags:
  - name: Customer
    description: Customer related operations
    x-displayName: Customer
    x-traitTag: true
  - name: Payout
    description: Payout related operations
  - name: Webhooks
    description: Webhook related operations
  - name: Widget
    description: Hosted buy/sell widget session initialization
paths:
  /widget/initialize:
    post:
      tags:
        - Widget
      description: Initialize a widget session and receive a `widget_link` URL.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              oneOf:
                - type: object
                  title: Buy flow
                  properties:
                    asset_code:
                      type: string
                      description: Cryptocurrency asset code
                      example: USDT
                    fiat_amount:
                      type: string
                      description: Fiat amount the user will pay (buy flow)
                      example: '1000'
                    fiat_currency:
                      type: string
                      description: Fiat currency code
                      example: INR
                    flow_type:
                      type: string
                      enum:
                        - buy
                      description: Must be `buy` for this request shape
                    network_code:
                      type: string
                      description: Blockchain network code for the asset
                      example: tron
                    payment_method:
                      type: string
                      description: Fiat payment method (e.g. IMPS, UPI)
                      example: IMPS
                    wallet_address:
                      type: string
                      description: User's wallet address to receive crypto
                      example: TXqH4MnDw46f3yyrRwau3JF92Y1ie3pAXf
                - type: object
                  title: Sell flow
                  properties:
                    asset_code:
                      type: string
                      description: Cryptocurrency asset code
                      example: USDT
                    asset_amount:
                      type: string
                      description: Crypto amount the user will sell
                      example: '10'
                    fiat_currency:
                      type: string
                      description: Fiat currency code for settlement quote
                      example: INR
                    flow_type:
                      type: string
                      enum:
                        - sell
                      description: Must be `sell` for this request shape
                    network_code:
                      type: string
                      description: Blockchain network code for the asset
                      example: tron
            examples:
              buy:
                summary: Buy flow
                value:
                  asset_code: USDT
                  fiat_amount: '1000'
                  fiat_currency: INR
                  flow_type: buy
                  network_code: tron
                  payment_method: IMPS
                  wallet_address: TXqH4MnDw46f3yyrRwau3JF92Y1ie3pAXf
              sell:
                summary: Sell flow
                value:
                  asset_code: USDT
                  asset_amount: '10'
                  fiat_currency: INR
                  flow_type: sell
                  network_code: tron
      responses:
        '200':
          description: >-
            Widget initialized successfully. The `widget_link` opens the widget;
            query parameters include `app_id` and `flow_type`.
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: Success
                  data:
                    type: object
                    properties:
                      widget_link:
                        type: string
                        format: uri
                        description: >-
                          URL to load the widget (includes `token`, `app_id`,
                          and `flow_type` query parameters)
                    required:
                      - widget_link
                required:
                  - status
                  - message
                  - data
              examples:
                buy:
                  summary: Buy flow response
                  value:
                    message: Success
                    status: true
                    data:
                      widget_link: >-
                        https://app.dollarpe.xyz/login?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJvcmdfaWQiOiJmZjQ2YjNiMC04NTQ3LTRmNDgtODRhNS00MDdjMzhlMGM0ZTkiLCJhcHBfaWQiOiJkb2xsYXJwZSIsImZsb3dfdHlwZSI6ImJ1eSIsImFzc2V0X2NvZGUiOiJVU0RUIiwiYXNzZXRfbmFtZSI6IlRldGhlciIsImFzc2V0X2xvZ28iOiJodHRwczovL2RvbGxhcnBlLXB1YmxpYy1kZXZlbG9wbWVudC5zMy51cy1lYXN0LTEuYW1hem9uYXdzLmNvbS9hc3NldHMvY29pbnMvdXNkdC5wbmciLCJmaWF0X2N1cnJlbmN5IjoiSU5SIiwibmV0d29ya19jb2RlIjoidHJvbiIsIm5ldHdvcmtfbmFtZSI6IlRyb24iLCJwYXltZW50X21ldGhvZCI6ImltcHMiLCJmaWF0X2Ftb3VudCI6IjEwMDAiLCJ3YWxsZXRfYWRkcmVzcyI6IlRYcUg0TW5EdzQ2ZjN5eXJSd2F1M0pGOTJZMWllM3BBWGYiLCJ0eXBlIjoid2lkZ2V0IiwiZXhwIjoxNzc1Njc4OTMxLCJpYXQiOjE3NzU2NzcxMzF9.4xEn4pKEi_nKpi-vY7MoiXqMBdcPgr7xvqNSF8YzMbM&app_id=dollarpe&flow_type=buy
                sell:
                  summary: Sell flow response
                  value:
                    message: Success
                    status: true
                    data:
                      widget_link: >-
                        https://app.dollarpe.xyz/login?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJvcmdfaWQiOiJmZjQ2YjNiMC04NTQ3LTRmNDgtODRhNS00MDdjMzhlMGM0ZTkiLCJhcHBfaWQiOiJkb2xsYXJwZSIsImZsb3dfdHlwZSI6InNlbGwiLCJhc3NldF9jb2RlIjoiVVNEVCIsImFzc2V0X25hbWUiOiJUZXRoZXIiLCJhc3NldF9sb2dvIjoiaHR0cHM6Ly9kb2xsYXJwZS1wdWJsaWMtZGV2ZWxvcG1lbnQuczMudXMtZWFzdC0xLmFtYXpvbmF3cy5jb20vYXNzZXRzL2NvaW5zL3VzZHQucG5nIiwiZmlhdF9jdXJyZW5jeSI6IklOUiIsIm5ldHdvcmtfY29kZSI6InRyb24iLCJuZXR3b3JrX25hbWUiOiJUcm9uIiwicGF5bWVudF9tZXRob2QiOiJpbXBzIiwiYXNzZXRfYW1vdW50IjoiMTIiLCJ0eXBlIjoid2lkZ2V0IiwiZXhwIjoxNzc1Njc4OTAzLCJpYXQiOjE3NzU2NzcxMDN9.s5BQ8gD8NAYHnqdNaMTROMvp8lY-GLoGz_1elWT-m5I&app_id=dollarpe&flow_type=sell
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    example: false
                  message:
                    type: string
                    example: Bad Request
                  data:
                    type: 'null'
                  err_code:
                    type: string
                    example: REQ_FIELD_MISSING
                  errors:
                    type: object
                    additionalProperties:
                      type: array
                      items:
                        type: string
                    example:
                      asset_code:
                        - This field is required.
                      wallet_address:
                        - Invalid wallet address format.
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    example: false
                  message:
                    type: string
                    example: Internal Server Error
                  data:
                    type: 'null'
                  err_code:
                    type: string
                    example: SYS_INTERNAL_ERROR
                  errors:
                    type: string
                    example: Unexpected error occurred. Please try again later.
      servers:
        - url: https://sandbox.dollarpe.xyz
          description: Widget API Base URL
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-KEY
      description: API Key for authentication
    TimestampAuth:
      type: apiKey
      in: header
      name: X-TIMESTAMP
      description: Current timestamp in seconds since epoch
    SignatureAuth:
      type: apiKey
      in: header
      name: X-SIGNATURE
      description: HMAC SHA256 signature of the request encoded in Base64

````