> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.staple.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.staple.ai/_mcp/server.

# Generate PDF Document with JSON format

POST https://api.staple.io/v2/supernova/models/document/create
Content-Type: application/json

Generate PDF documents based on input JSON data. The endpoint supports pre-configured formats and only specific data can go into each PDF document.

Reference: https://docs.staple.ai/api-reference/v2/document-creation/generate-pdf-document-with-json-format

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: v2
  version: 1.0.0
paths:
  /v2/supernova/models/document/create:
    post:
      operationId: generatePdfDocumentWithJsonFormat
      summary: Generate PDF Document with JSON format
      description: >-
        Generate PDF documents based on input JSON data. The endpoint supports
        pre-configured formats and only specific data can go into each PDF
        document.
      tags:
        - documentCreation
      parameters:
        - name: x-api-key
          in: header
          description: API key issued by Staple.
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/Document
                  Creation_generatePdfDocumentWithJsonFormat_Response_200
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                qid:
                  type: integer
                data:
                  $ref: >-
                    #/components/schemas/V2SupernovaModelsDocumentCreatePostRequestBodyContentApplicationJsonSchemaData
servers:
  - url: https://api.staple.io
    description: https://api.staple.io
components:
  schemas:
    V2SupernovaModelsDocumentCreatePostRequestBodyContentApplicationJsonSchemaDataTablesItems:
      type: object
      properties:
        headers:
          type: array
          items:
            type: string
        standardheader:
          type: array
          items:
            type: string
        rows:
          type: array
          items:
            type: array
            items:
              type: string
        table_format:
          type: integer
        table_name:
          type: string
        table_type:
          type: string
      title: >-
        V2SupernovaModelsDocumentCreatePostRequestBodyContentApplicationJsonSchemaDataTablesItems
    V2SupernovaModelsDocumentCreatePostRequestBodyContentApplicationJsonSchemaData:
      type: object
      properties:
        Address:
          type: array
          items:
            type: string
        Currency:
          type: array
          items:
            type: string
        Date:
          type: array
          items:
            type: string
        PO:
          type: array
          items:
            type: string
        Supplier:
          type: array
          items:
            type: string
        Vendor:
          type: array
          items:
            type: string
        Contact:
          type: array
          items:
            type: string
        tables:
          type: array
          items:
            $ref: >-
              #/components/schemas/V2SupernovaModelsDocumentCreatePostRequestBodyContentApplicationJsonSchemaDataTablesItems
      title: >-
        V2SupernovaModelsDocumentCreatePostRequestBodyContentApplicationJsonSchemaData
    Document Creation_generatePdfDocumentWithJsonFormat_Response_200:
      type: object
      properties: {}
      description: Empty response body
      title: Document Creation_generatePdfDocumentWithJsonFormat_Response_200
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: API key issued by Staple.
    bearerAuth:
      type: http
      scheme: bearer
      description: JWT obtained from the login endpoint.

```

## Examples

### Generate PDF Document with JSON format



**Request**

```json
undefined
```

**Response**

```json
{
  "createDocument": {
    "message": "Document creation request has been accepted.",
    "requestId": "5a359a65-f380-4822-8936-81e86005c669"
  }
}
```

**SDK Code**

```python Generate PDF Document with JSON format
import requests

url = "https://api.staple.io/v2/supernova/models/document/create"

headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, headers=headers)

print(response.json())
```

```javascript Generate PDF Document with JSON format
const url = 'https://api.staple.io/v2/supernova/models/document/create';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: undefined
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Generate PDF Document with JSON format
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.staple.io/v2/supernova/models/document/create"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Generate PDF Document with JSON format
require 'uri'
require 'net/http'

url = URI("https://api.staple.io/v2/supernova/models/document/create")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'

response = http.request(request)
puts response.read_body
```

```java Generate PDF Document with JSON format
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.staple.io/v2/supernova/models/document/create")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .asString();
```

```php Generate PDF Document with JSON format
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.staple.io/v2/supernova/models/document/create', [
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Generate PDF Document with JSON format
using RestSharp;

