Main Image Relationship

post
Create a Main Image Relationship

https://api.moltin.com/v2/products/:productId/relationships/main-image
Create a Product relationship to a single File, which can be used as a main_image. You can only have one main image relationship.
Request
Response
Path Parameters
productId
required
string
The ID of the product you wish to relate to the image.
Headers
Authorization
required
string
The Bearer token used to access the API.
Body Parameters
data[].type
required
string
Represents the type of the object (should be main_image).
data[].id
required
string
The ID of the image.
200: OK
{
"data": [
{
"type": "main_image",
"id": "8df7738-febe-4987-bc0e-b857297b30e9"
}
]
}
cURL
JavaScript SDK
curl -X "POST" https://api.moltin.com/v2/products/:productId/relationships/main-image \
-H "Authorization: Bearer XXXX" \
-H "Content-Type: application/json" \
-d $'{
"data": {
"type": "main_image",
"id": "98df7738-febe-4987-bc0e-b857297b30e9"
}
}'
const MoltinGateway = require('@moltin/sdk').gateway
const Moltin = MoltinGateway({
client_id: 'X',
client_secret: 'X'
})
const productId = 'XXXX'
const imageIds = [
'e9737dc6-876a-4eab-b3b7-af62a1999123'
]
Moltin.Products.CreateRelationships(productId, 'main-image', imageIds).then((relationships) => {
// Do something
})

put
Update a Main Image Relationship

https://api.moltin.com/v2/products/:productId/relationships/main-image
Update the main image relationship. This will replace any currently related image.
Request
Response
Path Parameters
productId
required
string
The ID of the product you wish to relate to the image.
Headers
Authorization
required
string
The Bearer token used to access the API.
Body Parameters
data[].type
required
string
Represents the type of object (should be main_image)
data[].id
required
string
The ID of the image.
200: OK
{
"data": [
{
"type": "main_image",
"id": "e9737dc6-876a-4eab-b3b7-af62a1999123"
}
]
}
cURL
JavaScript SDK
curl -X "PUT" https://api.moltin.com/v2/products/:productId/relationships/main-image \
-H "Authorization: Bearer XXXX" \
-H "Content-Type: application/json" \
-d $'{
"data": {
"type": "main_image",
"id": "e9737dc6-876a-4eab-b3b7-af62a1999123"
}
}'
const MoltinGateway = require('@moltin/sdk').gateway
const Moltin = MoltinGateway({
client_id: 'X',
client_secret: 'X'
})
const productId = 'XXXX'
const imageIds = [
'e9737dc6-876a-4eab-b3b7-af62a1999123'
]
Moltin.Products.UpdateRelationships(productId, 'main-image', imageIds).then((relationships) => {
// Do something
})

delete
Delete a Main Image Relationship

https://api.moltin.com/v2/products/:productId/relationships/main-image
Delete the main image relationship. This will remove the related main image.
Request
Response
Path Parameters
productId
required
string
The ID of the product you wish to remove the relationship for.
Headers
Authorization
required
string
The Bearer token used to access the API.
Body Parameters
data[].type
required
string
Represents the type of object (should be main_image).
data[].id
required
string
The ID of the image.
200: OK
cURL
JavaScript SDK
curl -X "DELETE" https://api.moltin.com/v2/products/:productId/relationships/main-image \
-H "Authorization: Bearer XXXX" \
-H "Content-Type: application/json" \
-d $'{
"data": {
"type": "main_image",
"id": "e9737dc6-876a-4eab-b3b7-af62a1999123"
}
}'
const MoltinGateway = require('@moltin/sdk').gateway
const Moltin = MoltinGateway({
client_id: 'X',
client_secret: 'X'
})
const productId = 'XXXX'
const imageIds = [
'e9737dc6-876a-4eab-b3b7-af62a1999123'
]
Moltin.Products.DeleteRelationships(productId, 'main-image', imageIds).then((relationships) => {
// Do something
})