BulkDownload now returning errors
We have a customer who is using a script to download files we send to a shared folder on ShareFile. The script uses the Items/BulkDownload method to download all the files in the shared folder. They've been using the same script successfully since 2018. On 2/24/2023, they reported that they are getting errors when they run the script. I'd appreciate any tips anyone might have.The relevant Perl code is listed below. The error string returned by the $ua->request(POST ...) statement follows the code: my $url = $hostname . '/sf/v3/Items/BulkDownload?parentid=$parent_id&redirect=false'; my $ua = LWP::UserAgent->new; $ua->default_header('Authorization' => 'Bearer $access_token'); my $response = $ua->request(POST $url, [ '' => \\\\@file_ids ]); {'code':'UnsupportedMediaType','message':{'lang':'en-US','value':'Media type [application/x-www-form-urlencoded] not supported for the request.'},'reason':'Unspecified'}

  • Hi Daniel,   Overall, the update we rolled out starting on the 22nd just makes our platform a bit more strict on what's accepted(it also greatly increases the performance of our entire system). We should still be accepting anything that's properly called though. And if not, I'm here to make sure we get it addressed.    Here's an updated version of the example screenshot: https://citrix.sharefile.com/d-se5464f22783d498abb04f0c8a348b0aa   You can see the request URL I called at the very top in the grey box and outlined in red, which is https://subdomain/sf/v3/items(id)/BulkDownload?redirect=false.  Just below that in blue, you can see my body is formatted as raw JSON, with a body of ['fileid1','fileid2,'fileid3'] In Postman, the application I used to make that call, when selecting JSON as the body type it automatically adds the Content-Type=application/json header.    If you could upload a capture of the decrypted SSL traffic to the support ticket so we can see the request URL, headers, and body content then we can be confirm if my above suspicions are correct. But simply based on the error response it sure sounds like it's just the wrong Content-Type header.   For BulkDownload endpoint we're expecting a json body as shown in my screenshot, and that would require the Content-Type header to be set as application/json. If the Content-Type header is anything other than what we expect, then our system should reject it. So overall as long as you're using the header Content-Type=application/json then you shouldn't be receiving a response mentioning 'application/x-www-form-urlencoded'. Which is the main concern to address based on the original exception message posted. 
  • Kevin, I'm not able to make any sense of the example link you sent. I don't even see BulkDownload in any of the content from the example.   I've tried adding 'Content-Type' => 'application/json' to the request header using the default_header() attribute of LWP::UserAgent but this didn't result in any difference in the request stream captured by grinder TCPProxy.    I'm starting to think I'll need to use encode_json before submitting the POST request. This wasn't necessary before. Can you tell me what was changed with BuilkDownload API functionality on or around 24FEB that caused this to start failing?
  • Hi Daniel,   Thanks for posting your ticket number! I reviewed the case and advised the support rep accordingly. While reviewing the case I noticed that it looks like you may be using 'application/x-www-form-urlencoded' as your Content-Type when formatting the request. For the BulkDownload endpoint, you'll actually want to use 'application/json' and then include a body with a list of items to download in JSON format.    Here's an example: https://citrix.sharefile.com/d-s02003ee0e4914ca8a8fc7e6d3553acc9
  • Hi Kevin, I was able to reproduce the customer's issue at my site. This way I'll be able to work with Citrix Support directly. I've opened Citrix Case#81739791. Please make sure it gets routed to the right support team as it wasn't obvious which category to select in the input form. thanks, Dan Williams
  • Hi Kevin, Thanks for this idea. I suggested to the customer to try changing the url statement to this:my $url = $hostname . '/sf/v3/Items($parent_id)/BulkDownload?redirect=false'; He tried that but got the same error re UnsupportedMediaType.   Do you think the POST statement may be the problem?my $response = $ua->request(POST $url, [ '' => \\@file_ids ]);  
  • Hi Daniel,   Thanks for bringing this to our attention!   Taking a look at your code there seems to be a slight discrepancy in the request url path. Currently you have this: '/sf/v3/Items/BulkDownload?parentid=$parent_id&redirect=false'   And our system should be expecting something more like this :'/sf/v3/Items($parent_id)/BulkDownload?redirect=false' You can see documentation for the bulk download endpoint on the items page of our API site here: https://api.sharefile.com/docs/resource?name=Items   Let me know if you have any issues with the suggested URL path and we would be happy to further investigate.
This question is closed.