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

# Cancel by user reference

> Cancel orders by their client-defined reference

Cancel every open order in the given game whose `userReference` matches one of the supplied references. Useful when you've tagged orders with your own ids and want to cancel by those instead of tracking 4casters order ids.

## Request

`POST /session/cancelByReference`

<ParamField body="gameID" type="string" required>
  Scope the search to a single game.
</ParamField>

<ParamField body="userReferences" type="array" required>
  Array of `userReference` strings. Every open order in `gameID` whose `userReference` is in this array is cancelled.
</ParamField>

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST https://api.4casters.io/session/cancelByReference \
    -H "Authorization: Bearer YOUR_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "gameID": "6924f82640a7e89c3d3acc41",
      "userReferences": ["my-order-1", "my-order-2"]
    }'
  ```
</CodeGroup>

## Response

<ResponseField name="data" type="array">
  Per-order cancel results. Same shape as [Cancel an order](/pages/rest/orders/cancel-order#response).
</ResponseField>

## Errors

| Status | Meaning                                   |
| ------ | ----------------------------------------- |
| `400`  | `userReferences` missing or not an array. |


## OpenAPI

````yaml POST /session/cancelByReference
openapi: 3.1.0
info:
  title: 4casters REST API
  version: 1.0.0
  description: >-
    Public REST API for the 4casters peer-to-peer betting exchange. Use this API
    to manage your account, query the orderbook and games, and place / edit /
    cancel orders.


    All responses (unless noted otherwise) are JSON envelopes of the form `{
    "data": ... }`.
  contact:
    name: 4casters
    url: https://4casters.io
servers:
  - url: https://api.4casters.io
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Authentication
    description: Login and account session management
  - name: User
    description: Read account info, bets, and orders
  - name: Orders
    description: Place, edit, look up, and cancel orders
  - name: Markets
    description: Browse leagues, games, participants, and orderbooks
  - name: Affiliate
    description: Affiliate / referral commission
paths:
  /session/cancelByReference:
    post:
      tags:
        - Orders
      summary: Cancel orders by user reference
      description: >-
        Cancel every open order in the given game whose `userReference` matches
        one of the supplied references.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - userReferences
                - gameID
              properties:
                userReferences:
                  type: array
                  items:
                    type: string
                gameID:
                  type: string
            example:
              gameID: 6924f82640a7e89c3d3acc41
              userReferences:
                - my-order-1
                - my-order-2
      responses:
        '200':
          description: Per-order cancel results
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/CancelResult'
        '400':
          description: '`userReferences` missing or not an array'
        '401':
          $ref: '#/components/responses/Unauthorized'
components:
  schemas:
    CancelResult:
      type: object
      properties:
        success:
          type: boolean
        reason:
          type: string
          description: Failure reason. Present only when `success` is `false`.
        sessionID:
          type: string
          description: Order id.
        description:
          type: string
          description: Human-readable order description (e.g. `Lakers -3.5 -110`).
        odds:
          type: integer
          description: American odds of the cancelled order.
        filled:
          type: number
        offered:
          type: number
        remaining:
          type: number
        gameID:
          type: string
        userReference:
          type: string
  responses:
    Unauthorized:
      description: Missing or invalid auth token
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Pass your auth token in the `Authorization` header. The `Bearer` prefix
        is optional; the server also accepts a signed `auth` cookie or a `token`
        field in the request body.

````