• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Scheduling a task with REST API in Publishing Server

New Here ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Dear community,

I developped last year a REST API to create/update/trigger Framemaker Publishing Server 2019 tasks from an automation server. Apparently the interface has changed with the 2020 version, and I'm struggling to get it running following the Adobe user guide.

 

A working example in groovy language of a POST request to create a task is as follows:

 

httpRequest (
        contentType: 'APPLICATION_JSON', 
        httpMode: 'POST', 
        ignoreSslErrors: true, 
        requestBody: json_body,
        responseHandle: 'NONE', 
        url: "http://my_node:7000/v16/tasks", 
        wrapAsMultipart: false
    ) 

Replacing json_body and my_node by my specific task configuration and host where I run the server. I don't use authentication and that code is enough to successfully create a task.

Where I struggle at the moment is to run a task. The example in the user guide suggests using the task ID (earlier version 2019 required the task name):

http://<FMPS_server>:<port>/v16/queue/scheduleTask/:id

Therefore I'm scheduling the task as follows:

httpRequest (
   contentType: 'APPLICATION_JSON', 
   httpMode: 'POST', 
   ignoreSslErrors: true, 
   //requestBody: body.toString(), -> NO BODY
   responseHandle: 'NONE', 
   url: "http://my_node:7000/v16/queue/scheduleTask/:my_task_id", 
   wrapAsMultipart: false
) 

I'm fetching the id with a GET command that retrieves all tasks details, resulting in the following url (random id as example):

"http://my_node:7000/v16/queue/scheduleTask/:603e488ebe24e438bcf7dd0b"

I might be doing a silly mistake somewhere.

 

Many thanks in advance

 

TOPICS
Publishing , Scripting

Views

526

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Employee , Mar 03, 2021 Mar 03, 2021

Hi @Marc5C0A 

There was a small typo with the URL, Please remove ": " before giving taskid .

For eg : 

http://my_node:7000/v16/queue/scheduleTask/603e488ebe24e438bcf7dd0b

 

POST /v16/queue/scheduleTask/{{YourTaskid}}

Further, You can also save your taskid while fetching json response of Create Task  API.

I hope it solves your issue.

Thanks
Pulkit Nagpal

Votes

Translate

Translate
Adobe Employee ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Hi @Marc5C0A 

There was a small typo with the URL, Please remove ": " before giving taskid .

For eg : 

http://my_node:7000/v16/queue/scheduleTask/603e488ebe24e438bcf7dd0b

 

POST /v16/queue/scheduleTask/{{YourTaskid}}

Further, You can also save your taskid while fetching json response of Create Task  API.

I hope it solves your issue.

Thanks
Pulkit Nagpal

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Hi Pulkit,

Issue solved, thanks.

Now moving to the next step, when running the task, I have a Pre-publish script uploaded which takes as an input an XML file in DITA format and converts it to .FM after applying the right structure from a template. This input file is located in the same directory of the script. However, as I can see in the 2020 version, the Pre-publish script is copied to the windows temp folder and executed from there:

Running pre-publishing extendscript: C:\Users\my_user\AppData\Local\Temp\test\4184\my_pre_publish_script.jsx

Giving me the according error that it can't find the input XML file anymore as it's not present in the Temp folder.

Is this an expected behavior? It used to work to specify a relative path on included files in the pre-publish script:

#target framemaker
#targetengine main
#include "My_relative_path/helper_script.jsx"

// path to input XML file in the same directory
var path_repo = (new File($.fileName)).parent.fsName + "\\";
var input_file = "my_input_file.xml";

// my code

Why is the script executed from the Temp folder and not from the folder I'm uploading it? This had worked before in the 2019 version.

 

Thanks,

Marc

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Hi Marc,

I need clarification on your workflow, It would be better if you can email me your query on punagpal@adobe.com , It would be a better medium of communication for your workflow.

