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

# Cancel an affiliate sale

> Cancels a website, iOS or Android sale you reported to Growi, the same way a Shopify refund cancels a Shopify sale: the sale is cancelled, its full amount and commission count as refunded, and it stops counting toward creator payouts. Full cancel only. Safe to retry.

Cancels a sale you reported to Growi from your website or your iOS or Android app. Call it from your backend when an order is refunded: a website order you refunded, an App Store refund or a Google Play voided purchase.

It works the same way a Shopify refund cancels a Shopify sale: the sale is marked cancelled, its full amount and commission count as refunded, and it stops counting toward the brand's revenue, the creator's commission and creator payouts. The creator sees it as cancelled.

## Request body

| Field | Type | Description | Required |
| - | - | - | - |
| `conversion_platform` | String | `website`, `ios` or `android`: the platform the sale was created with | Yes |
| `order_id` | String | The same `order_id` you sent when the sale was created: in the `payment_completed` [tracking event](https://docs.growi.io/api-reference/endpoint/create.md) or in [Create affiliate sale](https://docs.growi.io/api-reference/endpoint/create-affiliate-sale.md) | Yes |

## Behavior

* **Call it from your server.** The API key must never reach a browser or an app.
* **Website, iOS and Android only.** Shopify sales are cancelled automatically when the order is refunded in Shopify, so `shopify` is rejected here.
* **Full cancel only.** The whole sale is cancelled and the creator's full commission on it is removed. Partial refunds are not supported: if only part of an order is refunded, decide whether to cancel the sale or leave it.
* **Safe to retry.** Cancelling a sale that is already cancelled changes nothing and returns `200` with `result: "already_cancelled"`.
* **Already paid sales.** A sale whose commission was already paid is cancelled the same way, as with a Shopify refund. Growi does not take money back from creators. To protect yourself, ask Growi to set a payout delay on the campaign that covers most of your refund window.
* **Only your own sales.** Orders are matched to your organization and to the platform you send. An order id from another organization, from another platform or from your Shopify store returns `404`.
* **Rate limits.** Counts toward your [normal API budget](https://docs.growi.io/api-reference/rate-limits.md), including the 2-second spacing. On `429`, wait `Retry-After` seconds and send again.

## When to call it

### Website orders

When you refund an order on your website, send the same `order_id` you used for that sale with `conversion_platform: "website"`.

```bash theme={"dark"}
curl -X POST "https://api.growi.io/api/public/v1/affiliate_sales/cancel" \
     -H "Authorization: Bearer YOUR_PUBLIC_API_KEY" \
     -H "Content-Type: application/json" \
     -d '{ "conversion_platform": "website", "order_id": "ORDER-10045" }'
```

### Apple: App Store Server Notifications

1. In App Store Connect, set your **App Store Server Notifications** URL (version 2) to an endpoint on your server.
2. When a notification arrives with `notificationType` = `REFUND`, verify and decode `signedPayload`, then decode `data.signedTransactionInfo`.
3. Send the same id you sent as `order_id` in `payment_completed` for that purchase. If you sent `transactionId`, send the refunded transaction's `transactionId`. If you sent `originalTransactionId`, send that. Growi keeps one sale per `order_id`, so if you used one id for a whole subscription, any refund on it cancels that one sale.

```js theme={"dark"}
// notificationType === "REFUND"
const tx = decodeJws(payload.data.signedTransactionInfo);
// use the same field you sent as order_id in payment_completed
await fetch("https://api.growi.io/api/public/v1/affiliate_sales/cancel", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.GROWI_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ conversion_platform: "ios", order_id: tx.transactionId }),
});
```

`REFUND_REVERSED` (Apple undid a refund) is not handled by this endpoint. Contact Growi support if it happens.

### Google Play: voided purchases

Poll the [Voided Purchases API](https://developer.android.com/google/play/billing/voided-purchases) (`purchases.voidedpurchases.list`) from your server, for example once a day. It lists refunded, charged back and revoked purchases. For each one, send its `orderId` (the same `GPA.` order id you sent as `order_id` in `payment_completed`).

```bash theme={"dark"}
curl -X POST "https://api.growi.io/api/public/v1/affiliate_sales/cancel" \
     -H "Authorization: Bearer YOUR_PUBLIC_API_KEY" \
     -H "Content-Type: application/json" \
     -d '{ "conversion_platform": "android", "order_id": "GPA.3301-1234-5678-90123" }'
```

## Response

| Field | Type | Description |
| - | - | - |
| `success` | Boolean | `true` when the sale is cancelled (now or before) |
| `result` | String | `cancelled` (this request cancelled it) or `already_cancelled` (nothing changed) |
| `order_id` | String | The order id of the sale |
| `message` | String | What happened, in plain words |
| `affiliate_sale` | Object | The sale, in the same shape as [List affiliate sales](https://docs.growi.io/api-reference/endpoint/list-affiliate-sales.md) |

## Response example

```json theme={"dark"}
{
  "success": true,
  "result": "cancelled",
  "order_id": "2000000812345678",
  "message": "Sale cancelled.",
  "affiliate_sale": {
    "id": 1947458,
    "external_id": "2000000812345678",
    "platform": "ios",
    "status": "cancelled",
    "sale_type": "subscription",
    "sale_occurrence": "initial",
    "customer_occurrence": "first_time",
    "occurred_at": "2026-12-01T14:03:11.000Z",
    "total": 4999,
    "commission": 2000,
    "currency": "usd",
    "sub_id": null,
    "discount_code": null,
    "attribution_method": "cart_attribution",
    "campaign_affiliate_id": 5678,
    "campaign": { "id": 1234, "name": "Ambassadors" },
    "creator": { "id": 812, "name": "Cleo Creator", "email": "cleo@example.com" }
  }
}
```

`commission` is the original commission on the sale. The creator is no longer owed it once the sale is cancelled.

## Errors

| Status | `code` | When | What to do |
| - | - | - | - |
| `404` | `order_not_found` | No sale with this `order_id` on that platform in your organization | Nothing. Orders no creator referred have no sale, so a `404` is expected for them |
| `422` | `invalid_request` | `conversion_platform` is not `website`, `ios` or `android`, `order_id` is missing, or no app is connected for that platform | Fix the request |
| `422` | `cancel_failed` | The sale could not be cancelled. Nothing changed | Send it again later or contact Growi support |
| `401` | | Missing or invalid API key | Check the key |
| `403` | | Read-only API key | Use a full-access key |
| `429` | | Rate limited | Wait `Retry-After` seconds and send again |

```json theme={"dark"}
{
  "success": false,
  "code": "order_not_found",
  "error": "No sale with this order_id was found."
}
```


## OpenAPI

````yaml POST /affiliate_sales/cancel
openapi: 3.0.1
info:
  title: Growi API
  description: >-
    API documentation for Growi platform, showcasing the public tracking event
    endpoint
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.growi.io/api/public/v1
security:
  - bearerAuth: []
paths:
  /affiliate_sales/cancel:
    post:
      summary: Cancel an affiliate sale
      description: >-
        Cancels a website, iOS or Android sale you reported to Growi, the same
        way a Shopify refund cancels a Shopify sale: the sale is cancelled, its
        full amount and commission count as refunded, and it stops counting
        toward creator payouts. Full cancel only. Safe to retry.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CancelAffiliateSale'
      responses:
        '200':
          description: The sale is cancelled (by this request, or already before it)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CancelAffiliateSaleResult'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
        '403':
          description: Read-only API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
        '404':
          description: No sale with this order_id on that platform in your organization
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CancelAffiliateSaleError'
        '422':
          description: >-
            invalid_request: conversion_platform is not website, ios or android,
            order_id is missing, or no app is connected for that platform.
            cancel_failed: the sale could not be cancelled and nothing changed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CancelAffiliateSaleError'
        '429':
          description: Rate limited. Wait Retry-After seconds
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
components:
  schemas:
    CancelAffiliateSale:
      type: object
      required:
        - conversion_platform
        - order_id
      properties:
        conversion_platform:
          type: string
          enum:
            - website
            - ios
            - android
          description: >-
            The platform you created the sale with: website, ios or android.
            Shopify sales are cancelled by Shopify refunds, not by this endpoint
        order_id:
          type: string
          description: >-
            The same order_id you sent when the sale was created (in
            payment_completed or Create affiliate sale), for example your
            website order id, Apple's transactionId or the Google Play orderId
          example: '2000000812345678'
    CancelAffiliateSaleResult:
      type: object
      required:
        - success
        - result
        - order_id
        - message
        - affiliate_sale
      properties:
        success:
          type: boolean
          example: true
        result:
          type: string
          enum:
            - cancelled
            - already_cancelled
          description: >-
            cancelled: this request cancelled the sale. already_cancelled: it
            was cancelled before and nothing changed
        order_id:
          type: string
          example: '2000000812345678'
        message:
          type: string
          example: Sale cancelled.
        affiliate_sale:
          $ref: '#/components/schemas/AffiliateSale'
    ApiError:
      type: object
      properties:
        error:
          type: string
          description: What went wrong
    CancelAffiliateSaleError:
      type: object
      required:
        - success
        - code
        - error
      properties:
        success:
          type: boolean
          example: false
        code:
          type: string
          enum:
            - order_not_found
            - invalid_request
            - cancel_failed
        error:
          type: string
          description: What went wrong
    AffiliateSale:
      type: object
      properties:
        id:
          type: integer
          example: 1947457
          description: Unique Growi identifier for the sale
        external_id:
          type: string
          example: ORD-12345
          description: External order ID
        platform:
          type: string
          example: website
          enum:
            - website
            - ios
            - android
            - shopify
          description: Source platform
        status:
          type: string
          example: unpaid
          enum:
            - paid
            - due
            - unpaid
            - canceled
            - refunded
          description: Sale status
        occurred_at:
          type: string
          format: date-time
          example: '2025-09-30T23:55:29.000Z'
          description: When the sale occurred
        total:
          type: integer
          example: 9999
          description: Total amount in cents
        commission:
          type: integer
          example: 500
          description: Commission amount in cents
        currency:
          type: string
          example: usd
          description: Currency code
        sub_id:
          type: string
          example: instagram
          description: Custom source/sub-ID tag captured on the sale (null when not set)
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.