Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/argo-smart-routing/api.md
1## API Reference23**Note on Smart Shield:** Argo Smart Routing is being integrated into Cloudflare's Smart Shield product. API endpoints remain stable; existing integrations continue to work without changes.45### Base Endpoint6```7https://api.cloudflare.com/client/v48```910### Authentication11Use API tokens with Zone:Argo Smart Routing:Edit permissions:1213```bash14# Headers required15X-Auth-Email: [email protected]16Authorization: Bearer YOUR_API_TOKEN17```1819### Get Argo Smart Routing Status2021**Endpoint:** `GET /zones/{zone_id}/argo/smart_routing`2223**Description:** Retrieves current Argo Smart Routing enablement status.2425**cURL Example:**26```bash27curl -X GET "https://api.cloudflare.com/client/v4/zones/{zone_id}/argo/smart_routing" \28-H "Authorization: Bearer YOUR_API_TOKEN" \29-H "Content-Type: application/json"30```3132**Response:**33```json34{35"result": {36"id": "smart_routing",37"value": "on",38"editable": true,39"modified_on": "2024-01-11T12:00:00Z"40},41"success": true,42"errors": [],43"messages": []44}45```4647**TypeScript SDK Example:**48```typescript49import Cloudflare from 'cloudflare';5051const client = new Cloudflare({52apiToken: process.env.CLOUDFLARE_API_TOKEN53});5455const status = await client.argo.smartRouting.get({ zone_id: 'your-zone-id' });56console.log(`Argo status: ${status.value}, editable: ${status.editable}`);57```5859**Python SDK Example:**60```python61from cloudflare import Cloudflare6263client = Cloudflare(api_token=os.environ.get('CLOUDFLARE_API_TOKEN'))6465status = client.argo.smart_routing.get(zone_id='your-zone-id')66print(f"Argo status: {status.value}, editable: {status.editable}")67```6869### Update Argo Smart Routing Status7071**Endpoint:** `PATCH /zones/{zone_id}/argo/smart_routing`7273**Description:** Enable or disable Argo Smart Routing for a zone.7475**Request Body:**76```json77{78"value": "on" // or "off"79}80```8182**cURL Example:**83```bash84curl -X PATCH "https://api.cloudflare.com/client/v4/zones/{zone_id}/argo/smart_routing" \85-H "Authorization: Bearer YOUR_API_TOKEN" \86-H "Content-Type: application/json" \87-d '{"value": "on"}'88```8990**TypeScript SDK Example:**91```typescript92const result = await client.argo.smartRouting.edit({93zone_id: 'your-zone-id',94value: 'on',95});96console.log(`Updated: ${result.value} at ${result.modified_on}`);97```9899**Python SDK Example:**100```python101result = client.argo.smart_routing.edit(102zone_id='your-zone-id',103value='on'104)105print(f"Updated: {result.value} at {result.modified_on}")106```107108## Checking Editability Before Updates109110**Critical:** Always check the `editable` field before attempting to enable/disable Argo. When `editable: false`, the zone has restrictions (billing not configured, insufficient permissions, or plan limitations).111112**Pattern:**113```typescript114async function safelyEnableArgo(client: Cloudflare, zoneId: string): Promise<boolean> {115const status = await client.argo.smartRouting.get({ zone_id: zoneId });116117if (!status.editable) {118console.error('Cannot modify Argo: editable=false (check billing/permissions)');119return false;120}121122if (status.value === 'on') {123console.log('Argo already enabled');124return true;125}126127await client.argo.smartRouting.edit({ zone_id: zoneId, value: 'on' });128console.log('Argo enabled successfully');129return true;130}131```132133**Python Pattern:**134```python135def safely_enable_argo(client: Cloudflare, zone_id: str) -> bool:136status = client.argo.smart_routing.get(zone_id=zone_id)137138if not status.editable:139print('Cannot modify Argo: editable=false (check billing/permissions)')140return False141142if status.value == 'on':143print('Argo already enabled')144return True145146client.argo.smart_routing.edit(zone_id=zone_id, value='on')147print('Argo enabled successfully')148return True149```150151## Error Handling152153The TypeScript SDK provides typed error classes for robust error handling:154155```typescript156import Cloudflare from 'cloudflare';157import { APIError, APIConnectionError, RateLimitError } from 'cloudflare';158159async function enableArgoWithErrorHandling(client: Cloudflare, zoneId: string) {160try {161const result = await client.argo.smartRouting.edit({162zone_id: zoneId,163value: 'on',164});165return result;166} catch (error) {167if (error instanceof RateLimitError) {168console.error('Rate limited. Retry after:', error.response?.headers.get('retry-after'));169// Implement exponential backoff170} else if (error instanceof APIError) {171console.error('API error:', error.status, error.message);172if (error.status === 403) {173console.error('Permission denied - check API token scopes');174} else if (error.status === 400) {175console.error('Bad request - verify zone_id and payload');176}177} else if (error instanceof APIConnectionError) {178console.error('Connection failed:', error.message);179// Retry with exponential backoff180} else {181console.error('Unexpected error:', error);182}183throw error;184}185}186```187188**Python Error Handling:**189```python190from cloudflare import Cloudflare, APIError, RateLimitError191192def enable_argo_with_error_handling(client: Cloudflare, zone_id: str):193try:194result = client.argo.smart_routing.edit(zone_id=zone_id, value='on')195return result196except RateLimitError as e:197print(f"Rate limited. Retry after: {e.response.headers.get('retry-after')}")198raise199except APIError as e:200print(f"API error: {e.status} - {e.message}")201if e.status == 403:202print('Permission denied - check API token scopes')203elif e.status == 400:204print('Bad request - verify zone_id and payload')205raise206except Exception as e:207print(f"Unexpected error: {e}")208raise209```210211## Response Schema212213All Argo Smart Routing API responses follow this structure:214215```typescript216interface ArgoSmartRoutingResponse {217result: {218id: 'smart_routing';219value: 'on' | 'off';220editable: boolean;221modified_on: string; // ISO 8601 timestamp222};223success: boolean;224errors: Array<{225code: number;226message: string;227}>;228messages: Array<string>;229}230```231232## Key Response Fields233234| Field | Type | Description |235|-------|------|-------------|236| `value` | `"on" \| "off"` | Current enablement status |237| `editable` | `boolean` | Whether changes are allowed (check before PATCH) |238| `modified_on` | `string` | ISO timestamp of last modification |239| `success` | `boolean` | Whether request succeeded |240| `errors` | `Array` | Error details if `success: false`