Assets- Import

👍

Objective

This cookbook describes how to import and link your assets in three easy steps.

500

Process Overview

Importing your assets into Quable PIM is a multistep process . There are several factors that impact the quality of your data, such as dependencies and hierarchy. This is why importing your assets must be done in a specific order.

StepDataDescription
1Load assetsImport each asset into the PIM. Before you can link your assets to a target (document, classification, or variant), the asset must already exist in Quable PIM.
2Identify link targetLocate the target (document, classification, or variant) to which the asset will be associated.
3Link assetsLink your assets to the identified target(s).

👍

In some cases, you only need to perform the first step:

  • Using Quable PIM's rule engine (Administration > System > Automatic links), you can automatically link your assets to a specific document based on the file name.

  • Importing assets without creating links.

Use Case

A photo studio has placed assets on a server (e.g., FTP). The name of each asset contains:

  • the code of a reference document and
  • a position number to define the order of the reference document's assets within the same link type (e.g., "MYDOC_video_03.mp4").

In order to import them, you'll need to go through the list of assets and take the following steps for each one:

  1. Load the asset into Quable PIM (via URL or Binary File)
  2. Query Quable PIM to:
    • verify if the reference document exists, and
    • determine if the assets are already linked to it
  3. Create or delete links accordingly

Load Assets

Quable PIM API provides two methods to import your assets:

via URL

To create a new asset in Quable PIM, you must include the asset's code and URL.

URL Parameters
Endpoint /assets API v4 endpoint
HTTP Method POST
Request Body
Required Attributes code string The unique code of the asset.
media_url string The URL to the server where the asset is located.

Note: If you don't want to update the binary file, this attribute can be omitted.
Accepted Attributes active boolean If False, the asset becomes inactive and is unavailable via the interface.
{{_attribute_}} string Any attribute code with its value(s) (e.g., description in the code example).
classification_code string The DAM classification code the asset should be placed into.
media_original_filename string The original name of the asset file.

Note: If this attribute is not provided, the asset's filename will be derived from the URL.

Example

import requests
url= "https://{{YOUR-PIM}}.quable.com.quable.com/api_1.php/assets"
payload= {
    "code": "suede_shoe__jpg__01",
    "media_url" : "https://domain.tld/.../suede_shoe__jpg__01.jpg",
    "media_original_filename" : "suede_shoe__jpg__01.jpg",
    "description" : "lorem ipsum"
}
headers= {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer ...'
}
response= requests.request("POST", url, headers=headers, data=payload)

via Binary File

To import data from a binary file, a form based request must be used. The following example uses cURL but any other method can be used.

Request Parameters
Endpoint/assetsAPI v4 endpoint
HTTP MethodPOST-i includes the HTTP headers in the output
-X identifies the method to use
Form Data
Required AttributescodestringThe unique code of the asset.
filestringThe name of the binary file.

Example

curl -i -X POST \
   -H "Authorization:Bearer ..." \
   -H "Content-Type:multipart/form-data" \
   -F "file=@\"/assets/new/suede_shoe__jpg__01.jpg\";type=image/png;filename=\"/suede_shoe__jpg__01.jpg\"" \
   -F "code=suede_shoe__jpg__01" \
 'https://{{YOUR-PIM}}.quable.com/api_1.php/assets'

Identify Link Targets

Once your assets have been uploaded, you need to link them to the correct targets (documents, classifications or variants). The following sections describe how to identify document, classification, and variant targets.

Documents

URL Parameters
Endpoint/api/documents/{{id}}

Note: {{id}} is the unique code of the document to update.

API v5 endpoint
HTTP MethodGET
Query Parameters
Required AttributesidstringThe unique code of the document.
Accepted AttributesdocumentType.idstringThe unique code of the document type.

Example

import requests
url = "https://{{YOUR-PIM}}.quable.com.quable.com/api/documents?id=suede_shoe&documentType.id=Reference"
headers = {
  'Content-Type': 'application/hal+json',
  'Authorization': 'Bearer ...'
}
response = requests.request("POST", url, headers=headers, data=payload)

Response Body

The response body contains all of the details for the reference document. In particular, the assetLinks array contains all of the links between the document and existing assets.

You only need to check:

📘

If nothing matches the document's id, an HTTP 404 Not Found error code is returned.

  • if an asset is linked to the document for the required link type and
  • the position (sequence number) of the asset.

At this point, you have three options:

