Source: https://datafa.st/docs/api-delete-goal
Markdown source: https://datafa.st/docs/api-delete-goal.md
Description: Delete custom goal events by visitor, name, or time range.

# Delete goals

`DELETE https://datafa.st/api/v1/goals`

Delete custom goal events by visitor ID, event name, or within a time range. Requires [Bearer Token](/docs/api-introduction) authentication.

## Query Parameters

### Filter Parameters (Optional - at least one required if no time range)

- **`datafast_visitor_id`** (optional): Delete goals for a specific visitor
- **`name`** (optional): Delete goals with a specific event name (e.g., `signup`, `purchase`)
  - Will be auto-formatted to lowercase with underscores

### Time Range Parameters (Optional)

- **`startAt`** (optional): ISO 8601 timestamp (e.g., `2023-01-01T00:00:00Z`)
- **`endAt`** (optional): ISO 8601 timestamp (e.g., `2023-01-31T23:59:59Z`)

**⚠️ WARNING:** When using `datafast_visitor_id` or `name` WITHOUT time range, ALL matching records across all time will be deleted.

## Deletion Behavior

- **With time range only:** Deletes all goals in the specified time range
- **With visitor ID only:** Deletes all goals for that visitor (across all time)
- **With name only:** Deletes all goals with that name (across all time)
- **With visitor ID + name:** Deletes goals matching both criteria
- **With time range + filters:** Deletes goals matching the filters within the time range

## Response

- **Success (200 OK):** Returns confirmation of deletion.
- **Errors:** 400 if parameters are invalid, 404 if not found.

## Code examples

### Example request (Delete by name within time range)

```bash
curl -X DELETE "https://datafa.st/api/v1/goals?name=signup&startAt=2023-01-01T00:00:00Z&endAt=2023-01-31T23:59:59Z" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

### Success response

```json
{
  "status": "success",
  "data": [{
    "message": "Goal events deleted successfully within time range",
    "goal_name": "signup",
    "timeRange": {
      "start": "2023-01-01T00:00:00.000Z",
      "end": "2023-01-31T23:59:59.000Z"
    }
  }]
}
```
