REST API Cookbook with Working Examples Version: 1.
REST API Cookbook with Working Examples Version 1.5 Last Revision: 17/01/2017 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 PReS Connect REST API Cookbook 7 Technical Overview 8 Workflow & Workflow Processes 9 Workflow Components 16 Workflow Operations 20 JSON Structures 21 Working Examples 32 Getting Started 33 Server Security & Authentication 42 Working with the File Store 47 Working with the Entity Services 77 Working with the Workflow Services 98 REST API Reference 210 Authentication Service 214 Content Creation Service 219 Content Item Enti
Content Set Entity Service 242 Data Record Entity Service 255 Data Set Entity Service 270 Data Mapping Service 280 Content Creation (Email) Service 296 File Store Service 307 Content Creation (HTML) Service 328 Job Creation Service 337 Job Entity Service 351 Job Set Entity Service 361 Output Creation Service 371 All-In-One Service 387 Copyright Information 399 Legal Notices and Acknowledgments 400 Page 6
Welcome to the PReS Connect REST API Cookbook This guide is aimed at technically experienced users who wish to learn and use the REST API available in PReS Connect version 1.5. The PReS 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 PReS Connect and the REST API.
Workflow & Workflow Processes In PReS Connect there are four main workflow processes: Data Mapping, Content Creation, Job Creation, and Output Creation. There is also an additional workflow process, named All-In-One, which embodies all four other 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 from a PDF/VT file using its internal meta data instead of a data mapping configuration.
Page 11
Content Creation The Content Creation process involves taking a number of data records (from a Data Set) combining it with a suitable design template, and producing a set or sets of content (Content Sets). If the content is for the email or web context then output can be published at this stage.
Job Creation The Job Creation process involves taking one or more content sets and applying a preset for organising/sorting/grouping them into sets of logical jobs (a Job Set). This includes data filtering and finishing options.
Output Creation The Output Creation process involves taking a set of jobs, applying a preset and generating the printed output.
All-In-One The following flowchart illustrates the potential inputs, outputs and workflows for the All-In-One process: Page 15
Workflow Components Each process in the overall PReS Connect workflow takes a series of inputs and produces output. These can be divided into Input Components and Data Entities.
Input Components Input components are used as input to a specific workflow process. The following table lists the types of input components used in the PReS 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 PReS Connect, but not all entities can be accessed through the REST API. The main types to be aware of when working with the API are Data Sets, Data Records, Content Sets, Content Items, Jobs Sets and Jobs. The following table lists these entity types in greater detail: Entity Description Data Set & Data Records 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.
Data entities can be produced as output from a workflow process and can then be used as input to another workflow process.
Workflow Operations Each individual process in the overall workflow process can potentially be a long running operation. Accordingly, an initial HTTP request is submitted to initiate the workflow operation, then additional requests are required to monitor progress and retrieve the final result.
JSON Structures The following table lists the various JSON structures used by the PReS Connect REST API: Name Example JSON Identifier { "identifier": 12345 } JSON Identifier (Named) { JSON Identifier List { "identifier": "Promo-EN-1000.
Name Example "value": "2015-12-31 23:59:59T-0500" } ] JSON Name/Value List { "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 [ { "id": 12345, "properties": [ { "name": "start", "value": "2015-01-01 00:00:00T-0500" }, { "name": "end", "value": "2015-12-31 23:59:59T-0500" }, ] }, { Page 22
Name Example "id": 23456, "properties": [ { "name": "start", "value": "2015-01-01 00:00:00T-0500" }, { "name": "end", "value": "2015-12-31 23:59:59T-0500" }, ] } ] JSON Record Content List { "id": 12345, "table": "record", "fields":[ { "name": "ID", "value": "CU00048376" }, { "name": "Gender", "value": "M.
Name Example ] } JSON Record Content Lists [ { "id": 12345, "table": "record", "fields":[ { "name": "ID", "value": "CU00048376" }, { "name": "Gender", "value": "M.
Name Example { "name": "Gender", "value": "Miss" }, { "name": "FirstName", "value": "Dianne" }, { "name": "LastName", "value": "Straka" } ] } ] JSON Content Item Identifier List { "identifiers": [ { "item": 12345, "record": 54321 }, { "item": 23456, "record": 65432 }, { "item": 34567, "record": 76543 } ] } JSON Data { Page 25
Name Record Identifier JSON Identifier List (with Email Parameters) Example "record": 12345 } { "identifiers": [ 12345, 23456 ], "host": "mail.company.com", "user": "johns", "password": "password5", "sender": "john.smith@company.
Name Example { // First Document in first DocumentSet in first JobSegment in first Job "documentpages": [ { // First DocumentPages in first Document in first DocumentSet in first JobSegment in first Job "contentitem": 111 }, { // Second DocumentPages in first Document in first DocumentSet in first JobSegment in first Job "contentitem": 222 } ] }, { // Second Document in first DocumentSet in first JobSegment in first Job "documentpages": [ { // First DocumentPages in second Document in first DocumentSet in
Name Example "segments": [ { // First JobSegment in second Job "documentsets": [ { // First DocumentSet in first JobSegment in second Job "documents": [ { // First Document in first DocumentSet in first JobSegment in second Job "documentpages": [ { // First DocumentPages in first Document in first DocumentSet in first JobSegment in second Job "contentitem": 789 } ] } ] } ] } ] } ] } JSON HTML { Page 28
Name Example Parameters List "section": "Section 1", "inline": "ALL" } JSON All-InOne Configuration { "datamining": { "identifier": "Promo-EN-1000.csv", "config": "Promo-EN.OL-datamapper" }, "contentcreation": { "config": "letter-ol.
Name Example "name": "Plain A4 Paper", "size": "A4", "width": "210mm", "height": "297mm" } }, { "count": 108, "media": { "name": "Plain Letter Paper", "size": "Letter", "width": "8.
Name Example "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.
Working Examples This section provides a number of working examples that demonstrate the use of the various resources and methods available in the PReS Connect REST API. For help on getting started with the PReS 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 PReS Connect REST API Cookbook with Working Examples source you will require the following: 1. A working installation of PReS 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 PReS Connect's Server Security Settings set to enabled.
Installation The working examples source comes pre-installed with PReS Connect and can be located in a sub-directory of your existing PReS Connect installation directory. To locate the source on Windows: 1. Open up Windows Explorer and navigate to the PReS 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. You should now be exploring the following or similar location: C:\Program Files\Obje
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 PReS 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 PReS 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.