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.
| Advantages | Disadvantages |
|---|---|
| No need to save the script beforehand | Code must be sent with every request |
| Perfect for ad-hoc requests | Can become cumbersome for complex workflows |
| Directly test HTML, templates, or logic |
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.
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
PDF file generated successfully: customjs-output.pdf
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.
| Advantages | Disadvantages |
|---|---|
| Reusable for multiple requests | Script must be saved in the platform first |
| Code is centrally managed | Updating the script requires changes in the platform |
| Easier maintenance and versioning | |
| Reduces request size |

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.

| Inline JavaScript | Stored JavaScript | |
|---|---|---|
| Implementation | Code is sent directly in the HTTP request body. | Functions are saved in CustomJS and referenced by ID. |
| Best for | Quick tests or dynamic, one-off executions. | Production use, versioning, and sharing logic across workflows. |
| Setup effort | Minimal: Write and run immediately. | Requires initial setup to save and reference functions. |
| Reusability | Limited: Code must be redefined each time. | High: Reusable across multiple workflows. |
| Maintainability | Harder to manage changes across uses. | Easier to update and maintain in one place. |