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

# Create referral code

> This endpoint allows you to create a referral code



## OpenAPI

````yaml /api-reference/openapi.documented.json post /api/referral/codes
openapi: 3.0.2
info:
  title: Snag Solutions - API Docs
  description: >-
    Documentation for Loyalty & Socials APIs. Some endpoints require an API key
    to authenticate. To obtain a key, reach out to the Snag Solutions team at
    support@snagsolutions.io.
  version: '0.1'
servers:
  - url: https://admin.snagsolutions.io/
    description: Production
security: []
paths:
  /api/referral/codes:
    post:
      tags:
        - Referrals
      summary: Create referral code
      description: This endpoint allows you to create a referral code
      parameters: []
      requestBody:
        description: Body
        content:
          application/json:
            schema:
              type: object
              properties:
                websiteId:
                  type: string
                  format: uuid
                organizationId:
                  type: string
                  format: uuid
                userId:
                  type: string
                  format: uuid
                loyaltyRuleId:
                  type: string
                  format: uuid
                  example: 558bcf56-24f1-4ef4-9787-043086295780
                customReferralCode:
                  type: string
                  maxLength: 8
                  minLength: 1
                  pattern: ^[a-zA-Z0-9]+$
              required:
                - loyaltyRuleId
      responses:
        '200':
          description: '200'
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                  websiteId:
                    type: string
                  organizationId:
                    type: string
                  referralCode:
                    type: string
                  createdAt:
                    type: string
                    format: date-time
                  updatedAt:
                    type: string
                    format: date-time
                  deletedAt:
                    type: string
                    format: date-time
                    nullable: true
                  userId:
                    type: string
                required:
                  - id
                  - websiteId
                  - organizationId
                  - referralCode
                  - createdAt
                  - updatedAt
                  - deletedAt
                  - userId
        '403':
          description: '403'
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    title: Message
                    description: Error message
                    example: Forbidden, Could not validate api key
                required:
                  - message
                title: Forbidden Response
                description: Schema for forbidden response
                example: Forbidden, Could not validate api key
      security:
        - apiKeyAuth: []
components:
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: X-API-KEY

````