ReportingCloud

POST /v1/document/merge

Endpoint

POST https://api.reporting.cloud/v1/document/merge

Description

Merges JSON data into a template and returns the created documents. The template is a stored one, named in templateName, or one sent in the body as a Base64 string. The data is an array of records, or a single record: the members of a record fill the merge fields and merge blocks of the same names, without regard to case. By default, the documents of all records are appended into one; with append=false, every record becomes a document of its own. The response is an array of Base64 strings, in the format returnFormat names, PDF by default. See Mail Merge.

Warning

Document Quota. Each successful request counts 1 against the document quota. It counts 1 also when it returns one document per record. On a trial account, a test run (test=true) counts as well. Plans and Licensing lists the quota of each plan.

Examples

Request:

curl -u username:password \
  -H "Content-Type: application/json" \
  --data \
  "
  {
    \"mergeData\": [
      {
        \"OrderNumber\": \"O2787346623\",
        \"Name\": \"JackJohnson\",
        \"Articles\": [
          {
            \"Name\": \"Article1\"
          },
          {
            \"Name\": \"Article2\"
          }
        ]
      },
      {
        \"OrderNumber\": \"O2787346623\",
        \"Name\": \"Jack2Johnson2\",
        \"Articles\": [
          {
            \"Name\": \"Article1\"
          },
          {
            \"Name\": \"Article2\"
          }
        ]
      }
    ],
    \"template\": null,
    \"mergeSettings\": null
  }
  " \
  -X POST "https://api.reporting.cloud/v1/document/merge?templateName=test_invoice.tx&returnFormat=PDF"

Results:

["JVBERi0xLjQNJeLjz9MNMSAwIG9iago8PAovVH..."]

Authorization

This endpoint requires a "ReportingCloud-APIKey" or a "Basic" user authorization to access the user account, data and templates. Only one of these two methods is required.

API Keys describes how to create an API key, and Authentication explains both header forms.

ReportingCloud-APIKey

Header fieldDescription
AuthorizationRequired. A valid ReportingCloud account is required. The Authorization field is constructed as follows: An API key needs to be generated in the portal or with PUT /v1/account/apikey. The authorization method and a space, "ReportingCloud-APIKey ", is then put before the actual API key string. For example: Authorization: ReportingCloud-APIKey oMDM4MrAqL9QEOpyzupnQW5NjvCNtvE5cVDaaLqxI

Basic

Header fieldDescription
AuthorizationRequired. A valid ReportingCloud account is required. The Authorization field is constructed as follows: The user name and password are combined into a string separated by a colon, for example username:password. The resulting string is encoded using the RFC2045-MIME variant of Base64, except not limited to 76 char/line. The authorization method and a space, "Basic ", is then put before the encoded string. For example: Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l

Request Parameters

NameTypeValueOptional
returnFormatStringA string that specifies the format of the created document. Possible values are: PDF, PDFA, RTF, DOC, DOCX, HTML, TXT and TX, in any letter case. The default value is PDF. PDFA requires an Extreme license.yes
templateNameStringThe name of the template in the template storage, in any letter case. If no template is specified, the template must be uploaded in the MergeBody object of this request. An empty value counts as no template name. If both are given, the template from the template storage is merged and the uploaded one is ignored.yes
appendBooleanSpecifies whether the documents should be appended to one resulting document when more than 1 data row is passed. Left out, or given a value that is not a Boolean, they are appended, as with true.yes
testBooleanSpecifies whether it is a test run or not. Created documents contain a "TEST MODE" watermark. A test run of this endpoint is counted against the document quota of a trial account. Not possible using the Free license. The default value is false.yes

Request Payload

TypeValue
MergeBodyThe MergeBody object contains the data source as a JSON data object and optionally, a template encoded as a Base64 string and a ReportingCloud MergeSettings object.

MergeBody

NameTypeValueOptional
mergeDataJSON array or JSON objectThe data source for the merge process: an array of data rows, or one data row as an object. Merge field and merge block names are matched without regard to letter case.no
templateBase64 encoded stringThe template encoded as a Base64 string. Supported formats are RTF, DOC, DOCX, TX and HTML.yes
mergeSettingsReportingCloud MergeSettings objectOptional merge settings to specify merge properties and document properties such as title and author. A property that is null or left out takes its default value.yes

MergeSettings

NameTypeValueOptional
removeEmptyFieldsBooleanSpecifies whether empty fields should be removed from the template or not. The default value is true.yes
removeEmptyBlocksBooleanSpecifies whether the content of empty merge blocks should be removed from the template or not. A block is empty when its array is empty or missing. The default value is true.yes
removeEmptyImagesBooleanSpecifies whether images which don't have merge data should be removed from the template or not. The default value is false.yes
removeEmptyLinesBooleanSpecifies whether lines should be removed that contain only empty fields and no other content. The default value is false.yes
removeTrailingWhitespaceBooleanSpecifies whether trailing whitespace should be removed before saving a document. The default value is true.yes
mergeHtmlBooleanSpecifies whether field data can contain formatted HTML content or not. The default value is false. HTML content must be enclosed in an <html> tag element. Only active in the Merge endpoint.yes
authorStringSets the document's author.yes
creationDateDateTime (String)Sets the document's creation date which will be saved in the document.yes
lastModificationDateDateTime (String)Sets the date the document is last modified.yes
creatorApplicationStringSets the application, which has created the document.yes
documentSubjectStringSets the document's subject string which will be saved in the document.yes
documentTitleStringSets the document's title that will be saved in the document.yes
userPasswordStringSpecifies the password for the user to open the document. A PDF is encrypted with it, while a DOCX is returned without a password.yes
cultureStringSpecifies the culture for the merge process for date and currency values. It must be a Language Culture Name of Microsoft's Table of Language Culture Names, Codes, and ISO Values. For French use "fr-FR", for German "de-DE". Default is English "en-US". The data is read in this culture as well: with "de-DE", the value "1234.5" is not taken as a number and is merged as it is.yes

Success Response

StatusDescription
200On success, the HTTP status code in the response header is 200 (OK). The response body contains an array of the created documents encoded as Base64 encoded strings.

Error Response

StatusDescription
400A 400 (Bad Request) is returned, if the request body is empty or isn't JSON, the MergeBody object has no mergeData, no template is uploaded and the template is not found in the template storage, or returnFormat is not one of the possible values.
403A 403 (Forbidden) is returned, if the user is not authorized, the document quota is exceeded, more than 2 concurrent requests came in from the same account or the return format PDFA is requested without an Extreme license.
405A 405 (Method Not Allowed) is returned, if the request uses another HTTP method than POST. The Allow header of the response names POST.
411A 411 (Length Required) is returned, if the request has neither a body nor a Content-Length header.
415A 415 (Unsupported Media Type) is returned, if the request has a body but no Content-Type header, or a Content-Type such as text/plain that the endpoint doesn't read. Send Content-Type: application/json.
500A 500 (Internal Server Error) is returned, if the request has no Authorization header, an empty one or one that is not the authorization method, a space and the credentials, or if returnFormat is empty, the template is not a valid Base64 string or a MergeSettings property has a value of the wrong type.

Timeout Limitation. The pure processing time is limited to a maximum of 60 seconds. After this period of time, the task is canceled.

A typical document should not take more than 5 seconds. If your request takes longer, decrease the number of data rows and reduce the template size.