Generate Token Code API

Generate discount or benefit token codes for specific users

Tokens

Generate Token Code API

Generate unique token codes for users to apply discounts or receive special benefits. Create targeted promotional codes for individual users.

Create Rewards

Generate user-specific tokens.

Custom Discounts

Set personalized discount rates.

User Targeted

Codes tied to specific users.


Endpoint Overview

MUTATION/graphql

Generate a unique token code for a specific user. The token can include a discount rate and other benefits applicable on future purchases.

Authentication:Bearer Token
Required scopes:adminsupport

Request Parameters

tokenCodeView.userIdInt!Required

The ID of the user for whom the token is generated.

tokenCodeView.discountRateFloat

Discount percentage (0-100) the token provides.

tokenCodeView.expiresAtDateTime

Expiration date for the token code.


GraphQL Mutation

mutation generateTokenCodeForUser($tokenCodeView: TokenCodeView!) {
  generateTokenCodeForUser(tokenCodeView: $tokenCodeView) {
    tokenCode
    message
  }
}

Variables:

{
  "tokenCodeView": {
    "userId": 12345,
    "discountRate": 25
  }
}

HTTP Request:

curl -X POST https://api.orbnet.com/graphql \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \
  -d '{
    "query": "mutation generateTokenCodeForUser($tokenCodeView: TokenCodeView!) { generateTokenCodeForUser(tokenCodeView: $tokenCodeView) { tokenCode message } }",
    "variables": {
      "tokenCodeView": {
        "userId": 12345,
        "discountRate": 25
      }
    }
  }'

Response

200Token Generated Successfully
{
  "data": {
    "generateTokenCodeForUser": {
      "tokenCode": "TKN-ABCD-1234-EFGH",
      "message": "Token code generated successfully for user 12345"
    }
  }
}
400User Not Found
{
  "errors": [
    {
      "message": "User with ID 12345 not found",
      "path": ["generateTokenCodeForUser"],
      "extensions": {
        "code": "USER_NOT_FOUND"
      }
    }
  ],
  "data": null
}
400Invalid Discount Rate
{
  "errors": [
    {
      "message": "Discount rate must be between 0 and 100",
      "path": ["generateTokenCodeForUser"],
      "extensions": {
        "code": "INVALID_DISCOUNT"
      }
    }
  ],
  "data": null
}

Use Cases

Loyalty Rewards

Reward long-term customers.

Compensation

Make up for service issues.

Promotions

Special offers for select users.

Referral Rewards

Thank users for referrals.


Best Practices

Document Reason

Record why token was generated.

Set Expiration

Add expiry for time-limited offers.

Reasonable Discount

Use appropriate discount levels.

Notify User

Inform user about their token.



Single Use

Generated token codes are typically single-use and tied to the specific user. After redemption, the code becomes inactive.

Verify Token Codes

Check the status and details of generated tokens.

Check Token