ScenarioSolution
The asset is already linked at the correct position (aka sequence).There is nothing more to do.
Another asset is linked at the desired position.
  • The existing link is deleted and a new link with the new asset can be created.

    OR

  • The existing link is kept and a new link is created for the new asset.

No asset is linked or the position is incorrect.A link with the new asset must be created.
{
    "hydra:member": [{
        "id": "suede_shoe",
        "active": true,
        "attributes": {...},
        "documentType": {
            "default": false,
            "id": "Reference"
        },
        "attributeSet": null,
        "classifications": [...],
        "documentLinks": [...],
        "assetLinks": [{
            "linkType": {
                "id": "article_images_media"
            },
            "origin": {
                "id": "suede_shoe"
            },
            "target": {
                "id": "suede_shoe__jpg__01"
            },
            "sequence": 1,
            "id": "e5924756-513c-4b0f-8866-8d36262f5914"
        }],
        "workflows": [],
        "tags": [],
        "completenesses": {...},
        "variants": [...]
    }],
    "hydra:totalItems": 1,
    ...
}

Classifications

URL Parameters
Endpoint/api/classification/{{id}}

Note: {{id}} is the unique code of the classification to update.
API v5 endpoint
HTTP MethodGET
Query Parameters
Required AttributesidstringThe unique code of the classification.

Variants

URL Parameters
Endpoint/api/variants/{{id}}

Note: {{id}} is the unique code of the variant to update.
API v5 endpoint
HTTP MethodGET
Query Parameters
Required AttributesidstringThe unique code of the variant.

Link assets

You can link your assets to:

👍

For complete instructions about adding links, see 5. Import links in the Import from ERP cookbook.

Documents

To create a link between documents and assets, you must include the document's code, the link type's code, and define the link's mode (behavior).

URL Parameters
Endpoint/documents/{{document_code}}/links/{{link_type_code}}API v4 endpoint
HTTP MethodPOST
Query Parameters
{{document_code}}stringThe unique code of the document.
{{link_type_code}}stringThe unique code of the document - asset link type.
Request Body
Required Attributesitemsarray(objects) Array of objects to link. Each object is composed of a:

  • sequence - The asset's position within the link.
  • target_code - The unique code of the asset to link.
mode stringYou must choose one of the following two behaviors:

  • update - Default. Add the supplied elements to the document's existing links on the given link type.

  • replace - Replace all of the document's existing links on the given link type.

Example

import requests
import json
url= "https://{{YOUR-PIM}}.quable.com.quable.com/api_1.php/documents/suede_shoe/links/videos"
payload= {
    "mode" : "update", // or replace
    "items": [{
        "sequence" : 1,
        "target_code" : "asset_video_tour_mp4"
    },{
        "sequence" : 8,
        "target_code" : "asset_video_mini-tour_mp4"
    }]
}
headers= {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer ...'
}
response= requests.request("POST", url, headers=headers, data=json.dumps(payload))

Classifications

For complete instructions about adding links, see 5. Import links.

  • link_type_code must be the unique code of a LinkType defined between classifications and assets.
  • target_code must be the unique code for the new asset you've created.
URL Parameters
Endpoint/classifications/{{code}}/links/{{link_type_code}}API v4 endpoint
HTTP MethodPOST
Query Parameters
{{code}}stringThe unique code of the classification.
{{link_type_code}}stringThe unique code of the link type between the classification and the asset.
Request Body
Required Attributesitemsarray(objects) Array of objects to link. Each object is composed of a:

  • sequence - The asset's position within the link.
  • target_code - The unique code of the asset to link.
mode stringYou must choose one of the following two behaviors:

  • update - Default. Add the supplied elements to the classification's existing links on the given link type.

  • replace - Replace all of the classifications's existing links on the given link type.

Variants

For complete instructions about adding links, see 5. Import links.

  • link_type_code must be the unique code of a LinkType defined between classifications and assets.
  • target_code must be the unique code for the new asset you've created.

Delete Assets

It may become necessary at some point to delete an asset from Quable PIM.

To delete an asset, you must identify the asset's unique code.

URL Parameters
Endpoint/api_1/assets/{{code}}

Note: {{code}} is the unique code of the asset to delete.
API v4 endpoint
HTTP MethodDELETE
Query Parameters
Required AttributescodestringThe unique code of the asset.
import requests
url = "https://{{YOUR-PIM}}.quable.com.quable.com/api_1.php/assets/suede_shoe__jpg__01"
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer 883ae3ca7d90f91542227dc8d0d38b46'
}
response = requests.request("DELETE", url, headers=headers)