Generate and Download Document
This topic describes the details and steps for generating the document with JSON data and downloading the generated document to your browser. You might use this functionality differently to generate documents depending on your business case.
Prerequisites
- Contact your Account Executive with your 18-digit OrgID to enable the Composer API feature.
- Refer to the Authentication section to generate the Client ID and Client Secret that will be used in the code to connect to the Conga Authorization server.
Use Case
In this use case, we use the template saved in your Box account, merge the document with JSON data, convert it to PDF format, and then download it. All of these composer parameters are added to the legacyOptions tag of the merge request body, as well as a JSON payload in the jsonData tag.
You can also use the following cloud storage providers as per your business use case:
- AWS
- SharePoint
- Google Drive
- Dropbox
- OneDrive
- Salesforce
- SFTP
Generate and Download Document Use case
This use case describes how a REST API developer merges a template stored in a cloud storage provider with JSON data, converts the result to PDF, and downloads the generated document using the Composer API.
This use case provides an example of how to generate a document from a template and JSON data, and download the resulting file using the Composer API. Your implementation may vary based on your specific business requirements.
Business Context
Organizations that generate high volumes of business documents, such as proposals, contracts, or order confirmations, often store reusable templates in a cloud storage provider and need to merge those templates with dynamic data at the time of generation. Rather than manually assembling documents, an integration developer can use the Composer API to programmatically merge a stored template with JSON data, produce a PDF, and deliver it directly to an end user or downstream system. This approach reduces manual effort, ensures consistent formatting, and allows document generation to be embedded into existing applications or workflows.
Overview
In this use case, a template saved in a Box account is merged with JSON data, converted to PDF format, and downloaded. The Composer parameters that control this behavior are included in the LegacyOptions tag of the merge request body, along with a JSON payload in the JsonData tag and template source details in the TemplateSources tag.
Although this use case uses Box, you can use other cloud storage providers based on your business requirements, including AWS, SharePoint, Google Drive, Dropbox, OneDrive, Salesforce, and SFTP.
Actors/Roles
- Integration developer: Configures the API client, authenticates to the Conga Authorization server, and submits the merge and download requests.
- Composer API: Processes the merge request, generates the document, and makes it available for download.
- Cloud storage provider (Box): Stores the source template referenced by the merge request.
Prerequisites
- The Composer API feature is enabled for the Salesforce org. Contact your Account Executive with your 18-digit Org ID to enable this feature.
- A Client ID and Client Secret have been generated for connecting to the Conga Authorization server. See Authentication.
- A template containing the required merge fields has been created and uploaded to a Box account folder, and its File ID has been noted.
Trigger
An integration developer initiates the process by submitting a merge request to the Composer API that references a template stored in Box and includes a JSON data payload. The request explicitly sets generateDocumentDownload to true under output, which signals that the resulting document should be made available for download rather than routed through another delivery method.
Tasks
-
Prepare the template and store it in the Box account folder. Create a template that contains the required merge fields and upload it to the Box folder. Note the template's File ID for use in the merge request.
-
Retrieve the Conga authentication token. Call the Composer REST API token endpoint using the Client ID and Client Secret to obtain a bearer token required for subsequent requests.
Field Value Endpoint https://login-rls.congacloud.com/api/v1/auth/connect/token Method POST Request header Content-Type: application/x-www-form-urlencoded Request body grant_type=client_credentials&scope=doc-gen.composer&client_id=<congaAuthClientId>&client_secret=<congaAuthClientSecret> The response includes an access_token, its expires_in value (in seconds), and the token_type (Bearer).
-
Create and submit the merge request. Submit a merge request that includes the PDF output option and output file name in LegacyOptions, the merge data in JsonData, the Box template reference in TemplateSources, and generateDocumentDownload set to
true.Note: Escape double quotes inside the JsonData tag with a backslash (\).Field Value Endpoint https://coreapps-rlsprod.congacloud.com/api/ingress/v1/Merge Method POST Request header Authorization: Bearer <congaAuthToken>; Content-Type: application/json { "LegacyOptions": { "DefaultPdf": "1", "OFN": "Box + Document Download Testing" }, "JsonData": "{\"firstName\":\"John\",\"lastName\":\"Doe\", \"executiveSummary\":\"Below, you will find a proposal, etc. etc.\", \"products\":[{\"name\":\"test product\",\"quantity\":5, \"price\":10,\"total\":50},{\"name\":\"Creative Name\", \"quantity\":10,\"price\":20,\"total\":200}]}", "TemplateSources": [ {"IntegrationName":"box", "FileId": "{{FileId}}"} ], "output": {"generateDocumentDownload": true} }A successful response returns a correlationId and a status of Accepted.
-
Check the merge request status. Poll the status endpoint using the correlationId from the previous step until the status changes from Pending to Completed or Error.
Field Value Endpoint https://coreapps-rlsprod.congacloud.com/api/status/v1/status/{correlationId} Method GET Request header Authorization: Bearer <congaAuthToken> -
Get the downloadable URL. Once the status is Completed, call the pre-signed service endpoint using the correlationId (as lookupId) to retrieve the URL for the generated document.
Field Value Endpoint https://coreapps-rlsprod.congacloud.com/api/presigned/v1/PreSignedService/{lookupId} Method GET Request header Authorization: Bearer <congaAuthToken> The response contains isSuccessful and a URL similar to
https://ENVIRONMENT_DOMAIN/PreSignedService/{lookupId1}/{lookupId2}/{{filename}}. -
Download the document. Parse lookupId1 and lookupId2 from the URL returned in the previous step, and call the download endpoint to retrieve the generated document.
Field Value Endpoint https://coreapps-rlsprod.congacloud.com/api/presigned/v1/PreSignedService/{lookup1}/{lookup2} Method GET Request header Authorization: Bearer <congaAuthToken>
Result
-
The template is merged with the JSON data and generated as a PDF document.
-
A downloadable URL for the generated document is returned to the requesting application.
-
The document is downloaded to the requesting application or browser.
Variations
This use case can be adapted to reference a template stored in a different cloud storage provider, such as AWS, SharePoint, Google Drive, Dropbox, OneDrive, Salesforce, or SFTP, by changing the IntegrationName value in TemplateSources. It can also be adapted to generate the document in a different output format, or to deliver the generated document by email instead of a direct download.
Tips and Best Practices
expires_in
is typically 3600 seconds) instead of requesting a new token for every merge
request.Step 1: Prepare the Template and Store it in your Box account folder
Create a template with all merge fields and upload it to your Box folder. Carefully note the template's file ID. For more information on how to create a template and get the File ID, see the following topics:
Step 2: Retrieve Conga Authentication Token
A Conga authentication token is required when you submit a request to merge a document or check the merge request status. To get this token, pass the client ID and client secret you obtained when enabling the Salesforce org for Conga Composer API.
Call the following Composer REST API method to get the Conga authentication token.
|
End Point |
|
|
Request Method |
POST |
|
Request Header |
|
|
Request Body |
|
|
Response Body |
|
Step 3: Create Merge Request and Submit
After completing the previous three steps, you can create a merge request to generate the document. The merge request contains several parameters that determine which features are included in the generated document.
In the merge API request body, you can control the behavior of document generation by including values in the legacyOptions tag, a JSON payload in the jsonData tag, and getting the template from your cloud storage provider in the TemplateSources tag.
In this use case:
- DefaultPDF: Generate a document in PDF format.
- OFN: Output File Name, overriding the default name of the file.
-
jsonData: Create a JSON Data body as described above in the example. Note:
You must include the escape character (\) for double quotes inside the jsonData tag.
-
TemplateSources
- IntegrationName: box (name of the cloud storage provider)
- FileID: The location of a template file.
-
generateDocumentDownload under output must be set to true.
Tip:
For example
"output": {"generateDocumentDownload": true}
Call the below Composer REST API method to create a document using the Merge API service.
|
End Point |
|
|
Request Method |
POST |
|
Request Header |
|
|
Request Body |
|
|
Response Body |
|
Step 4: Check Merge Request Status
Once you send a request to generate a document, you will receive a correlationId in response. You can check the current merge status request using this correlationId.
Call the following Composer REST API service to check the merge request status.
Call this method repeatedly with a delay until the status changes from "Pending" to "Completed" or "Error."
- correlationId: You can find the value for this parameter from the previous step to submit the merge request’s response body.
|
End Point |
|
|
Request Method |
GET |
|
Request Header |
Authorization: |
|
Response Body |
|
Step 5: Get the Downloadable URL(s)
After receiving a Completed status response in step 4, the document is ready to be downloaded.
Call the following Composer REST API service to get the downloadable URL(s) for download.
-
lookupId: The CorrelationId obtained from the response in step 3.Note: The merged file download link is valid for 7 days. After 7 days, using the correlationId to fetch the download URL will return a 404 Not Found error, and the link will no longer be valid.
|
End Point |
|
|
Response Endpoint |
|
|
Request Method |
GET |
|
Request Header |
Authorization: |
|
Response Body |
The response should contain:
|
Step 6: Download the Document
Use the lookupIds available in the URL received in the response of step 5 to download the document.
Call the following Composer REST API service to download the document:
Refer to the example below to understand how to obtain the lookupId1 and lookupId2 from the URL received in step 5.
For example: If the URL received is: https://ENVIRONMENT_DOMAIN/PreSignedService/523954f3264c463fa6cbf36deaed3df2_DatasetJson/aae1bdcb-e520-4581-8e96-23aae5bc0b88/<filename>, then lookupId1=
523954f3264c463fa6cbf36deaed3df2_DatasetJson
and lookupId2=
aae1bdcb-e520-4581-8e96-23aae5bc0b88
|
End Point |
|
|
Request Method |
GET |
|
Request Header |
Authorization: |
