Skip to main content

Quick Start Guide

This guide will walk you through creating your first document with Json2doc. In just a few minutes, you'll create a professional PDF or Word document using either template mode or document mode.

Prerequisites

  • A Json2doc account with an API key (sign up here)
  • Basic knowledge of HTTP requests
  • A command line tool like cURL (or use our examples in other languages)

Option 1: Template Mode (Simplest)

If you have a Word document template with placeholders like {{companyName}}, this is the fastest way to get started.

Step 1: Upload Your Template

First, upload a Word document template:

curl -X POST 'https://api.json2doc.com/v1/templates/upload' \
-H 'Content-Type: multipart/form-data' \
-H 'Accept: application/json' \
-H 'x-api-key: YOUR_API_KEY' \
-F 'file=@"/path/to/your/template.docx"' \
-F 'name="Business Report Template"'

Response:

{
"success": true,
"data": {
"id": "template_abc123",
"name": "Business Report Template",
"filename": "template.docx",
"storagePath": "/templates/template_abc123.docx",
"createdAt": "2025-01-15T10:30:00Z"
}
}

Step 2: Generate Document from Template

Create a document using your template with variable replacement:

curl -X POST \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"templateId": "template_abc123",
"variables": {
"companyName": "Acme Corporation",
"year": "2024",
"revenue": "$1,250,000",
"profit": "$185,000"
},
"output": {
"filename": "acme-report-2024",
"type": "pdf"
}
}' \
https://api.json2doc.com/v1/templates/generate

Response:

{
"success": true,
"data": {
"jobId": "job_def456",
"status": "PENDING",
"type": "TEMPLATE",
"estimatedTokens": 5,
"createdAt": "2025-01-15T10:32:00Z"
}
}

Step 3: Download Your Document

curl -H "x-api-key: YOUR_API_KEY" \
-o acme-report-2024.pdf \
https://api.json2doc.com/v1/jobs/job_def456/download

🎉 Congratulations! You've created your first document using template mode!

Option 2: Document Mode (Full Control)

For complete control over document structure and styling, use document mode.

Step 1: Create a Simple Document Job

Create a document from scratch with full styling control:

curl -X POST \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"document": {
"type": "pdf",
"filename": "business-report",
"title": "Business Report 2024",
"author": "Json2doc API",
"size": "A4"
},
"defaults": {
"fontFamily": "Arial",
"fontSize": 11,
"styles": {
"h1": {
"fontSize": 24,
"fontWeight": "bold",
"color": "#0066cc",
"align": "center"
},
"h2": {
"fontSize": 18,
"fontWeight": "bold",
"color": "#333333"
}
}
},
"sections": [
{
"type": "flow",
"content": [
{
"type": "h1",
"text": "Business Report 2024"
},
{
"type": "h2",
"text": "Executive Summary"
},
{
"type": "text",
"text": "This comprehensive report covers our business performance for 2024. We achieved significant growth with **25% revenue increase** and expanded our market presence."
},
{
"type": "text",
"text": "Key highlights include:",
"spacing": {
"after": 10
}
},
{
"type": "list",
"ordered": false,
"items": [
"Revenue growth of **25%** year-over-year",
"Expansion into **3 new markets**",
"Customer satisfaction score of **4.8/5**",
"Team growth to **150 employees**"
]
}
]
}
]
}' \
https://api.json2doc.com/v1/jobs

Response:

{
"success": true,
"data": {
"jobId": "job_ghi789",
"status": "PENDING",
"type": "DOCUMENT",
"estimatedTokens": 8,
"createdAt": "2025-01-15T10:32:00Z"
}
}

Step 2: Check Job Status

curl -H "x-api-key: YOUR_API_KEY" \
https://api.json2doc.com/v1/jobs/job_ghi789

Response when complete:

{
"success": true,
"data": {
"id": "job_ghi789",
"type": "DOCUMENT",
"status": "COMPLETED",
"outputFileId": "file_jkl012",
"tokensUsed": 8,
"completedAt": "2025-01-15T10:32:02Z",
"createdAt": "2025-01-15T10:32:00Z"
}
}

Step 3: Download Your Document

curl -H "x-api-key: YOUR_API_KEY" \
-o business-report.pdf \
https://api.json2doc.com/v1/files/file_jkl012/download

🎉 Congratulations! You've created your first document using document mode!

What Just Happened?

Template Mode

  1. Template Upload: You uploaded a Word document template
  2. Variable Replacement: Json2doc replaced {{variables}} with your data
  3. Generation: Created a new document in your chosen format
  4. Download: Retrieved the final document

Document Mode

  1. JSON Configuration: You defined the complete document structure in JSON
  2. Style Definition: Set up fonts, colors, and spacing using defaults
  3. Content Creation: Added headings, text, and lists with formatting
  4. Generation: Json2doc rendered everything into a professional PDF

Error Handling

If something goes wrong, the API returns clear error messages:

{
"success": false,
"error": "validation_error",
"message": "Template variable 'companyName' is not defined"
}

Common issues:

  • Missing API key: Include the x-api-key header in all requests
  • Invalid JSON: Ensure your JSON configuration is valid
  • Undefined variables: Template mode requires all {{variables}} to be provided
  • Invalid paths: File paths in document mode must start with /

Ready for More?

Now that you've created your first document, explore:

Questions? We're here to help at support@json2doc.com!