Synchronous generation

PDFMonkey main generation mechanism is asynchronous. Your Document is queued for generation and you can either use a webhook or call our API in a loop to get notified of the generation success.

The sync generation feature allows you to skip this, and simplify your workflow. It will queue the Document as usual but will wait for the generation to either succeed or fail before responding.

How does it work?

In order to use the sync feature, call the POST /api/v1/documents/sync endpoint when generating your Document.

curl \
  "https://api.pdfmonkey.io/api/v1/documents/sync" \
  -X POST \
  -H 'Authorization: Bearer YOUR-API-KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "document": {
      "document_template_id": "ID-OF-YOUR-TEMPLATE",
      "status": "pending", // To force generation to be queued upon creation
      "payload": {
        "clientName": "Peter Parker",
        "orderDate": "2050-03-14",
        "products": [
          { "name": "Spider silk", "quantity": 12, "unitPrice": 123.50 },
          { "name": "Spandex fabric", "quantity": 2, "unitPrice": 28.90 }
        ]
      },
      "meta": {
        "_filename": "2050-03-14 Peter Parker.pdf",
        "clientRef": "spidey-616"
      }
    }
  }'

Response

{
  "document_card": {
    "app_id": "ID-OF-YOUR-WORKSPACE",
    "created_at": "2050-03-13T12:34:56.181+02:00",
    "id": "12345678-1234-1234-1234-123456789012",
    "meta": {
      "_filename": "2050-03-14 Peter Parker.pdf",
      "clientRef": "spidey-616"
    },
    "status": "generating", // Document is queued (could also still be "pending")
    "updated_at": "2050-03-13T12:34:56.181+02:00",
    "document_template_id": "ID-OF-YOUR-TEMPLATE",
    "document_template_identifier": "My Awesome Template",
    "download_url": null, // Not filled until generation success
    "failure_cause": null, // Filled in case of error
    "filename": "2050-03-14 Peter Parker.pdf",
    "preview_url": "https://...", // Used to embed a preview like in our dashboard
    "public_share_link": null // Filled upon generation success on a Pro+/Premium plan    
  }
}

Last updated

Was this helpful?