# Withdraw one of your students from an exam

- Endpoint: `DELETE /v1/{organizationId}/application/{applicationId}`
- Production: `https://api.main-team.org/v1/{organizationId}/application/{applicationId}`
- Sandbox: `https://apisnd.main-team.org/v1/{organizationId}/application/{applicationId}`
- Operation: `deleteApplication` (Applications)
- Authentication: `Authorization: Bearer <token>`, a short-lived token you sign with your API key and secret
- Permission: `application/delete:$org:$ID`

## Description

Deletes an application of one of your students. `data` is the application as it was, with `exam`, `payment` and `user` as ids.

An application whose payment is settled (`status` `paid`, with an `amount` above 0) cannot be deleted: deleting refunds nothing, and this API never moves money. A free exam’s payment (`paid`, `amount` 0) and a `pending` or `canceled` one do not block it.

The payment is the only state checked. Whether the student has started the exam, or its sitting has passed, is not: read `participated` and `examSubmitted` first if that matters to you.

Your students are the ones your account registered: an application of anyone else’s student answers `404`, as an unknown id does. Deleting again answers `404` too, so a retried delete that gets `404` has already succeeded.

## Parameters

| Name | In | Required | Type | Description |
| --- | --- | --- | --- | --- |
| `organizationId` | path | yes | string | The organization’s `_id`: 24 hexadecimal digits, as `listOrganizations` (`GET /v1/organization`) lists it. |
| `applicationId` | path | yes | string | The application’s `_id`, from `createApplication` or one of the application lists. |

## Response

`200` Success: `message` is "Application deleted successfully.".

```json
{
  "success": true,
  "message": "Application deleted successfully.",
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 57,
    "totalPages": 3
  },
  "data": {
    "_id": "6650a1b2c3d4e5f6a7b8c9e5",
    "exam": "6650a1b2c3d4e5f6a7b8c9e1",
    "user": "6650a1b2c3d4e5f6a7b8c9e9",
    "payment": "6650a1b2c3d4e5f6a7b8c9e6",
    "partners": [
      {
        "user": "6650a1b2c3d4e5f6a7b8c9d6",
        "accepted": true
      }
    ],
    "participated": false,
    "examStart": "2026-11-14T10:04:12.000Z",
    "examSubmitted": false,
    "submitDate": "2026-11-14T11:12:40.000Z",
    "simulationStarted": false,
    "simulationStart": "2026-11-07T10:00:00.000Z",
    "simulationSubmitted": false,
    "removeAfter": "2026-09-02T14:05:00.000Z",
    "uuid": "a3f-09c-7e1",
    "createdAt": "2026-09-01T09:30:00.000Z",
    "updatedAt": "2026-09-02T14:05:00.000Z"
  }
}
```

## Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | [`bad_request`](https://hub.main-team.org/api/errors#bad_request) | `applicationId` is not 24 hexadecimal digits. |
| 401 | [`unauthorized`](https://hub.main-team.org/api/errors#unauthorized) | The token is missing or malformed, is not signed with your account’s `apiSecret`, breaks the `iat` and `exp` rules, has expired or been revoked, or its account is not active. All of these answer the same. |
| 403 | [`forbidden`](https://hub.main-team.org/api/errors#forbidden) | The token is valid, but no role on your account allows `application/delete` on the organization in the path, or a role denies it. |
| 404 | [`not_found`](https://hub.main-team.org/api/errors#not_found) | `organizationId` is not the `_id` of an organization. |
| 404 | [`not_found`](https://hub.main-team.org/api/errors#not_found) | No application of your students has this id: it matches nothing, or the application belongs to another account’s student. Both get the same answer. |
| 409 | [`conflict`](https://hub.main-team.org/api/errors#conflict) | The payment is settled. Cancelling a paid application is a refund, which happens outside this API. |
| 429 | [`too_many_requests`](https://hub.main-team.org/api/errors#too_many_requests) | Your account has made more than 100 requests to this operation in the current 60-second window. Wait the seconds in `Retry-After` before sending again. |
| 500 | [`internal_error`](https://hub.main-team.org/api/errors#internal_error) | Something failed on our side. Retry later, and quote `request_id` if it goes on. |

## Code samples

### curl

```bash
# $TOKEN: a short-lived token you minted with your API key and secret
curl -sS -X DELETE 'https://api.main-team.org/v1/<organizationId>/application/<applicationId>' \
  -H "Authorization: Bearer $TOKEN"
```

### Node.js

```js
const token = process.env.TOKEN; // a short-lived token you minted with your API key and secret

const res = await fetch('https://api.main-team.org/v1/<organizationId>/application/<applicationId>', {
  method: 'DELETE',
  headers: {
    Authorization: `Bearer ${token}`,
  },
});
const body = await res.json();
if (!res.ok) throw new Error(`${res.status} ${body.error.code}: ${body.error.message}`);
console.log(body.data);
```

### PHP

```php
<?php
$token = getenv('TOKEN'); // a short-lived token you minted with your API key and secret

$ch = curl_init('https://api.main-team.org/v1/<organizationId>/application/<applicationId>');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'DELETE',
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . $token,
    ],
    CURLOPT_RETURNTRANSFER => true,
]);
$response = curl_exec($ch);
if ($response === false) {
    throw new RuntimeException(curl_error($ch));
}
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
$body = json_decode($response, true);
if ($status >= 400) {
    $error = $body['error'];
    throw new RuntimeException("$status {$error['code']}: {$error['message']}");
}
print_r($body['data']);
```
