rest api: article update with csv

669 views Asked by At

i want to use the rest api for updating my articles with a csv file.

the manual apdate recoding to this link here works: https://developers.shopware.com/developers-guide/rest-api/examples/batch/

but how can i load my csv file?

i only fount the links below, which are al little bit older: https://forum.shopware.com/discussion/11727/api-artikel-import-mit-csv-datei https://forum.shopware.com/discussion/15796/lagerbestand-abgleich-csv-mit-hilfe-von-api

$api = Shopware()->Api(); 
...
$data_path = $api->load("http://www.XXXXXX.de/import/test.csv";

this doesn't work in shopware 5

1

There are 1 answers

0
wheeler On

First of all the Rest API is an API which has to be called by URL with parameters. You cannot instanciate it within you PHP code directly. It is used if you want to have another software connect to shopware.

In you case there is another way. You can use the Resources that the API internally also uses.

$manger = new \Shopware\Components\Api\Manager();   
$resource = $manger->getResource('Article');
foreach ($csvRows as $row){
   // create an array for the csv > article mapping
   $data = [];
   $data['name'] = $row['csv_row_name'];
   // do all mappings into the data array
   // ....
   // create the article from that array    
   $article = $resource->create($data);
} 

In this documentation you can see which fields are required in the $data array to successfully create an article https://developers.shopware.com/developers-guide/rest-api/api-resource-article/