/
Upload new product

Upload new product

In this example, we want to import the product 'Wallpaper'.

import requests import json def get_product_type_code(): url_get_product_type = 'https://pim-client.wizart.ai/api/v2.1/import/product-types' headers = { 'Authorization': access_token } response = requests.get(url_get_product_type, headers=headers) if response.status_code == 200: get_product_types = requests.get(url_get_product_type, headers=headers) product_types = json.loads(get_product_types.content.decode('utf8').replace("'", '"')) for each_product_type in product_types['data']: if each_product_type['attributes']['name'] == 'Wallpaper': wallpaper_code = each_product_type['attributes']['code'] else: print(f"Error: {response.status_code} - {response.text}") return wallpaper_code product_code = get_product_type_code() def get_default_csv(): url_default_csv = f'https://pim-client.wizart.ai/api/v2.1/data-mappings/default/{product_code}' headers = { 'Authorization': access_token } response = requests.get(url_default_csv, headers=headers) if response.status_code == 200: get_default_csv = requests.get(url_default_csv, headers=headers) default_csv = get_default_csv.content.decode("utf-8") csv_columns = default_csv.split(',') else: print(f"Error: {response.status_code} - {response.text}") return csv_columns empty_csv_file = get_default_csv() def transform_custom_data_to_pim_csv(): #the process where you transform columns from your data storage into a format required for loading into a PIM system. #to merge columns, use the obtained empty_csv_file with all the relevant columns required for loading into the PIM system. return csv_data_for_import def import_to_pim(): url = f'https://pim-client.wizart.ai/api/v2.1/product-type/{product_code}/import' headers = { 'Authorization': access_token } files = { 'data': open('/path/to/file', 'rb'), 'archive': open('/path/to/file', 'rb') } response = requests.post(url, headers=headers, files=files) import_to_pim()
  1. The get_product_type_code() function retrieves the product type code for a specific product type (in this case, 'Wallpaper') from the PIM system. It sends a GET request to the /import/product-types endpoint, using the provided access_token for authorization. If the request is successful, the product types are obtained from the response, and the code for the 'Wallpaper' product type is extracted.

  2. The get_default_csv() function retrieves the default CSV mapping for the product type identified by product_code. It sends a GET request to the /data-mappings/default/{product_code} endpoint, again using the access_token. If the request is successful, the default CSV content is obtained from the response and split into individual columns.

  3. The transform_custom_data_to_pim_csv() function is a placeholder that represents the process of transforming columns from your data storage into the format required for loading into the PIM system. It mentions merging the columns using the empty_csv_file obtained from the get_default_csv() function. The actual implementation of this transformation process is not provided in the code.

  4. The import_to_pim() function performs the actual import of data to the PIM system. It sends a POST request to the /product-type/{product_code}/import endpoint, including the access_token in the headers and files to be uploaded (data and archive). The file paths should be updated accordingly.

  5. The import_to_pim() function is called at the end to initiate the data import process to the PIM system.

Related content

Upload new product to the PIM
Upload new product to the PIM
More like this
Get imports list by product type
Get imports list by product type
More like this
Update product in the PIM
Update product in the PIM
More like this
Update PIM product
More like this