# Offers

> Send, counter, accept, decline and withdraw offers.


Offers work where the marketplace takes them (`offers: true` in `GET /marketplaces`). Counteroffers and trades work where it takes trades.

```bash cURL
curl -X POST "https://dev.siteswap.pro/api/v1/offers" -H "Authorization: Bearer ssk_YOUR_KEY" -H "Content-Type: application/json" \
  -d '{"listing_id":"1042","kind":"cash","quantity":20,"total":300,"note":"Can pick up Friday."}'
```
```javascript JavaScript
const res = await fetch("https://dev.siteswap.pro/api/v1/offers?status=open&direction=received", {
  headers: { Authorization: "Bearer " + process.env.SITESWAP_KEY },
});
for (const o of (await res.json()).data) console.log(o.id, o.other_company.name, o.quantity, o.unit, o.total_cents / 100);
```
```python Python
import os, requests
h = {"Authorization": "Bearer " + os.environ["SITESWAP_KEY"]}
r = requests.post("https://dev.siteswap.pro/api/v1/offers/88/accept", headers=h)
print(r.status_code, r.json())
```

## How an offer moves

| From | Call | To |
|---|---|---|
| open | `POST /offers/{id}/accept` (the other side) | accepted. The quantity is set aside on the listing at once. |
| open | `POST /offers/{id}/decline` (the other side) | declined |
| open | `POST /offers/{id}/withdraw` (the side that sent it) | withdrawn |
| open | `POST /offers/{id}/counter` (the other side) | countered; a new open offer answers it |
| open | 7 days pass | expired |

> Note: Accepting locks the listing, so two offers can never be promised the same quantity. When not enough is left, accepting answers `409 not_enough_left`. When the listing changed after the offer was made, `409 listing_changed`: ask for a new offer.

Handing over and cancelling an accepted offer are done on the site, in the conversation.