var client = new RestClient("https://api.staple.io/v2/supernova/models/document/create");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
IRestResponse response = client.Execute(request);
```

```swift Generate PDF Document with JSON format
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.staple.io/v2/supernova/models/document/create")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Document Creation_generatePdfDocumentWithJsonFormat_example



**Request**

```json
{
  "name": "01",
  "qid": 1,
  "data": {
    "Address": [
      "1500",
      "2000"
    ],
    "Currency": [
      "SGD"
    ],
    "Date": [
      "1200"
    ],
    "PO": [
      "800"
    ],
    "Supplier": [
      ""
    ],
    "Vendor": [
      ""
    ],
    "Contact": [
      "DA foods"
    ],
    "tables": [
      {
        "headers": [
          "Description",
          "Quantity",
          "UOM",
          "Unit Amount",
          "Line Amount"
        ],
        "standardheader": [
          "Description",
          "Quantity",
          "UOM",
          "Unit Amount",
          "Line Amount"
        ],
        "rows": [
          [
            "a2",
            "3",
            "PCS",
            "5",
            "15"
          ],
          [
            "b2",
            "3",
            "PCS",
            "3",
            "9"
          ],
          [
            "c2",
            "4",
            "PCS",
            "5",
            "20"
          ]
        ],
        "table_format": 1,
        "table_name": "table",
        "table_type": "default"
      }
    ]
  }
}
```

**Response**

```json
{
  "createDocument": {
    "message": "Document creation request has been accepted.",
    "requestId": "5a359a65-f380-4822-8936-81e86005c669"
  }
}
```

**SDK Code**

