Welcome

You can find the open API JSON file below.

Onedoc API endpoints

View the OpenAPI specification file

Authentication

All Onedoc API endpoints are authenticated using an API key and picked up from the request header.

"header": [
  {
    "x-api-key": "XXXX-XXXX-XXXX-XXXX-XXXX"
  }
]

Usage

Rendering a PDF with the Onedoc API takes 3 steps:

1

Initiate document rendering (Onedoc API)

This step creates a bucket with SignedUrls for each file your document needs to be rendered.

2

Upload your assets to their respective buckets using signedUrls (Supabase API)

This is when you load the bucket with all the necessary files. One API call should be made per file.

3

Generate your document (Onedoc API)

Onedoc renders your document from your loaded bucket!

1. Initiate document rendering

In order to render a document, intiate rendering with api/docs/initiate.
This step returns a list of signed bucket URLs to which you should upload your assets’ content. You should include:

  • an ìndex.html file that should include your bundled react code and/or raw html. All stylesheets or other asset imports should be done with relative paths. (MANDATORY)
  • stylesheets with a path matching the relative one in the ìndex.html (OPTIONAL)
  • all other assets such as images, logos etc. (OPTIONAL)
    Make sure all imports are relative and make sure they match the paths you provide in the request body.
    This query will return a list of SignedUrl, path, token triple.

2. Upload your assets to their respective buckets using signedUrls.

Then, upload all your assets to the paths you the specified in the intiate using the returned signed Urls. Uploading an asset using a signed URL consists in sending a PUT request with the token and the asset at {signedUrl}/object/upload/sign/{path}.
Below is a helper function to upload assets to a bucket using a signed Url for Node JS. This implementation is specific to supabase, specifically in our URL and path management.

async function uploadToSignedUrl(
  urlToFS: string,
  path: string,
  token: string,
  fileBody: FileBody,
  fileOptions?: any
) {
  const url = new URL(urlToFS + `/object/upload/sign/${path}`);
  url.searchParams.set("token", token);

try {
    let body;
    const options = { upsert: DEFAULT_FILE_OPTIONS.upsert, ...fileOptions };
    const headers: Record<string, string> = {
    ...{ "x-upsert": String(options.upsert as boolean) },
    };

    if (typeof Blob !== "undefined" && fileBody instanceof Blob) {
      body = new FormData();
      body.append("cacheControl", options.cacheControl as string);
      body.append("", fileBody);
    } else if (
      typeof FormData !== "undefined" &&
      fileBody instanceof FormData
    ) {
      body = fileBody;
      body.append("cacheControl", options.cacheControl as string);
    } else {
      body = fileBody;
      headers["cache-control"] = `max-age=${options.cacheControl}`;
      headers["content-type"] = options.contentType as string;
    }

    const res = await fetch(url.toString(), {
      method: "PUT",
      body: body as BodyInit,
      headers,
    });

    const data = await res.json();

    if (res.ok) {
      return {
        data: { path: path, fullPath: data.Key },
        error: null,
      };
    } else {
      const error = data;
      return { data: null, error };
    }

    } catch (error) {
    throw error;
    }
}

3. Generate your document by specifying your bucket identifier, auth and options.

You can generate your document using api/docs/generate. This step lets Onedoc know the bucket is loaded with the base html, assets (optionally) and that it is ready for rendering to .PDF. You the bucket, password and username are retrieved form the response of the first call to api/docs/initiate.