Skip to main content

I have an API that I call to extract certain pages from a PDF. The request seems to be ok. However I get a response in form-data back and I'm stock on how to process. 

< HTTP/1.1 200 OK
< Date: Tue, 01 Oct 2024 14:36:40 GMT
< Content-Type: application/pdf
< Content-Disposition: form-data; name="attachment"; filename="QUERO%20QUERO%201S24_rearranged.pdf"
< Content-Length: 518605

Now I fetch it with @document_data, but it needs treatment to be correct. The previewer cannot read it because probably the content-disposition header should be stripped?

Appears that the whole request isn't accepted. Please TW be a bit clear, or support form-data. I've read all the posts here, chat GPT and everything on google and I really don't  get it working. 

Please explain how I should set up the web connector to do the below API:

https://stirlingpdf.io/swagger-ui/index.html#/General/rearrangePages

I have the document and page range in the database. 


Hello @Freddy,

We do support multipart/form-data through Web connections.

So judging by their API docs, you’ll need to provide three multipart/form-data parameters to the request:

  • fileInput
  • pageNumbers
  • customMode

I'm assuming that fileInput and pageNumbers will require dynamic values and that customMode is an optional parameter that can typically be skipped. So we will need two input parameters on our Web connection:

 

Your endpoint configuration should look like this:

Again, I have not added a form field for the customMode parameter, because I'm assuming that it is optional.

Now you will need to supply values for the fileInput and pageNumbers parameters in the corresponding Web connection process action. To do this, you will need two process variables:

  • fileInput - This should be a VARCHAR(max) because the API docs state that the parameter is a binary string. I'm assuming that binary string means base64 encoded binary string, as this is typically how this works in APIs, but it's hard to be certain, the API docs are not clear.
  • pageNumbers - This should be something like VARCHAR(100) to allow for various page range expressions like ‘1, 2-5, 7, 8’.

These parameters can simply be hooked up to the input parameters of the Web connection process action.

Now you will most likely need a task that allows you to upload a PDF document and enter the page range. The easiest way to do this is to use a database file storage location on your task with a VARBINARY backing task parameter for the PDF upload. All that's left to do then is to convert the VARBINARY to a base64 string and assign it to the fileInput process variable. Which you can do like this:
declare @pdf_data varbinary(max);

SELECT CAST('' AS XML).value('xs:base64Binary(sql:variable("@pdf_data"))', 'VARCHAR(MAX)')

I think that this is how the request should be set up, can you check if this request is accepted by the web service? If so, then we can continue this topic on how you need to process the response. For that part it would be helpful to have an example of what the response looks like, as the API docs are extremely limited in this regard.

I hope this helps.


Thanks @Vincent Doppenberg, give me some time to actually test it and come back to you. 


Reply