CustomJS offers two ways to execute JavaScript code for processing data or generating PDFs: Inline Scripts and Stored Scripts. Both methods have advantages depending on your use case.
Inline Scripts are sent directly in the API request.
This method is ideal for quick tests or one-off executions.
curl -X POST 'https://e.customjs.io/__js1-YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-H 'customjs-origin: inline/pdf-generator' \
--data-raw '{"input":{"html":"<h1>Hello World</h1>"},"code":"const { HTML2PDF } = require(\"./utils\"); return HTML2PDF(input.html);","returnBinary":"true"}' \
> customjs-output.pdf
In this example, an HTML string is passed via input.html
and converted into a PDF.
The JavaScript code is sent inline with the request.
Stored Scripts are saved once in the CustomJS platform and can be reused multiple times.
This is ideal for recurring workflows or more complex scripts.
curl -X POST 'https://e.customjs.io/5CbuoC' -H 'Content-Type: application/json' -H 'x-api-key: YOU_API_KEY' -d '{
"Users": "[{\"name\":\"John\", \"lastName\": \"Doe\"}, {\"name\":\"Luke\", \"lastName\": \"Freeman\"}]"
}'
This approach sends only the input data, while the stored script executes the logic on the platform.