# Delete unpaid memberships for a member

`DELETE /api/members/{memberId}/memberships/unpaid`

- **Success:** `200 OK`
- **Products:** Operator (`FOH`), Consumer (`CONSUMER`) (any one of these products, not all)
- **Features:** Online Joining (`ONLINEJOIN`), Front of House Generic Access (`FOHGENERIC`) (any one of these features, not all)

HTML version: [Delete unpaid memberships for a member](https://support.gladstonesoftware.cloud/reference/members/delete-unpaid-memberships-for-a-member)

## Overview

Abandons a membership purchase that was never paid for. Use it when a member starts a join or renewal, an invoice is raised, and payment is then abandoned — the half-finished records would otherwise sit against the member forever and confuse later purchases.

A membership is removed only if **both** of these hold:

- its sales invoice is still in the *unpaid* state, and
- no receipt has been allocated against that invoice — not even a partial one.

Anything with money against it is left completely alone. The call is therefore safe to make speculatively, but it is not selective: you cannot name a particular membership, so **every** unpaid membership the member holds is removed in one go.

For each membership that qualifies, the endpoint deletes the membership, its sales invoice and invoice lines, any discount products attached to the membership, and the matching unpaid items in the member's basket. It then updates the member's own record and adds entries to the member's event log for the change. The deletion is not reversible through the API — the member has to buy the membership again.

The call returns `200 OK` even when nothing was deleted, so the status code alone tells you nothing about what happened. Read `paidMembershipsAreOutstanding` to find out whether paid memberships were left behind.

One quirk worth knowing before you parse the response: it is a single JSON object, not an array, even though the field paths below are written with a leading `[]`.

## Endpoint

`DELETE {base_url}/api/members/{memberId}/memberships/unpaid`

`{base_url}` is the environment URL issued to your integration. See [Authenticating with Gladstone APIs](../../guides/authenticating-with-gladstone-apis.md).

## Path parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `memberId` | integer (int32) | Yes | The member whose unpaid memberships are removed. Must be greater than `0`; `0` (non-member) and `-999` (purged member) are rejected with `400`. With a member-scoped token you may pass either your own id or that of a member linked to you — but a **secondary** member cannot pass the id of their **primary** member, which is rejected with `403`. |

## Sample request

```bash title="cURL"
curl -X DELETE '{base_url}/api/members/{memberId}/memberships/unpaid' \
  -H 'Authorization: Bearer {accessToken}' \
  -H 'X-Use-SSO: true'
```

## Response fields

| Field | Type | Description |
|-------|------|-------------|
| `[].paidMembershipsAreOutstanding` | boolean | `true` when the member still has at least one membership invoice with a receipt allocated against it — that is, memberships that were paid for, in full or in part, and so were deliberately **not** deleted. Use it to decide whether the member is now left with nothing (`false`) or still holds paid memberships you must account for (`true`). It is not a success flag: `false` is also what you get when the member had no membership records at all, and it says nothing about how many unpaid memberships were removed. |

## Sample response

```json title="200 OK"
[
  {
    "paidMembershipsAreOutstanding": true
  }
]
```

## Errors

| Status | Meaning | When |
|--------|---------|------|
| `400` | Bad request | `memberId` is `0` or negative. The body is `{memberId} is an invalid member ID`. |
| `401` | Unauthorized | The endpoint itself does not return this. In practice a `401` means your access token was missing, expired or rejected before the request was processed — see [Authenticating with Gladstone APIs](../../guides/authenticating-with-gladstone-apis.md). |
| `403` | Forbidden | Your token is for a secondary member and `memberId` is their primary member. The body is `The linked member cannot modify records for their primary member.` The relationship is one-way: a primary member may act on a linked member, but not the reverse. |
| `403` | Forbidden | Your token is for a member who is neither `memberId` nor linked to them. The body is `The given member ID of {memberId} does not belong to the logged in member nor any linked members`. |
| `404` | Not found | `memberId` does not exist. The body is `The given member could not be found.` A member who exists but has no memberships returns `200`, not `404`. |
| `500` | Internal server error | An unexpected server-side failure while reading or deleting the membership records. Because the deletions are applied together, a failure part-way leaves the member's memberships as they were. |
