Is automated upload of images (using an API request) possible?

Hi all, I wonder whether it is - or will be - possible to upload images (e.g., logos) using an API call. I can imagine two options:

  1. passing an image as a BLOB to a specific datafield. I’ve seen that there is an option in the Q&A to upload an image, which places the (binary) image data in a text-type datafield. Is something like this also possible when assembling a document using an API POST request?

  2. uploading an image in a specific folder, unrelated to the assembly of a specific document.

In other words: can using images in documents be automated?

Hi Darina,

I would need to double-check (never tried this before), but your first option should be possible indeed. Just try passing the B64 to the datafield in your API call.

The second one is not currently possible, because we don’t currently offer any clause-upload facilities or image-upload facilities. It could be added (internally everything uses a kind of API already, so it’s mostly a matter of exposing the internal API), but we haven’t had the question earlier.

Hi Maarten,

Thank you. I have tried that but so far without success. Here’s what I did:

  1. I saved the content of the image in base64 format in a variable:
    IMG="$(base64 logo.png)"
  2. I sent the request, feeding the variable into the corresponding datafields:
    curl -X POST "$KEY" -H "accept: application/pdf" -H "Content-Type: application/json" -d "{\"documentId\": 1033935, \"outputFormat\": \"pdf\", \"language\": \"en\", \"stringDataFields\": [{ \"fieldId\": 101394, \"value\": \"$IMG\", \"fieldName\": \"header-right\", \"conceptName\": \"image\"}, { \"fieldId\": 101391, \"value\": \"$IMG\", \"fieldName\": \"page-center\", \"conceptName\": \"image\" }]}"
  3. There are no parsing errors, but the returned document does not have the logo. Instead, it shows “(image not found)”.

How do I do this correctly?

Hi Darina,

I just tried with a random example, and it did seem to work correctly on my end.

Just a hunch, but

  • can you check whether your B64 image starts with the typical B64 MIME header (some “data:image/jpeg;base64,” if it’s a JPEG; “data:image/png;base64,” for a PNG)
  • you are wrapping the datafield in a @image(…), right?

This is my trivial example:

When not have an @image(…) wrapper:

With the wrapper:

Datafield settings:

Swagger (the entire value is obviously truncated for reasons of brevity!)

Hi Maarten,
It was the MIME header that was missing. I just needed to add it when converting the image to base64:
IMG="data:image/jpeg;base64,$(base64 logo.png)"

Thank you so much for you help, it works now.