Using an existing import profile
In order to launch a new CSV Import with API using an existing import profile, you will need to get your profileId and to know the path to the file to import
import requests
import json
url = "https://_SUBDOMAIN_.quable.com/api/imports"
payload = json.dumps({
"importProfileId": "xxx-xxx-xxxx-xxxx-xxx-xxx",
"remotePath": "sftp://host.com:2222/quable/myfile.csv"
})
headers = {
'Content-Type': 'application/hal+json',
'Authorization': 'Bearer _BEARER_'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
Without import profile
In order to launch a new CSV Import with API without using an existing import profile, you will need the provide the informations relative to the import usually hold by the import profile, and to know the path to the file to import
url = "https://_SUBDOMAIN_.quable.com/api/imports"
payload = json.dumps({
"importProfile": {
"extension": "csv",
"model": "document.document_type",
"dateFormat|dateTimeSeparator"...
},
"fileId": "xxx-xxx-xxxx-xxxx-xxx-xxx"
})
headers = {
'Content-Type': 'application/hal+json',
'Authorization' : 'Bearer _BEARER_'
}
response = requests.request("POST", url, headers=headers, data=payload)
Retrieve import status
In order to get the 30 last import process, here is an example
import requests
url = "https://_SUBDOMAIN_.quable.com/api/processes?type=import&page=1&limit=30&order%5BdateCreated%5D=asc&order%5BendDate%5D=desc"
payload={}
headers = {
'Content-Type': 'application/hal+json',
'Authorization': 'Bearer _BEARER_'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
First part of the first ressource in the response body could be like this.
Take a look at status, metadata.count, metadata.report
[
{
"id": "c57b7057-56a2-4710-8c48-e45fa4aa4d9a",
"type": "import",
"status": "finished",
"documentType": "classification",
"metadata": {
"importProfile": {
"name": "ERP - Categories",
"model": "classification",
"description": "",
"locales": [
"en_GB",
"es_ES",
"fr_FR"
],
"mappings": [],
"endOfLine": "\\n",
"encoding": "UTF-8",
"emptyValueStrategy": "ignore",
"dateFormat": "DD/MM/YYYY",
"dateTimeSeparator": "%20",
"enclosure": "\\\"",
"fieldSeparator": ";",
"multiValueSeparator": "|",
"numberFormat": ".",
"timeFormat": "hh:mm:ss",
"extension": "csv"
},
"count": {
"blocs": 1,
"duplicates": 0,
"errors": 2,
"items": 222,
"lines": 222
},
"report": {
"info": 220,
"error": 20,
"status": "error"
}
}
Second part of the first ressource in the response body could be like this.
Take a look at the files.id while filtering on type:import
This fileId will be used to download the CSV file that have been imported
"files": [
{
"id": "4604b202-c7f2-430d-969c-bcd06d6502ca",
"status": "available",
"type": "import",
"isDownloadable": true
},
{
"id": "a47fb9d4-1f69-4dbc-8c15-3f7c8cda437d",
"status": "available",
"type": "import_report",
"isDownloadable": true
}
],
"dateCreated": "2021-02-16T15:56:41+00:00",
"startDate": "2021-02-16T15:56:41+00:00",
"endDate": "2021-02-16T15:57:20+00:00"
Let's download the source file
The following call will return the CSV content.
import requests
url = "https://_SUBDOMAIN_.quable.com/api/files/YOUR-FILE-ID/download"
payload={}
headers = {
'Content-Type': 'application/hal+json',
'Authorization': 'Bearer _BEARER_'
}
response = requests.request("GET", url, headers=headers, data=payload)