With the Magic URL feature, you can generate images or PDFs using your existing templates without writing any code. You can pass the data and options as query parameters in the URL and get the generated image or PDF.
And many more...
Before generating an image or PDF with a URL, you need to enable the Magic URL option for the template you want to use.
Visit the Templates page and click on the template you want to enable Magic URL for. Then, enable the Magic URL
option.
The URL structure is as follows:
https://render.markupgo.com/template/{templateId}.{extension}?{query}
templateId
: The ID of the template you want to use.extension
: The output format. Supported formats are png
, jpeg
, webp
, pdf
.You can use the "Copy Magic URL" button to copy the Magic URL directly to your clipboard.
json=true
query parameter to get the JSON response and return the task URL to the client-side.redirect=true
query parameter to get redirected to the generated image or PDF URL.options
: The Image or PDF options. Please see the Image Options and PDF Options sections.json=true
: If you want to get the JSON response instead of the image or PDF, you can pass the json
query parameter. The response will be equivalent to the Task object response. Please see the Task Object section. This is the best way to generate the URL on the server-side and pass the task URL to the client-side without exposing the generated image or PDF URL. Please see this example.redirect=true
: If you want to be redirected to the generated image or PDF URL (Task URL), you can pass the redirect
query parameter. The response will be a 302 redirect to the generated image or PDF URL. With this option, you can hide the initial URL from the end-user.context
field. Please see the Building the Magic URL section and Examples section for more details.MarkupGo uses the qs
library to parse query parameters. Please see the qs documentation for more information.
Here is the QS options that MarkupGo internally uses:
const QS_OPTIONS = {
arrayFormat: 'brackets'
};
Let's imagine your existing API request body is as follows.
{
"context": {
"episode": 1,
"title": "We talk about stuff and things, tune in!",
},
"options": {
"properties": {
"width": 1200,
"omitBackground": true
}
}
}
You don't need to define the context
suffix explicitly in the query parameters. As mentioned earlier, except for the options
field, all other fields will be considered as part of the context
field.
?title=We talk about stuff and things, tune in!
&episode=1
&options[properties][width]=1200
&options[properties][omitBackground]=true
Now, you can add this query to the URL.
https://render.markupgo.com/template/{YOUR_TEMPLATE_ID}.png?episode=1&title=We talk about stuff and things, tune in!&options[properties][width]=1300&options[properties][omitBackground]=true
That's it! You can use this URL to generate images or PDFs. Let's see some examples.
Here are some examples of how you can use the same template with different data and options.
<img src="https://render.markupgo.com/template/${YOUR_TEMPLATE_ID}.png?episode=1&title=We talk about stuff and things, tune in!" />
<img src="https://render.markupgo.com/template/${YOUR_TEMPLATE_ID}.png?episode=2&title=Rounding off from last time, let's talk about more stuff and things!" />
<img src="https://render.markupgo.com/template/${YOUR_TEMPLATE_ID}.png?episode=3&title=We're back again, discussing even more stuff and things!" />
<img src="https://render.markupgo.com/template/${YOUR_TEMPLATE_ID}.png?episode=4&title=Bonus Episode: We talk about even more stuff and things!" />
Let's use Magic URL with the json=true
query parameter to get the JSON response and return the task URL to the client-side.
The Magic URL:
https://render.markupgo.com/template/${YOUR_TEMPLATE_ID}.png?episode=5&title=Let's get json response and use the task URL&json=true
The Task Response:
{
"id": "66d301f42d9d3c58d27cdffd",
"url": "https://files.markupgo.com/tasks/66923f55c937bb8a3d73a1fb/1725104627341.png",
...
}
Now, let's use the task URL to render the image. 🚀