Thanks
Pulkit Nagpal

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Except answering on this forum may help the rest of us working with FrameMaker Publishing Server.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Will post answers  here for everyone once I have clear details

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

Dear all,

For completeness I post here the conclusions and next steps for my use case:

Framemaker 2020 as the earlier 2019 version need a windows user logged in to run, this defeats the purpose of automation because e.g. every morning a user needs to log in to our server machines so that the publishing can happen.
As opposed to Publishing Server 2019 in the 2020 version we can't provide the path of the Pre (and Post) Publish scripts, they are saved as objects in the server database.
Include files and input files needed by the scripts are of course not saved in the database, which means absolute paths need to be given in the pre/post-publish scripts. Which is not so nice.
For my use case, this implies:
Include files with relative paths won't work anymore, so all previous scripts need to be adapted.
My example script in 2019:

#target framemaker
#targetengine main
#include "My_relative_path/helper_script.jsx"

var path_repo = (new File($.fileName)).parent.fsName + "\\";
var input_file = "my_input_file.xml";
var output_file = "Topics\\output.fm";

/* calling foo() from helper_script.jsx which parses the input XML file, applies a structure given by a template and saves it as output.fm inside Topics folder, which is published together with the rest of the components of the book */
foo(path_repo, input_file, output_file);

For my script to work with 2020 I need to pre-compile it with python or another enviroment so that the script contains absolute paths to the included files (the absolute path changes depending which machine runs the task). Another alternative discussed during the meeting was to inline the code so that no includes are necessary. I would like to avoid this last one.
I have to mention that I'm running the pre-publish script to process my input XML and saving it as .FM with publishing server because I did not find a way to call the script from command line. If that feature would be available I would just call the script from the automation server (jenkins) and right after call the request to run the publishing server task with REST API to publish the pdf.

My ideal solution if I could pass a.jsx file to run it with framemaker would be something like:

// Code running in continuous integration server (jenkins)

// Here I call the script
CALL C:\\path_to_exe\\framemaker.exe path_to_script\\my_script.jsx

// Here I schedule the task to publish the PDF
httpRequest (
contentType: 'APPLICATION_JSON',
httpMode: 'POST',
ignoreSslErrors: true,
responseHandle: 'NONE',
url: "http://my_node:7000/v16/queue/scheduleTask/:my_task_id",
wrapAsMultipart: false
)


Thanks for your support so far,

Marc

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

Hi Marc, .jsx and .jsxbin scripts in the startup folder load automatically when FrameMaker starts. You might use this as a way to mimic calling a script from the command line. Make your command line program copy your script to the startup folder and then launch FrameMaker. The script will execute, then you can programmatically remove the script from the startup folder when it is done. -Rick

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

LATEST

This may not be directly related to what you are trying to do, but I am using some event handlers to do pre- and post-processing with FMPS 2019 (I am not sure if it works in 2020):

Notification (Constants.FA_Note_PostPublishDitamap, true);
Notification (Constants.FA_Note_PrePublishDitamap, true);

function Notify (note, object, sparam, iparam) {
    
    var mapxml;
    
    switch (note) {
        
        case Constants.FA_Note_PostPublishDitamap:
        
            if ((iparam) && (iparam.constructor.name === "Book")) {
                BC_PPD.callFunctions (iparam, object);
            }
            break;
            
        case Constants.FA_Note_PrePublishDitamap:
        
            // Load the map into an XML object to capture the metadata.
            mapxml = CP.loadXml (object.Name);
            if (mapxml.errors.length === 0) {
                BC_PPD.mapxml = mapxml.xml.bookmeta;
            }
            else {
                BC_PPD.mapxml = <bookmeta/>;
            }
            break;            
    }
}

Note that I have left out some of the code for clarity, but the idea is to capture anything you need before the publishing starts; here I am grabbing the book meta data from the map itself and storing it in an XML object. This object will be available to me after the book is created and captured by the post-processing event. After my book functions are run, the publishing process will automatically continue and I will get my PDF, etc.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines