Inline vs. Stored Scripts

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

Inline Scripts are sent directly in the API request.
This method is ideal for quick tests or one-off executions.

Advantages

  • No need to save the script beforehand
  • Perfect for ad-hoc requests
  • Directly test HTML, templates, or logic

Disadvantages

  • Code must be sent with every request
  • Can become cumbersome for complex workflows

Example (PDF Generator)

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

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

  • Reusable for multiple requests
  • Code is centrally managed
  • Easier maintenance and versioning
  • Reduces request size

Disadvantages

  • Script must be saved in the platform first
  • Updating the script requires changes in the platform

Workflow in the CustomJS Platform

  1. Open the Code Editor in the CustomJS app.
  2. Create a new script and enter your code.
  3. Save the script and note the Script ID.
  4. Send API requests using the Script ID instead of the full code:
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.

CustomJS Code Editor
CustomJS Code Editor
HTML Template View
HTML Template View