# Offer routes: trial, withdraw

URL: /code/api/offer/verbs-trial · Id: `page:code/api/offer/verbs-trial`

> The Offer Verbs trial, withdraw as api.sb routes, with inputs, result, refusals and an example.

Reference for [Offer](/business/nouns/offer), one group of [Offer routes](/code/api/offer).

### Offer.trial
Trial starts a Customer on an Offer free for a set number of days, with or without a card, converting or ending by its terms. [Verb page](/business/nouns/offer/trial?interface=api).

```text
POST /{namespace}/offers/{offer}/trial
```

Path: `offer`. Body, as JSON: the other inputs. Emits [`Offer.trialed`](/business/events/Offer.trialed).

**Inputs**

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `offer` | [Offer](/business/nouns/offer) | Yes | The Offer to try. |
| `customer` | [Customer](/business/nouns/customer) | Yes | The Customer who tries it. |
| `days` | `integer` | Yes | How long the trial runs. Never randomized. |
| `card` | `boolean` | No | True to take a card up front and charge it when the trial ends. |

**Returns**

| Output | Type | Required | Description |
| --- | --- | --- | --- |
| `subscription` | [Subscription](/business/nouns/subscription) | Yes | The Subscription, free until the trial ends. |
| `offer` | [Offer](/business/nouns/offer) | Yes | The Offer the trial is on. |

**Refuses when**

| Check | Error | Fix | Then call |
| --- | --- | --- | --- |
| The key is valid, but its scopes do not allow this operation. | [`forbidden`](/code/api/errors/forbidden) | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |

**Example**

```bash
curl -X POST https://api.sb/leaseline.app/offers/offer_2hzYe1ERo0/trial \
  -H "Authorization: Bearer $STARTUP_BUILDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"customer":"cus_K1BROJhqzZ","days":1}'
```

```json
{
  "api": "https://api.sb/leaseline.app",
  "subscription": {
    "$id": "https://api.sb/leaseline.app/subscriptions/sub_jpvy3zejKB",
    "$type": "Subscription",
    "status": "active"
  },
  "offer": {
    "$id": "https://api.sb/leaseline.app/offers/offer_2hzYe1ERo0",
    "$type": "Offer",
    "price": {
      "amount": 29,
      "currency": "USD"
    }
  },
  "action": {
    "$id": "https://api.sb/leaseline.app/actions/act_br07HsG8MG",
    "operation": "Offer.trial",
    "status": "done"
  },
  "links": {
    "self": "https://api.sb/leaseline.app/actions/act_br07HsG8MG"
  }
}
```

### Offer.withdraw
Withdraw closes a published Offer to new Customers and leaves every existing Order and Subscription in force. [Verb page](/business/nouns/offer/withdraw?interface=api).

```text
POST /{namespace}/offers/{offer}/withdraw
```

Path: `offer`. Emits [`Offer.withdrawn`](/business/events/Offer.withdrawn).

**Inputs**

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `offer` | [Offer](/business/nouns/offer) | Yes | The Offer to withdraw. |

**Returns**

| Output | Type | Required | Description |
| --- | --- | --- | --- |
| `offer` | [Offer](/business/nouns/offer) | Yes | The Offer, closed to new acceptance. |

**Refuses when**

| Check | Error | Fix | Then call |
| --- | --- | --- | --- |
| The key is valid, but its scopes do not allow this operation. | [`forbidden`](/code/api/errors/forbidden) | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |
| The record is not in a state that allows this Verb, so the call is refused. | [`refused`](/code/api/errors/refused) | Read the record, run the Verb that moves it to an allowed state, then retry. | None. |

**Example**

```bash
curl -X POST https://api.sb/leaseline.app/offers/offer_2hzYe1ERo0/withdraw \
  -H "Authorization: Bearer $STARTUP_BUILDER_API_KEY"
```

```json
{
  "api": "https://api.sb/leaseline.app",
  "offer": {
    "$id": "https://api.sb/leaseline.app/offers/offer_2hzYe1ERo0",
    "$type": "Offer",
    "price": {
      "amount": 29,
      "currency": "USD"
    }
  },
  "action": {
    "$id": "https://api.sb/leaseline.app/actions/act_br07HsG8MG",
    "operation": "Offer.withdraw",
    "status": "done"
  },
  "links": {
    "self": "https://api.sb/leaseline.app/actions/act_br07HsG8MG"
  }
}
```