Jump to content

Add attachments to products via webservice


Recommended Posts

Hello,

I have prestashop 1.7.7.2 and I am developing an api in C # to communicate with the store. I want to add attachments (* .pdf) to my products. From the backend I see that they can be uploaded. But I have not seen any resource in the webservice to be able to access and upload those files and attach them to my products. I also do not see that the products have any XML tag to be able to upload it. I have something implemented very similar to uploading the images but I don't know what url to send the raw pdf to be saved.

 

Any ideas ?, I hope I have explained myself well.

Edited by warrios96 (see edit history)
Link to comment
Share on other sites

  • 2 months later...
  • 5 weeks later...

Hello, did anyone manage to upload the attachments in 1.7.8? i try curl, i get code 200, no attachment

My code:

url = 'http://xxxxxx/api/attachments/';
$key  = 'xxxxxx';
$args['file'] = new CurlFile($att_path);
$args['file_name'] = 'file_name';
$args['mime'] = 'image/jpeg';
$args['name'] = 'name';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, $key.':');
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch);
curl_close($ch);

 

Edited by sebma
Add code (see edit history)
Link to comment
Share on other sites

  • 8 months later...

Hello in 1.7.8

In the class: /classes/webservice/WebserviceSpecificManagementAttachments.php

 * Examples:
     * [GET] https://domain.tld/api/attachments/ give a response in XML/json with all attachments.
     * [POST] https://domain.tld/api/attachments/ only creates model information (similar to any other default api), no file information.
     * [POST] https://domain.tld/api/attachments/file creates an attachment AND uploads a file for it.
     *
     * [PUT] https://domain.tld/api/attachments/$id_attachment here urlSegment[1] is id_attachment, updates model information only.
     * [PUT] https://domain.tld/api/attachments/file/$id_attachment here urlSegment[1] is 'file' and urlSegment[2] is id_attachment, updates file (binary) only.
     *
     * [GET] https://domain.tld/api/attachments/$id_attachment gives a response in XML/json for the attachment model information.
     * [GET] https://domain.tld/api/attachments/file/$id_attachment downloads the id_attachment file

 

So the curl is this one:

curl -v -X POST  --form '[email protected]'  'https://WSKEY@HOST/api/attachments/file' > xml2.xml

And you get the info in the xml.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...