curl
This page contains instructions on how to use curl to interact with Amica APIs.
What is curl?
curl is a command-line tool and library for transferring data from or to a server using URLs. It supports a lot of protocols, HTTPS included. While its use can result non-immediately obvious to the non-initiated, it has been around since early days of computing and is supported on all kind of platforms.
Quoting the website:
curl is also used in cars, television sets, routers, printers, audio equipment, mobile phones, tablets, medical devices, settop boxes, computer games, media players and is the Internet transfer engine for thousands of software applications in over twenty billion installations. curl is used daily by virtually every Internet-using human on the globe.
curl is everywhere.
Using curl with Amica APIs
As you can infer from the URLs, in all the following examples the API version is
v2
and the company ID is set to 1
.
Authentication
curl -i --location 'https://adminws.amica20.it/api/v2/authenticate' \
--header 'X-Amica20-ApplicationId: curl' \
--header 'X-Amica20-ApiKey: 0e6f7b10-4de2-4140-a95f-c7f84ff5bd84' \
--header 'Content-Type: application/json' \
--data-raw '{
"UserName":"user",
"Password":"password"
}'
HTTP/1.1 200 OK
X-Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBY2NvdW50SWQiOiIxMiIsIkRhdGFCYXNlSWQiOiIxNyIsIkRhdGFCYXNlIjoiY2xpX2MyayIsIlJvbGUiOiJhZG1pbiIsIlN1YnNjcmlwdGlvbklkIjoic3ViX3Rlc3QiLCJuYmYiOjE2OTM0OTI3OTYsImV4cCI6MTY5NDA5NzU5NiwiaWF0IjoxNjkzNDkyNzk2fQ.f4saPMxtRsKvT1ufkR80rLI3QFtT-HbDrHoKkbICJ7w
The response's X-Token
header value is then used in authenticated requests (see below).
GET a stock item
curl -i -X GET --location 'https://customerws1.amica20.it/api/v2/1/articolo/1' \
-H 'X-Amica20-ApplicationId: curl' \
-H 'X-Amica20-ApiKey: 0e6f7b10-4de2-4140-a95f-c7f84ff5bd84' \
-H 'X-Amica20-LicenseKey: 0f96e4b7-998f-4d79-b3ab-6927a094580b' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
HTTP/1.1 200 OK
{"$id":"1","categoriaMerceologicaId":null,"categoriaMerceologica":null,"gruppoMerceologicoId":null,"gruppoMerceologico":null,"causaleIvaId":null,"causaleIva":null,"tagliaId":null,"taglia":null,"marcaId":null,"marca":null,"produttoreId":null,"produttore":null,"repartoId":null,"reparto":null,"nome":"Alveari per Scatole Medie","codice":"CELM","nomeBreve":"Alveari Scatole Medie","codiceFornitore":null,"codiceProduttore":null,"gestioneArticolo":"Standard","contestoArticolo":"Sempre","barCode":null,"costoUltimo":0.2,"costoMedio":0.2,"unitàMisuraIntera":false,"articoloComposto":false,"stato":true,"dataInserimento":"2005-01-11T00:00:00Z","unitàMisuraMovimenti":"N","unitàMisuraInventario":"N","fattoreConversioneUnitàMisura":1,"note":null,"mediaFile":null,"contoRawVendita":null,"contoRawAcquisto":null,"distintaBase":null,"id":1,"concurrencyToken":835853}
PUT a stock item (update)
curl -i -X PUT --location 'https://customerws.amica20.it/api/v2/1/articolo/1' \
-H 'X-Amica20-ApplicationId: curl' \
-H 'X-Amica20-ApiKey: 0e6f7b10-4de2-4140-a95f-c7f84ff5bd84' \
-H 'X-Amica20-LicenseKey: 0f96e4b7-998f-4d79-b3ab-6927a094580b' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
--data '{"categoriaMerceologicaId":null,"categoriaMerceologica":null,"gruppoMerceologicoId":null,"gruppoMerceologico":null,"causaleIvaId":null,"causaleIva":null,"tagliaId":null,"taglia":null,"marcaId":null,"marca":null,"produttoreId":null,"produttore":null,"repartoId":null,"reparto":null,"nome":"Alveari per Scatole Medie","codice":"CELM","nomeBreve":"Alveari Scatole Medie","codiceFornitore":null,"codiceProduttore":null,"gestioneArticolo":"Standard","contestoArticolo":"Sempre","barCode":null,"costoUltimo":0.2,"costoMedio":0.2,"unitàMisuraIntera":false,"articoloComposto":false,"stato":true,"dataInserimento":"2005-01-11T00:00:00Z","unitàMisuraMovimenti":"N","unitàMisuraInventario":"N","fattoreConversioneUnitàMisura":1,"note":null,"mediaFile":null,"contoRawVendita":null,"contoRawAcquisto":null,"distintaBase":null,"id":1,"concurrencyToken":835853}'
HTTP/1.1 200 OK
{"$id":"1","categoriaMerceologicaId":null,"categoriaMerceologica":null,"gruppoMerceologicoId":null,"gruppoMerceologico":null,"causaleIvaId":null,"causaleIva":null,"tagliaId":null,"taglia":null,"marcaId":null,"marca":null,"produttoreId":null,"produttore":null,"repartoId":null,"reparto":null,"nome":"Alveari per Scatole Medie","codice":"CELM","nomeBreve":"Alveari Scatole Medie","codiceFornitore":null,"codiceProduttore":null,"gestioneArticolo":"Standard","contestoArticolo":"Sempre","barCode":null,"costoUltimo":0.2,"costoMedio":0.2,"unitàMisuraIntera":false,"articoloComposto":false,"stato":true,"dataInserimento":"2005-01-11T00:00:00Z","unitàMisuraMovimenti":"N","unitàMisuraInventario":"N","fattoreConversioneUnitàMisura":1,"note":null,"mediaFile":null,"contoRawVendita":null,"contoRawAcquisto":null,"distintaBase":null,"id":1,"concurrencyToken":835854}
DELETE a stock item
curl -i -X DELETE --location 'https://customerws1.amica20.it/api/v2/1/articolo/1 \
-H 'X-Amica20-ApplicationId: curl' \
-H 'X-Amica20-ApiKey: 0e6f7b10-4de2-4140-a95f-c7f84ff5bd84' \
-H 'X-Amica20-LicenseKey: 0f96e4b7-998f-4d79-b3ab-6927a094580b' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
HTTP/1.1 204 No Content
POST a country (add)
curl -i --location 'https://customerws.amica20.it/api/v2/1/nazione' \
-H 'X-Amica20-ApplicationId: curl' \
-H 'X-Amica20-ApiKey: 0e6f7b10-4de2-4140-a95f-c7f84ff5bd84' \
-H 'X-Amica20-LicenseKey: 0f96e4b7-998f-4d79-b3ab-6927a094580b' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
--data '{ "nome": "Cina" }'
HTTP/1.1 201 Created
{"$id":"1","nome":"Cina","id":1176,"concurrencyToken":838276}
GET a list of countries (query)
curl -i -X GET --location 'https://testcustomerws.amica20.it/api/v2/2/nazione?filter=nome%20%24ct%20cina' \
-H 'X-Amica20-ApplicationId: curl' \
-H 'X-Amica20-ApiKey: 0e6f7b10-4de2-4140-a95f-c7f84ff5bd84' \
-H 'X-Amica20-LicenseKey: 0f96e4b7-998f-4d79-b3ab-6927a094580b' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
}'
HTTP/1.1 200 OK
{"$id":"1","$values":[{"$id":"2","nome":"Cina","id":1176,"concurrencyToken":838276}]}
Note
The query part of the URL (?filter=nome $eq cina
) must be escaped as ?filter=nome%20%24ct%20cina'
.