Invio dell’aggiornamento delle giacenze¶
Per inviare un aggiornamento giacenze/prezzo, viene utilizzato il seguente enpoint a cui l’aggiornamento deve essere inviato periodicamente:
https://merchants-connector-importer.zalandoapis.com/{Client ID}/{Stock File Name}
Richiesta HTTP¶
Metodo PUT
Parametri URL e header¶
Parametro | Tipo | Esempio |
---|---|---|
Client ID | String | d329krpq |
Stock File Name | CSV | 20181023_update.csv |
API Key (x-api-key) | String | lXViWTzFic9sM8Qqe9Ew7JME8xTdBAOMJHdIjK7XkjQ00OWr |
Requisiti (OBBLIGATORI)¶
La richiesta
- Deve essere una richiesta HTTP PUT.
- Deve contenere l’**ID cliente ** nella richiesta URL ({Client ID} deve essere sostituito). Esempio: d329krpq.
- Deve contenere il nome del file delle giacenze che sarà ricevuto ({Stock File Name} sarà sostituito), che potrebbe essere diverso dal nome del proprio file locale. Esempio: 20181023_update.csv
- Deve includere il file CSV delle giacenze..
- Deve contenere la chiave API negli header (nome dell’header:x-api-key). Esempio: lXViWTzFic9sM8Qqe9Ew7JME8xTdBAOMJHdIjK7XkjQ00OWr.
Negozi in paesi diversi
Se i clienti operano in paesi diversi, ogni paese avrà una chiave API e un ID cliente diversi e dovrà avere feed delle giacenze separati in base al paese.
Esempi di codice¶
Shell¶
curl -v -X PUT https://merchants-connector-importer.zalandoapis.com/d329krpq/20181023_update.csv
--upload-file 20181023_update.csv
--header "x-api-key: lXViWTzFic9sM8Qqe9Ew7JME8xTdBAOMJHdIjK7XkjQ00OWr"
Powershell¶
Invoke-WebRequest `
-UseBasicParsing `
-Uri https://merchants-connector-importer.zalandoapis.com/d329krpq/20181023_update.csv `
-Method PUT `
-InFile 20181023_update.csv `
-Headers @{'x-api-key'='lXViWTzFic9sM8Qqe9Ew7JME8xTdBAOMJHdIjK7XkjQ00OWr'}
Python¶
import requests
client_id = "d329krpq"
headers = {
'x-api-key': "lXViWTzFic9sM8Qqe9Ew7JME8xTdBAOMJHdIjK7XkjQ00OWr",
'content-type': "application/csv",
'cache-control': "no-cache"
}
with open('feed_data.csv', 'rb') as f:
res = requests.put(f"https://merchants-connector-importer.zalandoapis.com/{client_id}/20181023_update.csv".format(client_id=client_id), headers=headers, data=f.read())
if res.status_code == 200:
print("Success")
else:
print("Failed")
Nodejs¶
const axios = require('axios')
const fs = require('fs')
const clientId = "d329krpq"
const apiKey = "lXViWTzFic9sM8Qqe9Ew7JME8xTdBAOMJHdIjK7XkjQ00OWr"
const fileName = "file.csv"
const data = fs.createReadStream(fileName)
const url = `https://merchants-connector-importer.zalandoapis.com/${clientId}/${fileName}`
const config = {
headers: {
"content-type": "application/csv",
"x-api-key": apiKey,
"cache-control": "no-cache"
}
}
axios.put(url, data, config)
.then((response) => {
// handle success
console.log(response);
})
.catch((error) => {
// handle error
console.log(error);
})
Risposta¶
Response status of 200 (OK)
Se l’upload del file è andato a buon fine, lo stato della risposta sarà 200 (OK). A questo punto un processo in backend preleverà il file nel giro di poco tempo ed eseguirà gli aggiornamenti se il formato e la codifica del file sono corretti.