GenerateDocument (Application-Level)
This method helps to generate a document, replacing requested values with desired output, and either return the output or store it in the server’s file system for subsequent merge with a cache key receipt.
Authentication
This method requires an authentication token if the access level of the application is set to Restricted.
Request
Target Endpoint
POST /Api/Applications/GenerateDocument
Parameters
Property Name |
Type |
Is Required? |
Description |
---|---|---|---|
ApplicationKey | String | Required | The application key, corresponding to your specific web service application. This constitutes the identifier for the requested resource. |
DocumentKey | String | Required | Key generated in the Control Panel UI for the specific document. |
Mappings | Object with schema:
{ “TexttoReplace”: “Value”, “TexttoReplace “: “Value” } |
Required | A dictionary of <string, string>, where key is text to replace and value is text to be replaced with. |
ImageMappings | Array of Object
[ { “Key”: String, “ImageType”: int, “ImageContent”: byte[] } ] |
A list of image stubs to be replaced.
Key: String corresponding to image stub name. ImageType: Enum value representing the image type: [0: Bmp] [1: Gif] [2: Png] [3: Tiff] [4: Icon] [5: Pcx] [6: Jpeg] [7: Emf] [8: Wmf] [9: Svg] ImageContent: Byte array containing the image data to be inserted in the place of the image containing the corresponding stub. |
|
OutputMode | int | Required | Enum value for what to do with the document after it is generated:
[0: ReturnDocument]: Return the document as a byte array. [1: StoreInFileSystem]: Store the file on the server and return a guid receipt for merging.
|
PrintMode | int | Required | Enum value for what format the output should be returned as:
[0: PDF]: Document will be returned as PDF document. [1: Word]: Document will be returned as a Word (.DOCX document). NOTE: This will be disregarded when using the StoreInFileSystem (1) value for OutputMode. |
IsCaseSensitive | Boolean | Optional | This flag will determine whether to consider case sensitivity when identifying stubs for replacement.
When set to True, if there are multiple stubs that are identical except for character case, then only stubs matching the exact case of the stub key will be replaced. When set to False, this same scenario will replace all stubs matching the target pattern. The default behavior is True. |
Request Sample (Restricted)
The sample below is a simple request to the GenerateDocument method for a restricted application, clearly designated by the bearer token in the authorization header. The token was retrieved using an authentication request. The process of retrieving an access token is documented here.
Headers
POST /Api/Applications/GenerateDocument HTTP/1.1 Authorization: Bearer Do3l_2l3uLdmYX76u-BufLzuuhFPOE-nRZDyU0adiFk1 Content-Type: application/json Host: dev7.pagos.com
Body (formatted)
{ "DocumentKey": "3a98a194-6768-432d-a7b7-b33104a5dd76", "Mappings": { "{{DummyStub}}": "Value", "{{DummyStub2}}": "Value 2" }, "ImageMappings": { "Key": "ImageStub", "Type": 2, "ImageContent":"/9j/4AAQSkZJRgABAQEASABIAAD/7QBkUGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAACwcAVoAAxslRxwCAAACAAIcAj4ACDIwMTIwNTExHAI/AAsxNjAyMjEtMDQw/Et7nkY1bnXscetMzdHsXU/9k=" }, "OutputMode": 0, "PrintMode": 0, "IsCaseSensitive": true, "ApplicationKey": "a4dcfb4f0464453b928ce1d6bcfb6aa3" }
Request Sample (Unrestricted)
Headers
POST /Api/Applications/GenerateDocument HTTP/1.1 Content-Type: application/json Host: dev7.pagos.com
Body (formatted)
{ "DocumentKey": "3a98a194-6768-432d-a7b7-b33104a5dd76", "Mappings": { "{{DummyStub}}": "Value", "{{DummyStub2}}": "Value 2" }, "ImageMappings": { "Key": "ImageStub", "Type": 2, "ImageContent":"/9j/4AAQSkZJRgABAQEASABIAAD/7QBkUGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAACwcAVoAAxslRxwCAAACAAIcAj4ACDIwMTIwNTExHAI/AAsxNjAyMjEtMDQw/Et7nkY1bnXscetMzdHsXU/9k=" }, "OutputMode": 0, "PrintMode": 0, "IsCaseSensitive": true, "ApplicationKey": "a4dcfb4f0464453b928ce1d6bcfb6aa3" }
Response
Property Name |
Type |
Description |
---|---|---|
Success | Boolean | Indicated whether or not the request was successful based on the provided token and application key. |
Document | byte[] | The document, if OutputMode = 0. |
CacheKey | string | The key for this document in the cache if OutputMode = 1 |
InvalidToken | Boolean | If the request is unsuccessful, indicates whether or not the failure was due to token. |
Messages | Array of String | A list of messages, which can be used or captured for diagnostics. When requests are unsuccessful, the reason for the failure will be documented in the Messages list. |
Response Sample (Success)
Headers
HTTP/1.1 200 OK Cache-Control: no-cache, no-store Content-Type: application/json; charset=utf-8
Body (formatted)
Example 1:
{ "Document": " JVBERi0xLjQNCiW0tba3DQoxIDAgb2JqDQo8PA0KL1BhZ2VzIDIgMCBSDQovUGFnZUxheW91dCAvT25lQ29sdW1uDQovVHlwZSAvQ2F0YWxvZw0KL091dHB1dEludGVudHMgWzw8DQovT3V0cHV0Q29uZGl0aW9uICgpDQovT3V0cHV0Q29uZGl0aW9uSWRlbnRpZmllciAoQ3VzdG9tKQ0KL1JlZ2lzdHJ5TmFtZSAoKQ0KL0luZm8gKHNSR0IgSUVDNjEY5ODc2IDAwMDAwIG4NCjAwMDAwNzAxOTUgMDAwMDAgbg0KMDAwMDA3MDUyMCAwMDAwMCBuDQowMDAwMDkwMTc0IDAwMDAwIG4NCnRyYWlsZXINCjw8DQovSW5mbyA2IDAgUg0KL1Jvb3QgMSAwIFINCi9TaXplIDI4DQo+Pg0KDQpzdGFydHhyZWYNCjEwMzQ0Mg0KJSVFT0YNCg==", "CacheKey": "00000000-0000-0000-0000-000000000000", "Success": true, "InvalidToken": false, "Messages": [] }
Example 2:
{ "Document": null, "CacheKey": "a81aecea-d38c-4973-96bc-964cfa10e9fe", "Success": true, "InvalidToken": false, "Messages": [] }
Response Sample (Failure)
Headers
HTTP/1.1 200 OK Cache-Control: no-cache, no-store Content-Type: application/json; charset=utf-8
Body (formatted)
Example 1:
{ "Document": null, "CacheKey": "00000000-0000-0000-0000-000000000000", "Success": false, "InvalidToken": false, "Messages": [ "The requested resource is restricted and your request did not provide a valid token." ] }
Example 2:
{ "Document": null, "CacheKey": "00000000-0000-0000-0000-000000000000", "Success": false, "InvalidToken": false, "Messages": [ "The submitted document key does not correspond to any existing document in the system. Please check the Control Panel for the appropriate document key." ] }