# Remove membership

Source: https://docs.tradeit.app/api/remove-membership

Call this endpoint from your server when a user leaves your platform and you want to end their organization membership.

```http
DELETE https://api.tradeit.app/api/partner/membership
Authorization: Basic <base64_encoded_client_credentials>
Content-Type: application/json

{ "user_id": 7 }
```

Authenticate with your organization's `client_id` and `client_secret`, using the same HTTP Basic format as the [Onboarding Portal](/sdk/onboarding).

## Example [#example]

```js
const credential = Buffer.from(
  `${encodeURIComponent(clientId)}:${encodeURIComponent(clientSecret)}`,
).toString('base64');

const response = await fetch('https://api.tradeit.app/api/partner/membership', {
  method: 'DELETE',
  headers: {
    Authorization: `Basic ${credential}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ user_id: tradeItUserId }),
});
if (!response.ok) throw new Error('Could not remove Trade It organization membership');
```

On success, Trade It returns `200`:

```json
{ "success": true }
```

## Membership and billing [#membership-and-billing]

The endpoint uses the same removal process as the organization's member-management screen:

- Removes this user's membership and roles in your organization. Memberships in other organizations are unaffected.
- Ends your organization's sponsorship of the user's Trade It Pro access.
- Retains usage already incurred in the current billing cycle. Removing an already-active user does not refund that cycle; they do not count in subsequent cycles unless they rejoin.
- Preserves their Trade It account, brokerage connections, accounts, and OAuth authorization. Membership removal does not revoke their tokens.

Completing partner onboarding again can restore the membership. Stop calling Trade It on the user's behalf after removing them from your platform.

## Errors [#errors]

| Status | Meaning |
| --- | --- |
| `400` | The JSON body is invalid, `user_id` is not a positive integer, or the member is the organization's last administrator. Assign another administrator before removing the last one. |
| `401` | HTTP Basic client credentials are missing, malformed, or invalid. User bearer tokens are not accepted. |
| `404` | No matching organization or active membership exists. A repeated removal returns `404`. |
