Skip to content

Create or update asset links

POST
/stores/{storeRef}/assets/links
curl --request POST \
--url https://apibase.ecomweb.app/api/v1/stores/example/assets/links \
--header 'Content-Type: application/json' \
--header 'x-api-key: <x-api-key>' \
--data '{ "links": [ { "asset_id": "example", "entity_type": "product", "entity_id": "example", "field": "gallery", "sort_order": 0, "is_primary": false, "extra": {} } ] }'

Links assets to records. A link is identified by asset, record type, record ID and field: an existing link is updated, otherwise a new one is created. Every asset must belong to this store and every record must exist in it.

Required scopes: write:assets

storeRef
required
string

The store’s ref, as returned by GET /stores.

Media typeapplication/json
object
links
required

Array of asset links to create/upsert

Array<object>
object
asset_id
required

Asset ID to link

string
entity_type
required

Entity type

string
entity_id
required

Entity ID

string
field
required

Field name

string
sort_order

Sort order

number
0
is_primary

Is primary asset

boolean
extra

Extra metadata

object
Media typeapplication/json
object
links
required

The links that were created or updated.

Array<object>
object
extra
required

Extra data stored with the link, such as alt text.

object
key
additional properties
any
created_by
required

ID of the user who created the link. Null when it was created with an API key.

string
nullable
id
required

Link ID.

string
asset_id
required

ID of the linked asset.

string
entity_type
required

Type of the record the asset is linked to, such as product.

string
entity_id
required

ID of the record the asset is linked to.

string
field
required

The field of the record the asset fills, such as gallery or logo.

string
sort_order
required

Position among the record’s assets for that field.

number
is_primary
required

Whether this is the record’s primary asset.

boolean
created_at
required

When the link was created, as an ISO 8601 timestamp.

string
message
required

A readable confirmation.

string

Example generated

{
"links": [
{
"extra": {},
"created_by": "example",
"id": "example",
"asset_id": "example",
"entity_type": "example",
"entity_id": "example",
"field": "example",
"sort_order": 1,
"is_primary": true,
"created_at": "example"
}
],
"message": "example"
}

The request is malformed or failed validation.

Media typeapplication/json
One of:
object
statusCode
required

The HTTP status code.

number
message
required

What went wrong; validation failures list one message per problem.

One of:
string
error

The HTTP status text, such as Bad Request.

string

Example generated

{
"statusCode": 1,
"message": [
"example"
],
"error": "example"
}

The key is missing, invalid, revoked or expired.

Media typeapplication/json
One of:
object
statusCode
required

The HTTP status code.

number
message
required

What went wrong; validation failures list one message per problem.

One of:
string
error

The HTTP status text, such as Bad Request.

string

Example generated

{
"statusCode": 1,
"message": [
"example"
],
"error": "example"
}

The key may not do this: a missing scope, a readonly key, a publishable key on a Store API route, or a disallowed origin.

Media typeapplication/json
One of:
object
statusCode
required

The HTTP status code.

number
message
required

What went wrong; validation failures list one message per problem.

One of:
string
error

The HTTP status text, such as Bad Request.

string

Example generated

{
"statusCode": 1,
"message": [
"example"
],
"error": "example"
}

The resource does not exist in this store.

Media typeapplication/json
One of:
object
statusCode
required

The HTTP status code.

number
message
required

What went wrong; validation failures list one message per problem.

One of:
string
error

The HTTP status text, such as Bad Request.

string

Example generated

{
"statusCode": 1,
"message": [
"example"
],
"error": "example"
}