API Docs

CustomJS Functions

Welcome to the CustomJS API documentation! CustomJS provides a suite of powerful tools designed to simplify web automation and content manipulation. With our API, you can effortlessly convert HTML to PNGs or PDFs, merge multiple PDFs, capture website screenshots, and even run headless browser tasks using Puppeteer. Whether you're automating reports, generating documents, or performing advanced web interactions, CustomJS enables seamless integration with platforms like Zapier, making it easier than ever to enhance your workflows. This guide will walk you through each API method, offering detailed explanations and examples to help you get started quickly.


Authentication

This endpoint is used to authenticate a CustomJS account by verifying the provided API key. It allows clients to validate their credentials and gain access to workspace-level details and settings associated with the API key. Successful authentication enables further interaction with the CustomJS API.


This endpoint is essential for clients to confirm their credentials before accessing other CustomJS API functionalities.

Request

curl -X GET https://api.app.customjs.io/core/api-key/{api_key} \
-H "x-api-key: {api_key}"

Response

{
  "workspaceId": "string",
  "name": "string",
  "maxRequestCount": "number",
  "apiKeyData": {
    "value": "string",
    "id": "string"
  },
  "apiKey": "string",
  "timestamp": "number",
  "createdAt": "number",
  "jwt": {
    "at_hash": "string",
    "sub": "string",
    "email_verified": "boolean",
    "iss": "string",
    "cognito:username": "string",
    "origin_jti": "string",
    "aud": "string",
    "token_use": "string",
    "auth_time": "number",
    "userId": "string",
    "providerName": "string",
    "providerType": "string",
    "issuer": "string",
    "primary": "boolean",
    "jti": "string",
    "email": "string"
  },
  "dateCreated": "number",
  "userId": "string",
  "exp": "number",
  "iat": "number"
}



1: HTML to PDF

Request

curl -X POST https://e.customjs.io/__js1-{api_key} \
-H "customjs-origin: zapier/generatePDF" \
-H "Content-Type: application/json" \
-d '{
  "input": "<html><body><h1>Hello World!</h1></body></html>",
  "code": "const { HTML2PDF } = require(\"./utils\"); return HTML2PDF(input);",
  "returnBinary": "true"
}'

Response

The response contains the binary data of pdf file.



2: Merge PDFs

Request

curl -X POST https://e.customjs.io/__js1-{api_key} \
-H "customjs-origin: zapier/mergePDFs" \
-H "Content-Type: application/json" \
-d '{
  "input": ["https://example.com/file1.pdf", "https://example.com/file2.pdf"],  // URLs of the PDFs to merge
  "code": "const { PDF_MERGE } = require(\"./utils\"); const axios = require(\"axios\"); const pdfBuffers = await Promise.all(input.map(async file => { const res = await axios.get(file, { responseType: \"arraybuffer\" }); return Buffer.from(res.data).toString(\"base64\"); })); return PDF_MERGE(pdfBuffers);",
  "returnBinary": "true"
}'

Response

The response contains the binary data of pdf file.



3: Create Screenshot

Request

curl -X POST https://e.customjs.io/__js1-{api_key} \
-H "customjs-origin: zapier/screenshot" \
-H "Content-Type: application/json" \
-d '{
  "input": "https://example.com",  // The URL of the page to capture a screenshot of
  "code": "const { SCREENSHOT } = require(\"./utils\"); return SCREENSHOT(input);",
  "returnBinary": "true"
}'

Response

The response contains the binary data of the screenshot file.



4: HTML to PNG

Request

curl -X POST https://e.customjs.io/__js1-{api_key} \
-H "customjs-origin: zapier/generatePNG" \
-H "Content-Type: application/json" \
-d '{
  "input": "<html><body><h1>Hello World!</h1></body></html>",  // HTML content to convert to PNG
  "code": "const { HTML2PNG } = require(\"./utils\"); return HTML2PNG(input);",
  "returnBinary": "true"
}'

Response

The response contains the binary data of the png file.



5: Run puppeteer

Request

curl -X POST https://e.customjs.io/__js1-{api_key} \
-H "customjs-origin: zapier/puppeteer" \
-H "Content-Type: application/json" \
-d '{
  "input": "await page.goto(\"https://example.com\");",  // Puppeteer code to run
  "code": "const { PUPPETEER } = require(\"./utils\"); return PUPPETEER(input);",
  "returnBinary": "true"
}'

Response

The response contains the binary data of the png file.