> ## Documentation Index
> Fetch the complete documentation index at: https://docs.go.gbgplc.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Delete journey data with the API

> Delete a completed journey session with the /journey/state/delete endpoint.

To delete a journey session, send its `instanceId` to the [`/journey/state/delete`](https://docs.go.gbgplc.com/docs/go-v1/api-reference/endpoint/delete-journey-state) endpoint. You can delete only journeys with the status `Completed`. For any other journey, including a journey that ended with the status `Error`, the API returns a `409` error.

> [!WARNING]
>
> This request deletes the journey's data from the GBG Go API service only. It doesn't delete the journey session record, documents, or biometrics in the Investigation portal. To delete those, for example for a GDPR erasure request, use [Delete journey session](https://docs.go.gbgplc.com/docs/go-v1/platform/investigate/delete-journey-session.md) in the Investigation portal.

## Before you begin

Make sure you have:

* **Access token**: Obtained in [Step 1: Authenticate](https://docs.go.gbgplc.com/docs/go-v1/developer-integration/execute-customer-journeys/authenticate.md).
* **Instance ID**: The `instanceId` returned by [`/journey/start`](https://docs.go.gbgplc.com/docs/go-v1/api-reference/endpoint/start-journey) when the journey started.

### Choose the base URL for your region

Use the base URL for the region where your journeys run.

| Region | Base URL |
| - | - |
| Europe | `https://eu.platform.go.gbgplc.com/captain/api` |
| United States | `https://us.platform.go.gbgplc.com/captain/api` |
| Australia | `https://au.platform.go.gbgplc.com/captain/api` |

The examples on this page use the Europe base URL. If your journeys run in another region, then replace `eu` with `us` or `au`.

## Step 1: Check that the journey has completed

This step is optional. If you're not sure whether the journey has completed, then fetch its state first.

```bash cURL theme={null}
curl --request POST \
  --url https://eu.platform.go.gbgplc.com/captain/api/journey/state/fetch \
  --header 'Authorization: Bearer your_access_token' \
  --header 'Content-Type: application/json' \
  --data '{
    "instanceId": "your-instance-id"
  }'
```

For the status values in the response, see [Step 6: Fetch journey state](https://docs.go.gbgplc.com/docs/go-v1/developer-integration/execute-customer-journeys/fetch-journey-state-step.md).

## Step 2: Delete the journey session

Send a `POST` request to `/journey/state/delete` with the `instanceId` in a JSON body. The endpoint uses the `POST` method, not the HTTP `DELETE` method.

```bash cURL theme={null}
curl --request POST \
  --url https://eu.platform.go.gbgplc.com/captain/api/journey/state/delete \
  --header 'Authorization: Bearer your_access_token' \
  --header 'Content-Type: application/json' \
  --data '{
    "instanceId": "your-instance-id"
  }'
```

### Request headers

| Header | Value |
| - | - |
| `Authorization` | `Bearer <access token>` |
| `Content-Type` | `application/json` |

### Request body fields

| Field | Type | Required | Description |
| - | - | - | - |
| `instanceId` | string | Yes | The journey instance ID returned by `/journey/start`. |

The API ignores any other fields in the request body.

## Handle the response

The API returns `200` when it schedules the deletion, before the deletion runs. The response contains the instance ID of the journey.

```json JSON theme={null}
{
  "instanceId": "PRC-b294e258-d918-11f1-9747-46db552413b4"
}
```

| Field | Type | Description |
| - | - | - |
| `instanceId` | string | The instance ID of the journey to delete. |

The deletion runs a few seconds after the response. Until then, `/journey/state/fetch` can still return the journey, and a repeated delete request returns `200` again.

In rare cases, a `200` response isn't followed by a deletion. To confirm the deletion, call `/journey/state/fetch` until it returns an error.

### After deletion

Once the deletion finishes, you can't fetch or delete the journey again:

* A `/journey/state/fetch` request for the same `instanceId` returns a `500` error with the message `Server setup has some issues`.
* A second `/journey/state/delete` request returns a `400` error with the identifier `journey-instance-not-found`.

### Error responses

Each error returns a body with the HTTP status, an error message, and an error identifier. Most errors also include a `loggerMessage` field:

```json JSON theme={null}
{
  "status": 409,
  "message": "An inflight journey can not be deleted",
  "error": "journey-instance-not-found",
  "loggerMessage": "The journey PRC-b294e258-d918-11f1-9747-46db552413b4 is not available for delete."
}
```

| Field | Type | Description |
| - | - | - |
| `status` | integer | The HTTP status code. |
| `message` | string | A description of the error. |
| `error` | string | The error identifier. |
| `loggerMessage` | string | Internal diagnostic detail. Include it when you contact GBG support, but don't parse it, because it can change. |

| HTTP status | `error` | When it happens |
| - | - | - |
| `400` | `invalid-token` | The access token is missing or invalid. |
| `400` | `bad-request-error` | The request body has no `instanceId`, or isn't valid JSON. |
| `400` | `journey-instance-not-found` | No journey with this `instanceId` is available to your organisation. This includes a journey that's already deleted, an incorrect `instanceId`, and another organisation's journey. |
| `404` | `not-found-error` | The request used the wrong method or path. For example, `GET` or `DELETE` instead of `POST`. |
| `409` | `journey-instance-not-found` | The journey doesn't have the status `Completed`. This includes a journey that's still in progress and a journey that ended with the status `Error`. |
| `500` | `default-error` | An unexpected error occurred. Retry later. If the error repeats, then contact GBG support with the response body and the time of the request. |
| `503` | | The service is temporarily unavailable. Retry later. |

> [!NOTE]
>
> Check the HTTP status as well as `error`. The identifier `journey-instance-not-found` is returned both for a journey that hasn't completed (`409`) and for a journey that isn't available to your organisation (`400`).

For help with these errors, see [Handle errors](https://docs.go.gbgplc.com/docs/go-v1/developer-integration/error-handling.md).

## FAQ

> [accordion] Does deleting a journey session delete all customer data?
>
> No. It deletes the journey's data from the GBG Go API service only. To delete the journey session record, documents, and biometrics, use [Delete journey session](https://docs.go.gbgplc.com/docs/go-v1/platform/investigate/delete-journey-session.md) in the Investigation portal.

> [accordion] Can I delete a journey that's still in progress?
>
> No. You can delete only journeys with the status `Completed`, and you can't delete a journey that ended with the status `Error`. For any other journey, the API returns a `409` error.

> [accordion] Is it safe to retry a delete request?
>
> Yes, a retry has no extra effect. If the deletion has run, then the retry returns a `400` error with the identifier `journey-instance-not-found`. If the deletion hasn't run yet, then the retry returns `200` again.
>
> A `400` error doesn't prove that the deletion ran, because the API also returns it for an incorrect `instanceId`. To confirm the deletion, check that a delete request for this `instanceId` returned `200`, and that `/journey/state/fetch` for the same `instanceId` now returns an error.
