Search…
API Reference
Resources
Create an attachment
How to create an attachment via API
To create a new attachment, send a POST request to the /api/attachments endpoint, passing the resource arguments in the request body.

Request

POST https://yourdomain.commercelayer.io/api/attachments

Arguments

Body Parameter
Type
Required
type
string
Required
attributes.name
string
Required
attributes.description
string
Optional
attributes.url
string
Optional
attributes.reference
string
Optional
attributes.reference_origin
string
Optional
attributes.metadata
object
Optional
relationships.attachable
object
Required

Example

Request
Response
The following request creates a new attachment:
1
curl -g -X POST \
2
'https://yourdomain.commercelayer.io/api/attachments' \
3
-H 'Accept: application/vnd.api+json' \
4
-H 'Authorization: Bearer your-access-token' \
5
-H 'Content-Type: application/vnd.api+json' \
6
-d '{
7
"data": {
8
"type": "attachments",
9
"attributes": {
10
"name": "DDT transport document"
11
},
12
"relationships": {
13
"attachable": {
14
"data": {
15
"type": "attachables",
16
"id": "QWERtyUpBa"
17
}
18
}
19
}
20
}
21
}'
Copied!
On success, the API responds with a 201 Created status code, returning the created resource object:
1
{
2
"data": {
3
"id": "xYZkjABcde",
4
"type": "attachments",
5
"links": {
6
"self": "https://yourdomain.commercelayer.io/api/attachments/xYZkjABcde"
7
},
8
"attributes": {
9
"name": "DDT transport document",
10
"description": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
11
"url": "https://s3.yourdomain.com/attachment.pdf",
12
"created_at": "2018-01-01T12:00:00.000Z",
13
"updated_at": "2018-01-01T12:00:00.000Z",
14
"reference": "ANY-EXTERNAL-REFEFERNCE",
15
"reference_origin": "ANY-EXTERNAL-REFEFERNCE-ORIGIN",
16
"metadata": {
17
"foo": "bar"
18
}
19
},
20
"relationships": {
21
"attachable": {
22
"links": {
23
"self": "https://yourdomain.commercelayer.io/api/attachments/xYZkjABcde/relationships/attachable",
24
"related": "https://yourdomain.commercelayer.io/api/attachments/xYZkjABcde/attachable"
25
}
26
}
27
},
28
"meta": {
29
"mode": "test"
30
}
31
}
32
}
Copied!
Last modified 2mo ago
Copy link