Purge Work Orders
curl --request POST \
--url https://agentgate.mynewapi.com/api/v1/work-orders/purge \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"statuses": [
{}
],
"olderThanDays": 123,
"dryRun": true
}
'import requests
url = "https://agentgate.mynewapi.com/api/v1/work-orders/purge"
payload = {
"statuses": [{}],
"olderThanDays": 123,
"dryRun": True
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({statuses: [{}], olderThanDays: 123, dryRun: true})
};
fetch('https://agentgate.mynewapi.com/api/v1/work-orders/purge', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://agentgate.mynewapi.com/api/v1/work-orders/purge",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'statuses' => [
[
]
],
'olderThanDays' => 123,
'dryRun' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://agentgate.mynewapi.com/api/v1/work-orders/purge"
payload := strings.NewReader("{\n \"statuses\": [\n {}\n ],\n \"olderThanDays\": 123,\n \"dryRun\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://agentgate.mynewapi.com/api/v1/work-orders/purge")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"statuses\": [\n {}\n ],\n \"olderThanDays\": 123,\n \"dryRun\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://agentgate.mynewapi.com/api/v1/work-orders/purge")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"statuses\": [\n {}\n ],\n \"olderThanDays\": 123,\n \"dryRun\": true\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"data": {
"deletedCount": 123,
"deletedIds": [
{}
],
"wouldDelete": 123
}
}Work Orders
Purge Work Orders
Bulk delete work orders by status and age criteria
POST
/
api
/
v1
/
work-orders
/
purge
Purge Work Orders
curl --request POST \
--url https://agentgate.mynewapi.com/api/v1/work-orders/purge \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"statuses": [
{}
],
"olderThanDays": 123,
"dryRun": true
}
'import requests
url = "https://agentgate.mynewapi.com/api/v1/work-orders/purge"
payload = {
"statuses": [{}],
"olderThanDays": 123,
"dryRun": True
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({statuses: [{}], olderThanDays: 123, dryRun: true})
};
fetch('https://agentgate.mynewapi.com/api/v1/work-orders/purge', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://agentgate.mynewapi.com/api/v1/work-orders/purge",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'statuses' => [
[
]
],
'olderThanDays' => 123,
'dryRun' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://agentgate.mynewapi.com/api/v1/work-orders/purge"
payload := strings.NewReader("{\n \"statuses\": [\n {}\n ],\n \"olderThanDays\": 123,\n \"dryRun\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://agentgate.mynewapi.com/api/v1/work-orders/purge")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"statuses\": [\n {}\n ],\n \"olderThanDays\": 123,\n \"dryRun\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://agentgate.mynewapi.com/api/v1/work-orders/purge")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"statuses\": [\n {}\n ],\n \"olderThanDays\": 123,\n \"dryRun\": true\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"data": {
"deletedCount": 123,
"deletedIds": [
{}
],
"wouldDelete": 123
}
}Purge Work Orders
Bulk deletes work orders matching specified criteria. Supports filtering by status and age, with a dry-run mode to preview deletions.Purged work orders and their associated runs are permanently deleted. This action cannot be undone.
Request
array
Filter by work order statuses. If omitted, applies to all statuses.
Valid values:
queued, running, waiting_for_children, integrating, succeeded, failed, cancelednumber
Only delete work orders older than this many days
boolean
default:"false"
If true, returns what would be deleted without actually deleting
curl -X POST https://agentgate.mynewapi.com/api/v1/work-orders/purge \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"statuses": ["failed", "canceled"],
"olderThanDays": 30,
"dryRun": false
}'
Dry Run Example
curl -X POST https://agentgate.mynewapi.com/api/v1/work-orders/purge \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"statuses": ["succeeded"],
"olderThanDays": 90,
"dryRun": true
}'
Response
boolean
required
Indicates if the request was successful
object
required
Example Responses
Actual Purge
{
"success": true,
"data": {
"deletedCount": 15,
"deletedIds": [
"wo_abc123",
"wo_def456",
"wo_ghi789",
"wo_jkl012",
"wo_mno345"
]
},
"requestId": "req_xyz789"
}
Dry Run
{
"success": true,
"data": {
"deletedCount": 0,
"deletedIds": [],
"wouldDelete": 42
},
"requestId": "req_xyz789"
}
No Matches
{
"success": true,
"data": {
"deletedCount": 0,
"deletedIds": []
},
"requestId": "req_xyz789"
}
Common Purge Patterns
Clean Up Old Failures
Delete failed work orders older than 7 days:curl -X POST https://agentgate.mynewapi.com/api/v1/work-orders/purge \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"statuses": ["failed"],
"olderThanDays": 7
}'
Archive Completed Work
Delete successful work orders older than 90 days:curl -X POST https://agentgate.mynewapi.com/api/v1/work-orders/purge \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"statuses": ["succeeded"],
"olderThanDays": 90
}'
Clean All Terminal States
Delete all completed (success, fail, cancel) work orders older than 30 days:curl -X POST https://agentgate.mynewapi.com/api/v1/work-orders/purge \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"statuses": ["succeeded", "failed", "canceled"],
"olderThanDays": 30
}'
Preview Before Delete
Always use dry run first to verify:# Step 1: Check what would be deleted
curl -X POST https://agentgate.mynewapi.com/api/v1/work-orders/purge \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"statuses": ["failed"],
"olderThanDays": 7,
"dryRun": true
}'
# Step 2: If results look correct, run actual purge
curl -X POST https://agentgate.mynewapi.com/api/v1/work-orders/purge \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"statuses": ["failed"],
"olderThanDays": 7,
"dryRun": false
}'
What Gets Deleted
When a work order is purged:- The work order record
- All associated runs
- All run audit records
- All iteration snapshots
Logs stored externally (e.g., in a log aggregation service) are not affected by purge.
Best Practices
Recommendations:
- Always use
dryRun: truefirst to preview deletions - Set up automated purge for old successful work orders
- Keep failed work orders longer for debugging
- Export important data before purging
Related
- List Work Orders - View work orders before purging
- Get Work Order - Check individual work order details