How to trigger an import with APIs

  • 21 December 2021
  • 0 replies
  • 649 views

Userlevel 4
Badge +2

Pigment allows users to automate their import process thanks to a generic API. In this article, you will find all the information you need on how to import your data using the Pigment Import API. 

 

Triggering an import 

 

To trigger an import from the Pigment Import API, you need two things:

  • Pigment API key: this secret key will be used to authenticate the service calling the API. Use the Integration page to get one.
  • Import configuration ID: this ID represents the import configuration. Check the Import configuration documentation to see how to generate one. 

An Import configuration ID in Pigment defines the destination of the file. It is dependent on the file you import and the destination within Pigment, kind of like the target path in a file server, with everything pre-configured.

 

Description

 

Here is the POST API URL : 

https://pigment.app/api/importservice/Csv/ApiPush/${CONFIGURATION_ID}

Add the CSV file in the request payload. 

To authenticate yourself to the API, there are two solutions:

  • using headers: add the Pigment API Key to the HTTP headers X-Pigment-Api-Key
  • using query string parameters: add the Pigment API Key as api_key

 

Note

Use the first option whenever possible. 

 

 

Examples

 

CURL example using HTTP headers:
 

# Template variables
export PIGMENT_API_KEY="CHANGE ME"
export CONFIGURATION_ID="CHANGE ME"
export FILE_PATH="CHANGE ME"

# Post the CSV
curl -X POST
"https://pigment.app/api/importservice/Csv/ApiPush/${P_ID}"CONFIGURATION\-H "X-Pigment-Api-Key: ${PIGMENT_API_KEY}"
\--data-binary "@/${FILE_PATH}"

 

CURL example using query string parameter:

# Template variables
export PIGMENT_API_KEY="CHANGE ME"
export CONFIGURATION_ID="CHANGE ME"
export FILE_PATH="CHANGE ME"

# Post the CSV
curl -X POST "https://pigment.app/api/importservice/Csv/ApiPush/${CONFIGURATION_ID}?api_key=${PIGMENT_API_KEY}"
\--data-binary "@/${FILE_PATH}"

 

Debug

 

Once you successfully submitted an import with this, it doesn't necessarily mean that the import has run successfully. To be sure, check the status of your last import in the “Update History” of your block. 

 

Note

The import will be displayed as if it was triggered by the person who saved the Import configuration.  

 

Click on the image to expand the view

 

If the import was not successful, you can check the "Import Summary" to get more information. 

 

Example:

 

Click on the image to expand the view

 

Do not hesitate to re-download the CSV as received by Pigment and try to reimport it manually to figure out whether the problem is related to the CSV input format or the saved Import configuration for the Import Configuration ID.

 

 


0 replies

Be the first to reply!

Reply