CSV-Datei hochladen über APICall

We need to upload a CSV file to update our catalogs from PlentyMarkets to Mirakl.

Is it possible to upload a CSV file with API Call in Synastry?

Because we have not succeeded so far.

We have the following error:

Last message: Step APICall: HTTP status code error: 400 (Bad Request)

In requestBody we have:

file = filename: $ {autoFilename}

import_mode = NORMAL

We can do it in Postman and with Curl on our server, but we would like to use Synesty.


Thanks for any help

Could you post an example how to do it with curl (anonymized with example data is fine)? Then we could check how to translate that to Synesty.

Hello,


Here is some of my code:


  $ postFields = array (
      'file' => new CurlFile ('/ var / www / update.csv', 'text / csv', 'update.csv'),
      'import_mode' => 'NORMAL'
  );



    CURLOPT_URL => "https://www.myUrl.com/api/imports",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => $ postFields,
    CURLOPT_HTTPHEADER => array (
      "Authorization: myKey",

    )

Could you post your curl request to a tool like requestbin and provide us with a Screenshot? You can anonymize the screenshot. For us it is important, how the request and especially the csv-content looks like when you do it with your php-curl.

Hello,


Here is the screenshots.


Thanks for your help.

Ok, thanks.

We could not resemble your request completely, but we have something which might work.

Could you try to use the URLDownload step instead. It has a fileToUpload input which you could pass the file directly.


The request looks a little bit different than yours, but maybe you are lucky and your API accepts it.

Let us know about the result. If it is not working, we can look into it again. Maybe we need to make an addition. We will talk to development once we got your response.





Hello,

I still have an error:

Last message: Step UrlDownload: HTTP status code error: 400 (Bad Request) (Explanation: Origin of this error: Caused by the remote side e.g. another server, API or webservice. Kind of error: Something could not be accessed (e.g. a server, a url or a file). Affected Parameters: {url=https://MyUrl.com/api/offers/imports?api_key=MyKey})

Just to make sure this is the step I used:


1) Add step UrlDownload

Host:
https://www.MyURL_CSV_file_from_PlentyMarket 

method:
GET

filename:
update.csv

2) Add step UrlDownload

host:https://MyUrl.com/api/offers/imports?api_key=MyKey

method:
POST

requestBody:
import_mode=normal

fileToUpload:
Uses file from step 1 UrlDownload

bodyContentType:
application/x-www-form-urlencoded; charset=ISO-8859-1

I have tried about 20 different configuration but no luck.


Ok, thanks for getting back to us.

It seems the remote server does not understand the request.

It seems that currently this is not possible to achieve this with URLDownload step.


The reason are probably 2 things:

  • it is currently not possible to name the 'file' parameter in your CURL example. URLDownload automatically names it 'upfile'
  • also the additional request parameters are not recognized.


At the moment there is nothing you can do about it.


We have opened a ticket with development and will investigate what options we have.


Thanks for taking the time to report back to us.

We will get back to us during the next week when somebody had a chance to look into it.



Quick update.

We deployed a fix for the POST request, so that your other parameter import_mode=normal is transmitted correctly.

It might be possible that it helps in your case, but probably not, because the file-parameter name is still hardcoded to 'upfile'.

So please retry and let us know. But probably it will still not work.


We are still working on another fix, to make the file-parameter-name configurable. Unfortunatelly this is a bigger change (sounds small, but affects a lot of other places).

We will keep you updated about this fix too.


Hi,


Thank you very much, I will try and I'll let you know.


Thanks

Hi,

I have tried with both UrlDownload and APICalI, I confirm that still not work.

I'm waiting for the other fix to see if it works.


Thanks

Ok thanks for the feedback.

There is a fix scheduled for beginning of next week, where you can specify the parametername of the uploaded file.

We hope this is the last missing piece in the puzzle to solve your problem.

Hi,


Thank you very much, we're looking forward for this.


Regards,


Nicolas

Ok, we have deployed the extension for URLDownload and APICall, so that you can specify the filename:





Can you please try again?

Please also show us the test result from requestbin.



Hello,


I did a test yesterday and I had an error, but today I tried again and everything works perfectly. I don't know if something was changed today.


I think this a great add on for Synesty, because there is more and more platforms using this method.


Do you still need the test result from requestbin?


Thank you very much.

Thanks for the feedback. Glad that it works for you now.
No we don't need the requestbin result anymore.