```python Document Creation_generatePdfDocumentWithJsonFormat_example
import requests

url = "https://api.staple.io/v2/supernova/models/document/create"

payload = {
    "name": "01",
    "qid": 1,
    "data": {
        "Address": ["1500", "2000"],
        "Currency": ["SGD"],
        "Date": ["1200"],
        "PO": ["800"],
        "Supplier": [""],
        "Vendor": [""],
        "Contact": ["DA foods"],
        "tables": [
            {
                "headers": ["Description", "Quantity", "UOM", "Unit Amount", "Line Amount"],
                "standardheader": ["Description", "Quantity", "UOM", "Unit Amount", "Line Amount"],
                "rows": [["a2", "3", "PCS", "5", "15"], ["b2", "3", "PCS", "3", "9"], ["c2", "4", "PCS", "5", "20"]],
                "table_format": 1,
                "table_name": "table",
                "table_type": "default"
            }
        ]
    }
}
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Document Creation_generatePdfDocumentWithJsonFormat_example
const url = 'https://api.staple.io/v2/supernova/models/document/create';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"name":"01","qid":1,"data":{"Address":["1500","2000"],"Currency":["SGD"],"Date":["1200"],"PO":["800"],"Supplier":[""],"Vendor":[""],"Contact":["DA foods"],"tables":[{"headers":["Description","Quantity","UOM","Unit Amount","Line Amount"],"standardheader":["Description","Quantity","UOM","Unit Amount","Line Amount"],"rows":[["a2","3","PCS","5","15"],["b2","3","PCS","3","9"],["c2","4","PCS","5","20"]],"table_format":1,"table_name":"table","table_type":"default"}]}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Document Creation_generatePdfDocumentWithJsonFormat_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.staple.io/v2/supernova/models/document/create"

	payload := strings.NewReader("{\n  \"name\": \"01\",\n  \"qid\": 1,\n  \"data\": {\n    \"Address\": [\n      \"1500\",\n      \"2000\"\n    ],\n    \"Currency\": [\n      \"SGD\"\n    ],\n    \"Date\": [\n      \"1200\"\n    ],\n    \"PO\": [\n      \"800\"\n    ],\n    \"Supplier\": [\n      \"\"\n    ],\n    \"Vendor\": [\n      \"\"\n    ],\n    \"Contact\": [\n      \"DA foods\"\n    ],\n    \"tables\": [\n      {\n        \"headers\": [\n          \"Description\",\n          \"Quantity\",\n          \"UOM\",\n          \"Unit Amount\",\n          \"Line Amount\"\n        ],\n        \"standardheader\": [\n          \"Description\",\n          \"Quantity\",\n          \"UOM\",\n          \"Unit Amount\",\n          \"Line Amount\"\n        ],\n        \"rows\": [\n          [\n            \"a2\",\n            \"3\",\n            \"PCS\",\n            \"5\",\n            \"15\"\n          ],\n          [\n            \"b2\",\n            \"3\",\n            \"PCS\",\n            \"3\",\n            \"9\"\n          ],\n          [\n            \"c2\",\n            \"4\",\n            \"PCS\",\n            \"5\",\n            \"20\"\n          ]\n        ],\n        \"table_format\": 1,\n        \"table_name\": \"table\",\n        \"table_type\": \"default\"\n      }\n    ]\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Document Creation_generatePdfDocumentWithJsonFormat_example
require 'uri'
require 'net/http'

url = URI("https://api.staple.io/v2/supernova/models/document/create")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"01\",\n  \"qid\": 1,\n  \"data\": {\n    \"Address\": [\n      \"1500\",\n      \"2000\"\n    ],\n    \"Currency\": [\n      \"SGD\"\n    ],\n    \"Date\": [\n      \"1200\"\n    ],\n    \"PO\": [\n      \"800\"\n    ],\n    \"Supplier\": [\n      \"\"\n    ],\n    \"Vendor\": [\n      \"\"\n    ],\n    \"Contact\": [\n      \"DA foods\"\n    ],\n    \"tables\": [\n      {\n        \"headers\": [\n          \"Description\",\n          \"Quantity\",\n          \"UOM\",\n          \"Unit Amount\",\n          \"Line Amount\"\n        ],\n        \"standardheader\": [\n          \"Description\",\n          \"Quantity\",\n          \"UOM\",\n          \"Unit Amount\",\n          \"Line Amount\"\n        ],\n        \"rows\": [\n          [\n            \"a2\",\n            \"3\",\n            \"PCS\",\n            \"5\",\n            \"15\"\n          ],\n          [\n            \"b2\",\n            \"3\",\n            \"PCS\",\n            \"3\",\n            \"9\"\n          ],\n          [\n            \"c2\",\n            \"4\",\n            \"PCS\",\n            \"5\",\n            \"20\"\n          ]\n        ],\n        \"table_format\": 1,\n        \"table_name\": \"table\",\n        \"table_type\": \"default\"\n      }\n    ]\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java Document Creation_generatePdfDocumentWithJsonFormat_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.staple.io/v2/supernova/models/document/create")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"01\",\n  \"qid\": 1,\n  \"data\": {\n    \"Address\": [\n      \"1500\",\n      \"2000\"\n    ],\n    \"Currency\": [\n      \"SGD\"\n    ],\n    \"Date\": [\n      \"1200\"\n    ],\n    \"PO\": [\n      \"800\"\n    ],\n    \"Supplier\": [\n      \"\"\n    ],\n    \"Vendor\": [\n      \"\"\n    ],\n    \"Contact\": [\n      \"DA foods\"\n    ],\n    \"tables\": [\n      {\n        \"headers\": [\n          \"Description\",\n          \"Quantity\",\n          \"UOM\",\n          \"Unit Amount\",\n          \"Line Amount\"\n        ],\n        \"standardheader\": [\n          \"Description\",\n          \"Quantity\",\n          \"UOM\",\n          \"Unit Amount\",\n          \"Line Amount\"\n        ],\n        \"rows\": [\n          [\n            \"a2\",\n            \"3\",\n            \"PCS\",\n            \"5\",\n            \"15\"\n          ],\n          [\n            \"b2\",\n            \"3\",\n            \"PCS\",\n            \"3\",\n            \"9\"\n          ],\n          [\n            \"c2\",\n            \"4\",\n            \"PCS\",\n            \"5\",\n            \"20\"\n          ]\n        ],\n        \"table_format\": 1,\n        \"table_name\": \"table\",\n        \"table_type\": \"default\"\n      }\n    ]\n  }\n}")
  .asString();
```

