|
| 1 | +# API Usage Examples |
| 2 | + |
| 3 | +## Creating a New Segment with Path Data (POST) |
| 4 | + |
| 5 | +Create a new segment with all required fields and upload path geometry from a file: |
| 6 | + |
| 7 | +```bash |
| 8 | +curl -X POST "http://localhost:8000/api/plugins/cesnet_service_path_plugin/segments/" \ |
| 9 | + -H "Authorization: Token YOUR_API_TOKEN" \ |
| 10 | + -F "name=Test Segment API" \ |
| 11 | + -F "status=active" \ |
| 12 | + -F "provider=32" \ |
| 13 | + -F "site_a=314" \ |
| 14 | + -F "location_a=387" \ |
| 15 | + -F "site_b=36" \ |
| 16 | + -F "location_b=24" \ |
| 17 | + -F "network_label=API-TEST-01" \ |
| 18 | + -F "provider_segment_id=API-TEST-SEGMENT-001" \ |
| 19 | + -F "provider_segment_name=Test Provider Segment" \ |
| 20 | + -F "provider_segment_contract=CONTRACT-2024-001" \ |
| 21 | + -F "path_file=@/path/to/your/segment_path.kmz" \ |
| 22 | + -F "path_notes=Path data uploaded via API" \ |
| 23 | + -F "install_date=2024-01-15" \ |
| 24 | + -F "termination_date=2024-12-31" |
| 25 | +``` |
| 26 | + |
| 27 | +**Supported file formats:** |
| 28 | +- GeoJSON files: `.geojson`, `.json` |
| 29 | +- KML files: `.kml` |
| 30 | +- KMZ files: `.kmz` |
| 31 | + |
| 32 | +## Updating an Existing Segment (PATCH) |
| 33 | + |
| 34 | +Update segment with ID 10 - you can update any combination of fields: |
| 35 | + |
| 36 | +### Update Path Data Only |
| 37 | +```bash |
| 38 | +curl -X PATCH "http://localhost:8000/api/plugins/cesnet_service_path_plugin/segments/10/" \ |
| 39 | + -H "Authorization: Token YOUR_API_TOKEN" \ |
| 40 | + -F "path_file=@/home/albert/cesnet/netbox/data/prubehy/segment_10_Mapa-Trasa.kmz" \ |
| 41 | + -F "path_notes=Updated path data via API" |
| 42 | +``` |
| 43 | + |
| 44 | +### Update Multiple Fields Including Path Data |
| 45 | +```bash |
| 46 | +curl -X PATCH "http://localhost:8000/api/plugins/cesnet_service_path_plugin/segments/10/" \ |
| 47 | + -H "Authorization: Token YOUR_API_TOKEN" \ |
| 48 | + -F "network_label=UPDATED-LABEL" \ |
| 49 | + -F "provider_segment_name=Updated Provider Name" \ |
| 50 | + -F "status=planned" \ |
| 51 | + -F "path_file=@/path/to/updated_path.geojson" \ |
| 52 | + -F "path_notes=Updated both metadata and path geometry" \ |
| 53 | + -F "termination_date=2025-06-30" |
| 54 | +``` |
| 55 | + |
| 56 | +## Important Notes |
| 57 | + |
| 58 | +1. **Authentication**: Replace `YOUR_API_TOKEN` with your actual NetBox API token |
| 59 | +2. **Content-Type**: Use `multipart/form-data` (automatic with `-F` flag) when uploading files |
| 60 | +3. **File Path**: Use absolute paths for the `path_file` parameter |
| 61 | +4. **Required Fields**: For POST requests, ensure all required fields are included: |
| 62 | + - `name`, `status`, `provider`, `site_a`, `location_a`, `site_b`, `location_b` |
| 63 | +5. **Field IDs**: Use numeric IDs for foreign key fields (provider, sites, locations) |
| 64 | +6. **Path Processing**: Files are automatically processed and geometry is calculated |
| 65 | +7. **Error Handling**: Invalid files will return detailed error messages |
| 66 | + |
| 67 | +## Response Example |
| 68 | + |
| 69 | +Successful upload will return the segment data with path information: |
| 70 | + |
| 71 | +```json |
| 72 | +{ |
| 73 | + "id": 10, |
| 74 | + "name": "Test Segment API", |
| 75 | + "status": "active", |
| 76 | + "path_length_km": "125.456", |
| 77 | + "path_source_format": "kmz", |
| 78 | + "path_notes": "Path data uploaded via API", |
| 79 | + "has_path_data": true, |
| 80 | + ... |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +## Getting Field IDs |
| 85 | + |
| 86 | +To find the correct IDs for providers, sites, and locations: |
| 87 | + |
| 88 | +```bash |
| 89 | +# List providers |
| 90 | +curl -H "Authorization: Token YOUR_API_TOKEN" \ |
| 91 | + "http://localhost:8000/api/circuits/providers/" |
| 92 | + |
| 93 | +# List sites |
| 94 | +curl -H "Authorization: Token YOUR_API_TOKEN" \ |
| 95 | + "http://localhost:8000/api/dcim/sites/" |
| 96 | + |
| 97 | +# List locations for a specific site |
| 98 | +curl -H "Authorization: Token YOUR_API_TOKEN" \ |
| 99 | + "http://localhost:8000/api/dcim/locations/?site_id=314" |
| 100 | +``` |
0 commit comments