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

# Cancel ASN

> Cancel an ASN that hasn't been received yet

<Warning>
  ASNs can only be cancelled if they haven't been received. Once receiving has started, the ASN cannot be cancelled.
</Warning>

### Path Parameters

<ParamField path="id" type="string" required>
  The unique identifier of the ASN to cancel
</ParamField>

### Request Body

<ParamField body="reason" type="string" required>
  Reason for cancellation
</ParamField>

<ParamField body="cancelled_by" type="string" required>
  User ID or email of the person cancelling the ASN
</ParamField>

<ParamField body="notify_supplier" type="boolean">
  Whether to notify the supplier of the cancellation (default: true)
</ParamField>

<ParamField body="notes" type="string">
  Additional notes about the cancellation
</ParamField>

### Response

<ResponseField name="id" type="string">
  ASN ID
</ResponseField>

<ResponseField name="asn_number" type="string">
  ASN number
</ResponseField>

<ResponseField name="status" type="string">
  Updated status (will be "cancelled")
</ResponseField>

<ResponseField name="cancelled_at" type="string">
  Timestamp of cancellation
</ResponseField>

<ResponseField name="cancelled_by" type="string">
  User who cancelled the ASN
</ResponseField>

<ResponseField name="cancellation_reason" type="string">
  Reason for cancellation
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl --location --request POST 'https://api.stateset.com/v1/asns/asn_0901f083-aa1c-43c5-af5c-0a9d2fc64e30/cancel' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --data-raw '{
      "reason": "Supplier notified of production delay",
      "cancelled_by": "purchasing@company.com",
      "notify_supplier": true,
      "notes": "Shipment delayed by 2 weeks due to material shortage. Will create new ASN when shipment is ready."
  }'
  ```

  ```graphQL GraphQL theme={null}
  mutation CancelASN($id: ID!, $input: CancelASNInput!) {
    cancelASN(id: $id, input: $input) {
      id
      asn_number
      status
      cancelled_at
      cancelled_by
      cancellation_reason
      purchase_order_id
    }
  }
  ```

  ```javascript Node.js theme={null}
  const result = await stateset.asns.cancel(
    'asn_0901f083-aa1c-43c5-af5c-0a9d2fc64e30',
    {
      reason: 'Supplier notified of production delay',
      cancelled_by: 'purchasing@company.com',
      notify_supplier: true,
      notes: 'Shipment delayed by 2 weeks due to material shortage'
    }
  );
  ```

  ```python Python theme={null}
  result = stateset.asns.cancel(
      'asn_0901f083-aa1c-43c5-af5c-0a9d2fc64e30',
      reason='Supplier notified of production delay',
      cancelled_by='purchasing@company.com',
      notify_supplier=True,
      notes='Shipment delayed by 2 weeks due to material shortage'
  )
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "id": "asn_0901f083-aa1c-43c5-af5c-0a9d2fc64e30",
    "object": "asn",
    "asn_number": "ASN-2024-00001",
    "status": "cancelled",
    "cancelled_at": "2024-01-16T10:30:00Z",
    "cancelled_by": "purchasing@company.com",
    "cancellation_reason": "Supplier notified of production delay",
    "purchase_order_id": "po_123456789",
    "supplier_id": "sup_abc123",
    "items_affected": [
      {
        "sku": "WBH-001",
        "quantity": 500
      },
      {
        "sku": "USB-C-001",
        "quantity": 1000
      }
    ],
    "notifications_sent": [
      {
        "type": "email",
        "recipient": "supplier@audiotech.com",
        "sent_at": "2024-01-16T10:31:00Z"
      },
      {
        "type": "webhook",
        "endpoint": "warehouse_system",
        "sent_at": "2024-01-16T10:31:00Z"
      }
    ],
    "notes": "Shipment delayed by 2 weeks due to material shortage. Will create new ASN when shipment is ready."
  }
  ```
</ResponseExample>

### Error Responses

<ResponseField name="error" type="object">
  Error object when cancellation fails

  <Expandable title="Error object properties">
    <ResponseField name="type" type="string">
      Type of error (e.g., "invalid\_status", "already\_received")
    </ResponseField>

    <ResponseField name="message" type="string">
      Human-readable error message
    </ResponseField>

    <ResponseField name="code" type="string">
      Error code for programmatic handling
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseExample>
  ```json Error Response theme={null}
  {
    "error": {
      "type": "invalid_status",
      "message": "Cannot cancel ASN that has already been received",
      "code": "ASN_ALREADY_RECEIVED"
    }
  }
  ```
</ResponseExample>
