Create or update asset links
const url = 'https://apibase.ecomweb.app/api/v1/stores/example/assets/links';const options = { method: 'POST', headers: {'x-api-key': '<x-api-key>', 'Content-Type': 'application/json'}, body: '{"links":[{"asset_id":"example","entity_type":"product","entity_id":"example","field":"gallery","sort_order":0,"is_primary":false,"extra":{}}]}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}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
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”The store’s ref, as returned by GET /stores.
Request Bodyrequired
Section titled “Request Bodyrequired”object
Array of asset links to create/upsert
object
Asset ID to link
Entity type
Entity ID
Field name
Sort order
Is primary asset
Extra metadata
object
Responses
Section titled “Responses”object
The links that were created or updated.
object
Extra data stored with the link, such as alt text.
object
ID of the user who created the link. Null when it was created with an API key.
Link ID.
ID of the linked asset.
Type of the record the asset is linked to, such as product.
ID of the record the asset is linked to.
The field of the record the asset fills, such as gallery or logo.
Position among the record’s assets for that field.
Whether this is the record’s primary asset.
When the link was created, as an ISO 8601 timestamp.
A readable confirmation.
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.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}The key is missing, invalid, revoked or expired.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
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.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}The resource does not exist in this store.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}