Product synchronization via API allows you to automate the creation and updating of your Connectif catalog products from an external system. You can synchronize products individually or perform bulk updates using a CSV file.
In this article, you will learn how to automatically import products using the Connectif API.
Before you start: use cases
This API covers the following use cases:
- If you want to create or update products individually from an external system.
- If you want to periodically automate the synchronization of all or most of your products via a CSV file.
STEP 1. Create the API key
1. Go to Store Settings in the left-hand menu.
2. In the tab selector, go to "API and IP Access" and click on API Keys.
3. Click the Create new API Key button.
4. In the Imports and products section of the creation panel, enable the permissions for "Read", "Write", and "Delete" in bulk.
5. Save the API key and copy it to use later in your automation script.
STEP 2. Choose the synchronization method
(In this step, you will choose how to send product information to Connectif depending on the volume and how you need to update your catalog).
6. Choose the synchronization method that best fits your case:
- Products API: Create or update products individually.
- Imports API: Create or update large quantities of products using a CSV file.
2.1. Individual product synchronization
(In this section, you will configure calls to the Products API).
7. Create the automation script from your system and include the API Key generated in the previous step.
8. Configure an HTTP PATCH request in the script to create or update the product in Connectif: https://api.connectif.cloud/products/product-id/{id}
In the request, specify:
- The API Key to authenticate the call.
- The content type application/json.
- The product information in the request body.
9. Include the following mandatory attributes in the request body:
- name: product name.
- productDetailUrl: product detail URL, which must be accessible.
- unitPrice: unit price of the product.
Example 1
Once created, the request will look similar to this:
const apiKey = "YOUR_API_KEY";
const productId = "SKU-12345";
const url = `https://api.connectif.cloud/products/product-id/${productId}`;
const product = {
name: "Running Shoe",
productDetailUrl: "https://www.mydomain.com/products/SKU-12345",
unitPrice: 39.95
};
async function main() {
const response = await fetch(url, {
method: "PATCH",
headers: {
"Authorization": `apiKey ${apiKey}`,
"Content-Type": "application/json"
},
body: JSON.stringify(product)
});
const result = await response.json();
console.log(result);
}
main();
2.2. Bulk product synchronization
(In this section, you will configure an import via API to create or update products in bulk).
10. Create and verify that your import CSV file meets the following conditions:
- Use UTF-8 encoding.
- The first row contains the field headers.
- Product data must use the same field names indicated in this article.
productDetailUrl,productId,name,unitPrice,availability,inStockUnits,brand
https://www.mydomain.com/products/SKU-12345,SKU-12345,Running Shoe,39.95,instock,25,Example Brand
https://www.mydomain.com/products/SKU-67890,SKU-67890,Trail Shoe,49.95,outofstock,0,Example Brand11. Create the automation script from your system and include the API Key generated in STEP 1.
12. Configure an HTTP POST request in the script to the following endpoint: https://api.connectif.cloud/imports/
13. Configure the request with the necessary data to perform the import:
- Specify products as the import type.
- Specify the delimiter used in the CSV file.
- Set whether you want to overwrite existing product data.
- Set whether you want to update only fields that are empty.
- Include the CSV file containing the products you want to import.
14. Execute the request to start the import.
Example 2
Once created, the request will look similar to this:
const fetch = require('node-fetch');
const fs = require('fs');
const FormData = require('form-data');
const apiKey = process.env.API_KEY;
const filePath = process.env.FILE_PATH;
async function main() {
const form = new FormData();
form.append('type', 'products');
form.append('delimiter', ',');
form.append('overrideExisting', 'true');
form.append('updateOnlyEmptyFields', 'false');
form.append('file', fs.createReadStream(filePath));
const response = await fetch('https://api.connectif.cloud/imports', {
method: 'POST',
headers: {
'Authorization': `apiKey ${apiKey}`,
...form.getHeaders()
},
body: form
});
if (!response.ok) {
console.error(response.status, await response.json());
process.exit(1);
}
const { id, total } = await response.json();
while (true) {
const getResponse = await fetch(
`https://api.connectif.cloud/imports/${id}`,
{
method: 'GET',
headers: {
'Authorization': `apiKey ${apiKey}`
}
}
);
const { success, errors, status } = await getResponse.json();
console.log(`completed ${success + errors} of ${total}`);
if (status === 'finished') {
console.log('Success');
process.exit(0);
}
await new Promise(resolve = setTimeout(resolve, 2000));
}
}
main().catch(error = {
console.error(error);
process.exit(1);
});
The script creates a product import from the CSV file whose path is set via the FILE_PATH environment variable. It sets products as the import type, uses , as the delimiter, overwrites existing products, and keeps updateOnlyEmptyFields as false.
Frequently Asked Questions
Can I check imports performed via API from Connectif?
Yes, the import engine is the same used by the Connectif application. Therefore, you can view in the import list both those performed via API and those performed from Connectif.
How many imports can be queued at once?
You can queue up to 10 imports at once. When you reach this limit, you must wait for an import to complete before adding another to the queue.
What is the maximum size of the CSV file?
The CSV file can be up to 50 MB in size.
Can I delete an import via API?
Currently, it is possible to delete the import history only when in the finished or error states.
Can I cancel an import via API?
Once the file has been uploaded via the API, it is not possible to cancel.
Keep learning!
To take full advantage of your Connectif account, we recommend continuing with the following articles:
Bulk product synchronization, to learn how bulk synchronization works and the differences between Web Scraping and Product Feed.
Synchronization methods and product verification in Connectif, to learn the different ways to keep your catalog updated.
Product synchronization via Feed, to configure bulk synchronization using a Product Feed.
Product synchronization via Web Scraping, to configure bulk synchronization using Web Scraping.