```php Document Creation_generatePdfDocumentWithJsonFormat_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.staple.io/v2/supernova/models/document/create', [
  'body' => '{
  "name": "01",
  "qid": 1,
  "data": {
    "Address": [
      "1500",
      "2000"
    ],
    "Currency": [
      "SGD"
    ],
    "Date": [
      "1200"
    ],
    "PO": [
      "800"
    ],
    "Supplier": [
      ""
    ],
    "Vendor": [
      ""
    ],
    "Contact": [
      "DA foods"
    ],
    "tables": [
      {
        "headers": [
          "Description",
          "Quantity",
          "UOM",
          "Unit Amount",
          "Line Amount"
        ],
        "standardheader": [
          "Description",
          "Quantity",
          "UOM",
          "Unit Amount",
          "Line Amount"
        ],
        "rows": [
          [
            "a2",
            "3",
            "PCS",
            "5",
            "15"
          ],
          [
            "b2",
            "3",
            "PCS",
            "3",
            "9"
          ],
          [
            "c2",
            "4",
            "PCS",
            "5",
            "20"
          ]
        ],
        "table_format": 1,
        "table_name": "table",
        "table_type": "default"
      }
    ]
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Document Creation_generatePdfDocumentWithJsonFormat_example
using RestSharp;

var client = new RestClient("https://api.staple.io/v2/supernova/models/document/create");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"01\",\n  \"qid\": 1,\n  \"data\": {\n    \"Address\": [\n      \"1500\",\n      \"2000\"\n    ],\n    \"Currency\": [\n      \"SGD\"\n    ],\n    \"Date\": [\n      \"1200\"\n    ],\n    \"PO\": [\n      \"800\"\n    ],\n    \"Supplier\": [\n      \"\"\n    ],\n    \"Vendor\": [\n      \"\"\n    ],\n    \"Contact\": [\n      \"DA foods\"\n    ],\n    \"tables\": [\n      {\n        \"headers\": [\n          \"Description\",\n          \"Quantity\",\n          \"UOM\",\n          \"Unit Amount\",\n          \"Line Amount\"\n        ],\n        \"standardheader\": [\n          \"Description\",\n          \"Quantity\",\n          \"UOM\",\n          \"Unit Amount\",\n          \"Line Amount\"\n        ],\n        \"rows\": [\n          [\n            \"a2\",\n            \"3\",\n            \"PCS\",\n            \"5\",\n            \"15\"\n          ],\n          [\n            \"b2\",\n            \"3\",\n            \"PCS\",\n            \"3\",\n            \"9\"\n          ],\n          [\n            \"c2\",\n            \"4\",\n            \"PCS\",\n            \"5\",\n            \"20\"\n          ]\n        ],\n        \"table_format\": 1,\n        \"table_name\": \"table\",\n        \"table_type\": \"default\"\n      }\n    ]\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Document Creation_generatePdfDocumentWithJsonFormat_example
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "01",
  "qid": 1,
  "data": [
    "Address": ["1500", "2000"],
    "Currency": ["SGD"],
    "Date": ["1200"],
    "PO": ["800"],
    "Supplier": [""],
    "Vendor": [""],
    "Contact": ["DA foods"],
    "tables": [
      [
        "headers": ["Description", "Quantity", "UOM", "Unit Amount", "Line Amount"],
        "standardheader": ["Description", "Quantity", "UOM", "Unit Amount", "Line Amount"],
        "rows": [["a2", "3", "PCS", "5", "15"], ["b2", "3", "PCS", "3", "9"], ["c2", "4", "PCS", "5", "20"]],
        "table_format": 1,
        "table_name": "table",
        "table_type": "default"
      ]
    ]
  ]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.staple.io/v2/supernova/models/document/create")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```