cancel
Showing results for 
Search instead for 
Did you mean: 

Post pdf product by api

Post pdf product by api

Hello,

 

I have a custom attribute named "fichier_pdf" for the products, I create the products with the api on c#, but to fill this field I can't upload the pdf, I found in the doc this : https://devdocs.magento.com/marketplace/eqp/v1/files.html, I tried like this : 

public String UploadFile(String file, bool selectOnUpload, bool startOnUpload)
{
System.Net.HttpStatusCode lastResultCode;
try
{
var request = new RestRequest("/rest/v1/files/uploads", Method.POST);
request.AddHeader("Content-Type", "multipart/form-data");
request.AddHeader("boudary", "NIQUE_BOUNDARY_TOKEN");
request.AddFile("file", file, "application/pdf");

if (selectOnUpload)
request.AddParameter("select", "true");

if (startOnUpload)
request.AddParameter("print", "true");

IRestResponse response = Client.Execute(request);
lastResultCode = response.StatusCode;
return response.Content;
}
catch (Exception ex)
{
lastResultCode = System.Net.HttpStatusCode.ExpectationFailed;

}
return null;
}

but it doesn't work, I have this error : "{"message":"Specified request cannot be processed."}". Do you have any ideas? I've looked and so far all the solutions I've tried don't work.

 

ps : the version of magento is Magento ver. 2.4.2