Skip to content

Commit 0f4afbc

Browse files
Closes #17243: Include example of image upload using REST API (#19330)
1 parent 37cfc50 commit 0f4afbc

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

docs/integrations/rest-api.md

+17
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,23 @@ http://netbox/api/dcim/sites/ \
568568
!!! note
569569
The bulk deletion of objects is an all-or-none operation, meaning that if NetBox fails to delete any of the specified objects (e.g. due a dependency by a related object), the entire operation will be aborted and none of the objects will be deleted.
570570

571+
## Uploading Files
572+
573+
As JSON does not support the inclusion of binary data, files cannot be uploaded using JSON-formatted API requests. Instead, we can use form data encoding to attach a local file.
574+
575+
For example, we can upload an image attachment using the `curl` command shown below. Note that the `@` signifies a local file on disk to be uploaded.
576+
577+
```no-highlight
578+
curl -X POST \
579+
-H "Authorization: Token $TOKEN" \
580+
-H "Accept: application/json; indent=4" \
581+
-F "object_type=dcim.site" \
582+
-F "object_id=2" \
583+
-F "name=attachment1.png" \
584+
-F "image=@local_file.png" \
585+
http://netbox/api/extras/image-attachments/
586+
```
587+
571588
## Authentication
572589

573590
The NetBox REST API primarily employs token-based authentication. For convenience, cookie-based authentication can also be used when navigating the browsable API.

0 commit comments

Comments
 (0)