REST API Cookbook with Working Examples Version: 1.7.
REST API Cookbook with Working Examples Version 1.7.1 Last Revision: 2017-10-30 Objectif Lune, Inc. 2030 Pie-IX, Suite 500 Montréal, QC, Canada, H1V 2C8 +1 (514) 875-5863 www.objectiflune.com All trademarks displayed are the property of their respective owners.
© Objectif Lune, Inc. 1994-2017. All rights reserved. No part of this documentation may be reproduced, transmitted or distributed outside of Objectif Lune Inc. by any means whatsoever without the express written permission of Objectif Lune Inc. Objectif Lune Inc. disclaims responsibility for any errors and omissions in this documentation and accepts no responsibility for damages arising from such inconsistencies or their further consequences of any kind. Objectif Lune Inc.
Table of Contents Table of Contents 5 Welcome to the PlanetPress Connect REST API Cookbook 11 Technical Overview 12 Workflow & Workflow Processes Data Mapping Content Creation Job Creation Output Creation All-In-One Input Files Data Entities Data Set & Data Record Entities Content Set & Content Item Entities Job Set & Job Entities Workflow Operations Asynchronous Operations Synchronous Operations JSON Structures Common Structures Specific Structures Working Examples 13 14 15 16 17 18 20 21 21 22 23 2
Uploading a Job Creation Preset to the File Store Uploading an Output Creation Preset to the File Store Working with the Entity Services Finding Specific Data Entities in the Server Finding all the Data Sets in the Server Finding the Data Records in a Data Set Finding all the Content Sets in the Server Finding the Content Items in a Content Set Finding all the Job Sets in the Server Finding the Jobs in a Job Set Working with the Workflow Services Running a Data Mapping Operation Running a Data Mapping Opera
Get All Operations Get Progress of Operation Get Result of Operation Cancel an Operation Service Version Content Item Entity Service Service Handshake Get Data Record for Content Item Get Content Item Properties Update Content Item Properties Update Multiple Content Item Properties Service Version Content Set Entity Service Get All Content Set Entities Get Content Items for Content Set Get Page Details for Content Set Delete Content Set Entity Get Content Set Properties Update Content Set Properties Service
Service Version Data Mapping Service Service Handshake Process Data Mapping Process Data Mapping (JSON) Process Data Mapping (PDF/VT to Data Set) Process Data Mapping (PDF/VT to Content Set) Get All Operations Get Progress of Operation Get Result of Operation Cancel an Operation Service Version Document Entity Service Service Handshake Get Document Metadata Properties Update Document Metadata Properties Service Version Document Set Entity Service Service Handshake Get Documents for Document Set Get Document
Download Managed File or Directory Delete Managed File or Directory Upload Data Mapping Configuration Upload Job Creation Preset Upload Data File Upload Design Template Upload Output Creation Preset Service Version Content Creation (HTML) Service Service Handshake Process Content Creation (By Data Record) Process Content Creation (By Data Record) (JSON) Get Template Resource Service Version Job Creation Service Service Handshake Process Job Creation Process Job Creation (JSON) Process Job Creation (JSON Job
Get Job Segment Metadata Properties Update Job Segment Metadata Properties Service Version Job Set Entity Service Get All Job Set Entities Get Jobs for Job Set Delete Job Set Entity Get Job Set Metadata Properties Update Job Set Metadata Properties Get Job Set Properties Update Job Set Properties Service Version Output Creation Service Service Handshake Process Output Creation Process Output Creation (JSON) Process Output Creation (By Job) (JSON) Get All Operations Get Progress of Operation Get Result of Op
Welcome to the PlanetPress Connect REST API Cookbook This guide is aimed at technically experienced users who wish to learn and use the REST API available in PlanetPress Connect version 1.7.1. The PlanetPress Connect REST API consists of many services that expose access to a number of areas including workflow, data entity management and file store operations.
Technical Overview This section provides an overview of the concepts and structures used within PlanetPress Connect and the REST API.
Workflow & Workflow Processes The primary workflow in PlanetPress Connect consists of four major processes that each require a number of inputs, and once executed, produce a particular form of output. These processes are: data mapping, content creation, job creation and output creation. There is an additional workflow process, named All-In-One, which embodies all four major workflow processes in a singular process.
Data Mapping The data mapping process involves taking a data file or source, applying a data mapping configuration to it, and producing a structured set of data or data records (a data set). This process can also produce a data set or content set from a PDF/VT file using its internal meta data instead of a data mapping configuration.
Content Creation The content creation process involves taking either a data set or one or more data records (from a data set), combining them with a suitable design template, and producing one or more sets of content (content sets). If the content is for the Email or Web context then output can be produced at this stage.
Job Creation The job creation process involves taking one or more content sets and applying a job creation preset for organizing, sorting and grouping them into a set of logical jobs (a job set). This includes the application of data filtering and finishing options.
Output Creation The output creation process involves taking either a job set or one or more jobs (from a job set), applying an output creation preset, and producing the print output (Print context).
All-In-One The All-In-One process embodies all four major workflow processes (data mapping, content creation, job creation and output creation) in a singular process. It can be configured to run one or more of the four processes, as long as the processes specified result in a logical sequence or workflow. Depending on it's configuration, the All-In-One process can produce either a data set, content sets, a job set or print output (Print context).
Processes Input Combination Expected Output Data Mapping Only Data File + Data Mapping Configuration Data Set Data Mapping + Content Creation Data File + Data Mapping Configuration + Design Template Content Set(s) Content Creation Only Data Records + Design Template Content Set(s) Data Mapping + Content Creation + Job Creation Data File + Data Mapping Configuration + Design Template Job Set Content Creation + Job Creation Data Records + Design Template Job Set Content Creation + Job Creati
Input Files Input files are used as input to a specific workflow process. The following table lists the types of input files used in the PlanetPress Connect workflow: Name Relevant Workflow Process Data File Data Mapping Data Mapping Configuration Data Mapping Design Template Content Creation File Name Examples l Promo-EN-10.csv l Promo-EN-10000.csv l PDFVT-Data.pdf l Promo-EN.
Data Entities There are many data entity types used by PlanetPress Connect, but not all data entities can be accessed through the REST API. The main data entities to be aware of when working with the API are: l Data Sets l Data Records l Content Sets l Content Items l Job Sets l Jobs Data Set & Data Record Entities The data set is the artefact produced by a data mapping operation. It holds the data that was mapped out of the input data file.
The following diagram illustrates the basic relationship between these entities in the context of the data mapping process: The data set and data record entities (shown above in blue) are accessible via the Data Set Entity and Data Record Entity services. Content Set & Content Item Entities The content set is the artefact produced by a content creation operation. It holds all the pages that were produced by the operation.
The content set and content item entities (shown above in blue) are accessible via the Content Set Entity and Content Item Entity services. Job Set & Job Entities The job set is the artefact produced by a job creation operation. It consists of a hierarchical structure that divides documents into various structures and it basically decides which documents are to be printed and in what order.
the overall context of the primary workflow in PlanetPress Connect: Page 24
Workflow Operations Each individual process in the overall workflow can potentially be a long running operation.
A request made to the cancel URI during processing will immediately cancel the operation. A request made to the result URI after processing has completed will return the final result of the operation. This is the default workflow operation type, and this approach is used across most workflow based services as demonstrated in the Working with the Workflow Services page of the Working Examples section.
JSON Structures The PlanetPress Connect REST API uses various JSON structures to describe certain inputs and outputs to resource methods.
} JSON Identifier List Describes a list of identifiers for multiple data entities in PlanetPress Connect. The structure consists of an object with a single name/value pair: l identifiers - an array of data entity identifiers (type of number) Example: { "identifiers": [ 12345, 23456, 34567 ] } JSON Name/Value List (Properties Only) Describes a list of properties (each as a name/value pair).
l id - the data entity identifier (type of number) l properties - the data entity properties, consisting of an array of objects each with the following name/value pairs: l name - the name of the property (type of string) l value - the value of the property (type of string) Example: { "id": 12345, "properties": [ { "name": "start", "value": "2015-01-01 00:00:00T-0500" }, { "name": "end", "value": "2015-12-31 23:59:59T-0500" } ] } JSON Name/Value Lists Describes multiple lists of properties (as name/v
} ] }, { "id": 23456, "properties": [ { "name": "start", "value": "2015-01-01 00:00:00T-0500" }, { "name": "end", "value": "2015-12-31 23:59:59T-0500" } ] } ] Specific Structures Specific JSON structures used in the PlanetPress Connect REST API include the following: JSON Identifier (with createOnly flag) Describes an identifier for a single job set entity, along with additional parameters used specifically in an output creation operation.
JSON Identifier List (with createOnly flag) Describes a list of identifiers for multiple job entities, along with additional parameters used specifically in an output creation operation.
l id - the data record entity identifier (type of number) l fields - a list of data fields in the data record entity, consisting of an array of objects each with the following name/value pairs: l l name - the name of the data field (type of string) l value - the value of the data field (type of string) records - a list of any nested data record entities, consisting of an array of objects each with the following name/value pairs: l id - the data record entity identifier (type of number) l table
}, { "name": "Gender", "value": "M." }, { "name": "FirstName", "value": "Benjamin" }, { "name": "LastName", "value": "Verret" } ] } { "id": 45678, "table": "detail", "parentrecordid": 23456, "fields": [ { "name": "ItemNumber", "value": "PSM002" }, { "name": "ItemDesc", "value": "PSM Production (unlimited)" }, { "name": "ItemUnitPrice", "value": "495.00" }, { "name": "ItemOrdered", "value": "2" }, { "name": "ItemTotal", "value": "990.
{ "id": 23456, "table": "record", "datasetid": 12345, "fields": [ { "name": "ID", "value": "CU00048376" }, { "name": "Date", "value": "2012-03-29T13:00Z" }, { "name": "DueDate", "value": "2012-04-28T14:00Z" }, { "name": "InvNumber", "value": "INV9441991" }, { "name": "Gender", "value": "M." }, { "name": "FirstName", "value": "Benjamin" }, { "name": "LastName", "value": "Verret" } { "name": "TotalOrdered", "value": "3" }, { "name": "InvSubTotal", "value": "1485.
"value": "111.38" }, { "name": "InvTotal", "value": "1596.38" } ], "records": [ { "id": 45678, "table": "detail", "parentrecordid": 23456, "fields": [ { "name": "ItemNumber", "value": "PSM002" }, { "name": "ItemDesc", "value": "PSM Production (unlimited)" }, { "name": "ItemUnitPrice", "value": "495.00" }, { "name": "ItemOrdered", "value": "2" }, { "name": "ItemTotal", "value": "990.
}, { "name": "ItemDesc", "value": "Upgrade (Starter to Web)" }, { "name": "ItemUnitPrice", "value": "495.00" }, { "name": "ItemOrdered", "value": "1" } { "name": "ItemTotal", "value": "495.00" } ] } ] } JSON Record Content Lists Describes multiple lists of data field values (as name/value pairs), nested data records (if any), along with a number of additional properties for data record entities of a specific ID. The structure consists of an array of JSON Record Content List structure objects.
"value": "PSM Production (unlimited)" }, { "name": "ItemUnitPrice", "value": "495.00" }, { "name": "ItemOrdered", "value": "2" }, { "name": "ItemTotal", "value": "990.00" } ] }, { "id": 45679, "table": "detail", "parentrecordid": 23456, "fields": [ { "name": "ItemNumber", "value": "PSM005" }, { "name": "ItemDesc", "value": "Upgrade (Starter to Web)" }, { "name": "ItemUnitPrice", "value": "495.00" }, { "name": "ItemOrdered", "value": "1" } { "name": "ItemTotal", "value": "495.
] JSON Record Content List (Fields Only) Describes a list of data field values (as name/value pairs) for a data record, used to update an existing data record entity of a specific ID.
"fields": [ { "name": "FirstName", "value": "Benjamin" }, { "name": "LastName", "value": "Verret" } ] }, { "id": 23456, "fields": [ { "name": "FirstName", "value": "Dianne" }, { "name": "LastName", "value": "Straka" } ] } ] JSON New Record List Describes a list of new data records (and their data field values (as name/value pairs)) to be added as data record entities to either an existing data set or data record entity of a specific ID.
Specific to the adding of data records to the record data table of an existing data set entity, an additional name/value pair is included: l datasetid - the data set entity identifier of parent entity (type of number) Specific to the adding of nested data records to a data table of an existing data record entity, two additional name/value pairs are included: l recordid - the data record entity identifier of parent entity (type of number) l table - the data record entity data table name (type of string)
{ "name": "Gender", "value": "Miss" }, { "name": "FirstName", "value": "Dianne" }, { "name": "LastName", "value": "Straka" } ] } ] } { "recordid": 12345, "table": "detail", "records": [ { "fields": [ { "name": "ItemNumber", "value": "PSM002" }, { "name": "ItemDesc", "value": "PSM Production (unlimited)" }, { "name": "ItemUnitPrice", "value": "495.00" }, { "name": "ItemOrdered", "value": "2" }, { "name": "ItemTotal", "value": "990.
] }, { "fields": [ { "name": "ItemNumber", "value": "PSM005" }, { "name": "ItemDesc", "value": "Upgrade (Starter to Web)" }, { "name": "ItemUnitPrice", "value": "495.00" }, { "name": "ItemOrdered", "value": "1" }, { "name": "ItemTotal", "value": "495.00" } ] } ] } JSON New Record Lists Describes multiple lists of new data records (and their data field values (as name/value pairs)) to be added as data record entities to either existing data set or data record entities of a specific ID.
{ "fields": [ { "name": "ID", "value": "CU00048376" }, { "name": "Gender", "value": "M.
"recordid": 12345, "table": "detail", "records": [ { "fields": [ { "name": "ItemNumber", "value": "PSM002" }, { "name": "ItemDesc", "value": "PSM Production (unlimited)" }, { "name": "ItemUnitPrice", "value": "495.00" }, { "name": "ItemOrdered", "value": "2" }, { "name": "ItemTotal", "value": "990.00" } ] }, { "fields": [ { "name": "ItemNumber", "value": "PSM005" }, { "name": "ItemDesc", "value": "Upgrade (Starter to Web)" }, { "name": "ItemUnitPrice", "value": "495.
"value": "1" }, { "name": "ItemTotal", "value": "495.00" } ] } ] } ] JSON Content Item Identifier List Describes a list of content item/data record entity identifier pairs (as name/value pairs) for a specific content set entity.
JSON Data Record Identifier Describes a single data record entity identifier for a specific content item entity. The structure consists of an object with a single name/value pair: l record - the data record entity identifier (type of number) Example: { "record": 12345 } JSON Identifier List (with Email Parameters) Describes a list of identifiers for multiple data entities (specifically data record entities), along with additional parameters used specifically in an content creation operation for email.
Example: { "identifiers": [ 12345, 23456 ], "host": "mail.company.com", "user": "johns", "password": "password5", "sender": "john.smith@company.com", "useAuth": true, "useStartTLS": false, "useSender": true, "attachWebPage": true, "attachPdfPage": true } JSON HTML Parameters List Describes a list of parameters used specifically in the creation of web content.
l jobs - the job entities within the job set, consisting of an array of objects each with the following name/value pairs: l segments - the job segment entities within a job, consisting of an array of objects each with the following name/value pairs: l documentsets - the document set entities within a job segment, consisting of an array of objects each with the following name/value pairs: l documents - the document entities within a document set, consisting of an array of objects each with the followin
} ] } ] } ] }, { "segments": [ { "documentsets": [ { "documents": [ { "documentpages": [ { "contentitem": 789 } ] } ] } ] } ] } ] } JSON All-In-One Configuration Describes the configuration of an All-In-One operation as a series of name/value pairs representing the processes (data mapping, content creation, job creation and output creation) to be completed as part of the overall operation. The value in each pair contains the parameters for that specific process.
l datamining - data mapping configuration parameters, consisting of an object with the following name/value pairs: l l l identifier - the managed file identifier (type of number) or named identifier (type of string) of the data file config - the managed file identifier (type of number) or named identifier (type of string) of the data mapping configuration contentcreation - content creation configuration parameters, consisting of an object with the following name/value pairs: l identifiers - an array
Examples: { "datamining": { "identifier": "Promo-EN-1000.csv", "config": "Promo-EN.OL-datamapper" }, "contentcreation": { "config": "letter-ol.OL-template" }, "jobcreation": { "config": "4567" }, "outputcreation": { "config": "5678", "createOnly": true }, "printRange": { "printRange": "1-3, 6, 10" } } { "contentcreation": { "identifiers": [ 34567, 34568 ], "config": "letter-ol.
{ "datamining": { "identifier": 12345, "config": 23456 } } JSON Page Details Summary Describes a summary of the page details for a specific content set entity. Page details include the number of pages per media type, along with media specific properties including the name, size, width and height. Used specifically with the Content Set Entity service.
{ "count": 108, "media": { "name": "Plain Letter Paper", "size": "Letter", "width": "8.5in", "height": "11in" } } ] } JSON Page Details List Describes a list of the the page details and identifiers for each content item contained within a specific content set entity. Page details include the number of pages per media type, along with media specific properties including the name, size, width and height. Used specifically with the Content Set Entity service.
{ "count": 2, "media": { "name": "Plain A4 Paper", "size": "A4", "width": "210mm", "height": "297mm" } }, { "count": 1, "media": { "name": "Plain Letter Paper", "size": "Letter", "width": "8.5in", "height": "11in" } } ] }, { "id": 23456, "pages": [ { "count": 2, "media": { "name": "Plain A4 Paper", "size": "A4", "width": "210mm", "height": "297mm" } }, { "count": 2, "media": { "name": "Plain Letter Paper", "size": "Letter", "width": "8.
] JSON Data Mapping Validation Result Describes the result of a request to validate a data mapping operation, including a list of any errors that occurred (used specifically with the Data Mapping service).
method. Search rules can be added to a search rules list and can be used to match data entities based on specific criteria. This rules list also specifies an operator which determines whether all rules or only one rule in the list is required to be matched. Search rules can be based on data record values, data entity properties, finishing options, document length, template names and whether an entity's identifier is contained or not contained in a list of identifiers.
l l entity - the data entity type (value of either DATARECORDS, DATASETS, CONTENTITEMS, CONTENTSETS, JOBS or JOBSETS) (type of string) search - search criteria, consisting of an object with the following name/value pairs: l l operator - the search rule operator for the base list of rules (value of either AND or OR) (type of string) rules - a base list of search rules, consisting of an array of objects each with a specific rule sub-structure depending on the type of rule l sort - a list of sorting rule
Search rule objects with a type value of value contain the following name/value pairs: l type - the type of search rule (value of value) (type of string) l name - the name of the data field (type of string) l l value - the value of the data field (type of string, or array of strings when condition is value of either IN or NOT IN) condition - the comparison condition (value of either EQUAL, NOTEQUAL, LESS, GREAT, LESSEQUAL, GREATEQUAL, STARTSWITH, ENDSWITH, CONTAINS, LIKE, NLIKE, IN or NOT IN) (type of
l l l l l l l l l l type - the type of search rule (value of finishing) (type of string) frontcoating - the front coating of the media used (value of either UNSPECIFIED, NONE, COATED, GLOSSY, HIGH_GLOSS, INKJET, MATTE, SATIN or SEMI_GLOSS) (type of string) backcoating - the back coating of the media used (value of either UNSPECIFIED, NONE, COATED, GLOSSY, HIGH_GLOSS, INKJET, MATTE, SATIN or SEMI_GLOSS) (type of string) condition - the comparison condition (value of either EQUAL or NOTEQUAL) (type of
l type - the type of search rule (value of templatename) (type of string) l template - the name of the design template used for document (type of string) l condition - the comparison condition (value of either EQUAL or NOTEQUAL) (type of string) Search rule group objects contain the following name/value pairs: l l operator - the search rule operator for sub-list of rules in rule group (value of either AND or OR) (type of string) rules - a sub-list of search rules, consisting of an array of objects e
] } ] }, "sort": [ { "name": "LastName", "order": "ASC", "numeric": false, "type": "value" } ], "group": [ { "name": "Gender", "order": "ASC", "numeric": false, "type": "value" } ] } JSON Identifier Lists (with Sort Key) Describes a set of search results as a list of one or more sub lists, each containing a list of data entity identifiers along with a sorting key value for each entry.
Example: [ [ { "identifier": 1604, "sortkey": "NB|Vilma" }, { "identifier": 1282, "sortkey": "NF|Lenard" }, { "identifier": 1443, "sortkey": "NF|Lenard" }, { "identifier": 1000, "sortkey": "SK|Cathleen" }, { "identifier": 1121, "sortkey": "SK|Rachel" } ] ] JSON Operations List Describes a list of workflow operations (specifically asynchronous workflow operations) actively running on the server, each containing various properties including the type of workflow operation, it's starting time and it's current p
workflow operations.
"template": "business-card-ol" }, { "id": "134f55a5-85f5-41d5-a0d3-e033eda45cb5", "type": "EmailExportRestService", "startTime": 1482368638197, "progress": 5 }, { "id": "d52cf2b6-9ca7-44e6-b548-5b249dedf40d", "type": "JobCreationRestService", "subTask": "Job Creation", "startTime": 1482367723483, "progress": 77 }, { "id": "02fa495b-ed56-47ef-ac49-e63df298b10e", "type": "OutputCreationRestService", "subTask": "Output Creation", "startTime": 1482367851340, "progress": 34 }, { "id": "fb414be9-4ec5-463a-8429-93
Working Examples This section provides a number of working examples that demonstrate the use of the various resources and methods available in the PlanetPress Connect REST API. For help on getting started with the PlanetPress Connect REST API Cookbook and the working examples, see the Getting Started page.
Getting Started This guide provides many working examples to help illustrate the correct use of a given API/method. To achieve this, the guide uses HTML5 & JavaScript/jQuery syntax, and thus, some basic experience and knowledge of these technologies is assumed. HTML5: http://www.w3schools.com/html/ jQuery: https://jquery.com/ Help on installing and getting started with the working examples can be found on the Requirements & Installation and Structure of the Working Examples pages.
Requirements & Installation Requirements To use the PlanetPress Connect REST API Cookbook with Working Examples source you will require the following: 1. A working installation of PlanetPress Connect 2. Any modern web browser able to display HTML51 Warning If using Internet Explorer, you may find issues when using the working examples with PlanetPress Connect's Server Security Settings set to enabled.
Installation The working examples source comes pre-installed with PlanetPress Connect and can be located in a sub-directory of your existing PlanetPress Connect installation directory. To locate the source on Windows: 1. Open up Windows Explorer and navigate to the PlanetPress Connect installation directory followed by its plugins sub-directory. 2. Find the com.objectiflune.serverengine.rest.gui directory and navigate to its www subdirectory 3.
Structure of the Working Examples The working examples are designed to be complete examples, and will generally consists of one HTML5 file paired with a JavaScript/jQuery module which can be found in the examples//js/ sub-directory. Where any frequent or boilerplate functionality is commonly used across the examples, this has been moved to the common/js/common.js JavaScript/jQuery module.
The examples also make use of some simple CSS classes as defined in common/css/styles.css and HTML snippets for the presentation of output results.
HTML Input Placeholders & Multiple Value Fields In the working examples, HTML input elements make use of the placeholder attribute to help provide some indication of the type and format of the value expected to be entered / specified. The following table lists examples of placeholders commonly used in the working examples: HTML Expected Type Example Values l 2341 l 3 l 2341 l Promo-EN-1000.
Display of Working Example Results When a working example is run, any results will be displayed in a Results area that will appear below the working example existing HTML interface. For example: Note In some examples the same result will displayed in both plain and JSON structure based formats. This is to assist ease-of-use when working with outputs of one example that will be needed as an input to another example.
A working example can be run multiple times, and each time the results will be appended below allowing you to compare the output of varying inputs. The Clear button can be selected at any time to clear all existing results.
Using the Working Examples with Server Security If you have the Server Security Settings set to enabled in your PlanetPress Connect Server Preferences, then you may see the following dialog box initially display when working with the examples: In the event of this dialog box, just follow the instructions and either refresh the page or reauthenticate by running the Authenticating with the Server (Authenticate/Login to Server) working example covered under the Server Security & Authentication section.
Server Security & Authentication This section consists of a number of pages covering various useful working examples: 1. Authenticating with the Server See the Authentication Service page of the REST API Reference section for further detail. Note A complete listing including these examples can be found in the index.html file located at the root of the working example source code which contains links to all working examples.
Authenticating with the Server Problem Your PlanetPress Connect Server is configured to use server security, and you want to authenticate with the server to obtain the correct access to make future requests. Solution The solution is to create a request using the following URI and method type to authenticate with the server via the Authentication REST service: Authenticate/Login to Server /rest/serverengine/authentication/login POST Example HTML5 auth-login-server.