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.

Step

Data

Description

1

Load assets

Import 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.

2

Identify link target

Locate the target (document, classification, or variant) to which the asset will be associated.

3

Link assets

Link 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/assetsAPI v4 endpoint
HTTP MethodPOST
Request Body
Required AttributescodestringThe unique code of the asset.
media_urlstring 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 AttributesactivebooleanIf False, the asset becomes inactive and is unavailable via the interface.
{{_attribute_}}stringAny attribute code with its value(s) (e.g., description in the code example).
classification_codestringThe DAM classification code the asset should be placed into.
media_original_filenamestring 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:

Scenario

Solution

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
POST
Query Parameters
{{document_code}}stringThe unique code of the document.
HTTP MethodPOST
Query Parameters
{{code}}stringThe unique code of the classification.
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)