Add Downloads to an article through the API - External File

Hi together,

I want to add downloads to an article through the API. Looking at the API, it should be easy, but somehow there is no file added to the article altough the API returns a HTTP: 200. Furthermore the file is on an external server and should be available then on the local server.

Here is my code

//Getting the article ID by ordernumber
$data = $client->get(‘articles/’.$arr[‘ordernumb’].’?useNumberAsId=true’);    

if($data[‘httpcode’] == 200){
        $a = array(‘downloads’ => $arr[‘downloads’]);
        $response = $client->put(‘articles/’.$data[‘data’][‘id’], array($a));
}

$a looks like "
Array ( [downloads] =>
        Array ( [name] => Name 
                    [file] => http://path/file.pdf )
)"

I already looked over here (german Forum), but this does not help.
https://forum.shopware.com/discussion/25589/artikel-per-api-eine-download-datei-zuweisen?

Can you help me how I can achieve my goal?

Hallo @dschu87‍,

what you must to do is add the file url in ‘link’ key not in ‘file’ key, so you array must look like:

Array ( [downloads] =>
        Array ( [name] => Name 
                    [link] => http://path/file.pdf )
)"

if you want to use a file that you have already in your Shopware media manager , then your array must be like this :

Array ( [downloads] =>
        Array ( [name] => Name 
                    [id] => 3 // media id 
             )
)"

VG,

Tel.: +49 755 - 183 990 00 | Email: info@enbit.de | Web: http://enbit.de/

Thank you for your reply with the link! That’s what I was looking for. I tried this also out but finally I found out, that I also built a wrong array (I had an array to less in „downloads“). Now it’s working like I want it to work!

Hallo @dschu87‍,

with link must work, I just notice somthing in your code:

        $response = $client->put('articles/'.$data['data']['id'], array($a));

why you have this extra array around $a, you must send the request like this

        $response = $client->put('articles/'.$data['data']['id'],$a);

try it and let me know.

VG,

Tel.: +49 755 - 183 990 00 | Email: info@enbit.de | Web: http://enbit.de/