Page 1 of 1

ProcessMap via REST API

Posted: Tue Aug 27, 2019 6:40 am
by jemiris
Hi,

Is there any way to get the process map and its properties via rest API
The attached image below:
processmap-rest.png
processmap-rest.png (68.81 KiB) Viewed 12181 times

Re: ProcessMap via REST API

Posted: Tue Aug 27, 2019 10:19 pm
by amosbatto
Install my extraRest plugin. Then call GET extrarest/session-id to get the session ID.

Then, you can create a <iframe> whose src is set to the URL:
http://{domain_or_ip}/sys{workspace}/{lang}/{skin}/designer?prj_uid={process_uid}&prj_readonly=true&app_uid={app_uid}&sid={session_id}

Example:
Code: Select all
<iframe src="http://example.com/sysworkflow/en/neoclassic/designer?prj_uid=6135378175a8dcdca9a2641037096319&prj_readonly=true&app_uid=9777918985a8dddbf884236088281261&sid=1234567890abcde1234567890abcde"></iframe>

Re: ProcessMap via REST API

Posted: Wed Aug 28, 2019 12:34 am
by jemiris
That's a great answer. Thanks and I have another question that if the session gets expired how can I get another session-id.
I need some clarifications on that. Could you please explain it?

Re: ProcessMap via REST API

Posted: Wed Aug 28, 2019 10:29 pm
by amosbatto
jemiris wrote: Wed Aug 28, 2019 12:34 am I have another question that if the session gets expired how can I get another session-id.
You have to login again with oAuth2 (or use the refresh token to get a new access token), and then call the endpoint again to get another Session ID.

Re: ProcessMap via REST API

Posted: Thu Aug 29, 2019 5:07 am
by jemiris
Thanks a lot.
My Questions:
1. How does the endpoint know that when the session get's expiry in the processmaker?
2. As of now, we are mentioning the session-id for any user. So how the rest API gets the session-id?
3. Is it getting the session id of the admin user or how is it getting?
4. Why I have these questions it's because in the web service name called "Automatic Login" https://wiki.processmaker.com/index.php ... atic_Login. In web services, we have to specify the username and password to get the particular user's session id. So my question is how the REST API will the particular user id?

Re: ProcessMap via REST API

Posted: Thu Aug 29, 2019 10:04 pm
by amosbatto
jemiris wrote: Thu Aug 29, 2019 5:07 am 1. How does the endpoint know that when the session get's expiry in the processmaker?
If the login session has expired (after 24 minutes of inactivity), then when you try to open the process map in an iframe, it will be redirected to the ProcessMaker login screen. The user can login, and then the iframe will redirect back to the process map.
If you want to avoid making the user login manually, then you should call a REST endpoint just to verify that the login session is still valid, before trying to display the process map in an iframe. If the call to the REST endpoint fails, then you need login using oAuth2 and then get a new session ID. Then, use that new session ID to display the process map in an iframe.
jemiris wrote: Thu Aug 29, 2019 5:07 am 2. As of now, we are mentioning the session-id for any user. So how the rest API gets the session-id?
3. Is it getting the session id of the admin user or how is it getting?
You can only get the session ID for the user who logged in using oAuth2. If you logged in as "admin", then you are getting the session ID for "admin". You can't get session IDs for other users.

If you want to do actions for other users, then the extraRest plugin has endpoints for Process Supervisors to do actions like route cases, assign cases, set variables, etc. for other users.
jemiris wrote: Thu Aug 29, 2019 5:07 am 4. Why I have these questions it's because in the web service name called "Automatic Login" https://wiki.processmaker.com/index.php ... atic_Login. In web services, we have to specify the username and password to get the particular user's session id. So my question is how the REST API will the particular user id?
That example from the web services documentation is attaching the session ID to the URL, just like I'm telling you to do with REST.

Web services is the same as REST. You need to login as each user to get his/her session ID.

Re: ProcessMap via REST API

Posted: Wed Sep 11, 2019 9:04 am
by jemiris
Is there any way to get the process map as HTML?

Re: ProcessMap via REST API

Posted: Wed Sep 11, 2019 11:00 pm
by amosbatto
I don't know of an easy way. You would have to read the info from the database to draw the map.

Re: ProcessMap via REST API

Posted: Wed Sep 11, 2019 11:49 pm
by jemiris
Thanks for Information

Re: ProcessMap via REST API

Posted: Sat Sep 21, 2019 1:59 am
by jemiris
Yes, I have used this API to get session id and process map.

https://sourceforge.net/p/pmcommunity/c ... session-id

but via rest API it is not the right way to handle it

Re: ProcessMap via REST API

Posted: Mon Sep 23, 2019 8:41 pm
by amosbatto
jemiris wrote:Yes, I have used this API to get session id and process map.

https://sourceforge.net/p/pmcommunity/c ... session-id

but via rest API it is not the right way to handle it
You can use an <iframe> to display the process map in an external web page like this:
Code: Select all
<iframe src="http://example.com/sysworkflow/en/neoclassic/designer?prj_uid=6135378175a8dcdca9a2641037096319&prj_readonly=true&app_uid=9777918985a8dddbf884236088281261&sid=1234567890abcde1234567890abcde"> 
That doesn't work for you?

Re: ProcessMap via REST API

Posted: Tue Sep 24, 2019 12:05 am
by jemiris
Thanks but I thought there will be a another way to get

Re: ProcessMap via REST API

Posted: Tue Sep 24, 2019 2:15 pm
by amosbatto
The process map is generated by the Designer::index() function defined in workflow/engine/controllers/designer.php

You can create your own REST endpoint which uses the code in that function.

Re: ProcessMap via REST API

Posted: Tue Sep 24, 2019 11:54 pm
by jemiris
Thanks a lot

Re: ProcessMap via REST API

Posted: Thu Sep 26, 2019 8:55 am
by jemiris
But this page code renders the HTML page which has dynamic js and CSS files. So it's better to display via iframe.

I have tried via iframe as below
Code: Select all
<iframe id="processMapFrame" name="processMapFrame" src="http://localhost:8080/sysjemiris/en/neoclassic/designer?prj_uid=6946716305d4a85a4125961038662114&prj_readonly=true&app_uid=4552307125d8c7ef5c652e7093079525&sid=7439575195d8cab80466c25035220712" 
    width="100%" height="700px" frameboarder="1px">
x-frame options.png
x-frame options.png (78.84 KiB) Viewed 11757 times

Re: ProcessMap via REST API

Posted: Thu Sep 26, 2019 9:39 pm
by amosbatto
What version of PM do you have? It used to work.

I assume this is a cross origin problem. In the Designer::index() function defined in workflow/engine/controllers/designer.php, add the following line:
header("Access-Control-Allow-Origin: *");

Re: ProcessMap via REST API

Posted: Fri Sep 27, 2019 1:00 am
by jemiris
yes, this works with iframe. But I have included the designer.php file inside my custom REST and it returns the HTML page, not the process map as below
Code: Select all
<!DOCTYPE html>
<head>
    <!-- translations -->
    <script type="text/javascript" src="/translations/translationsMafe.js"></script>


    <link rel="stylesheet" type="text/css" href="/lib/css/mafe-92a59a3-f9f10aa.css" />
    <link rel="stylesheet" type="text/css" href="/css/neoclassic-pm3.css" />
        <script type="text/javascript">
        var prj_uid = "6946716305d4a85a4125961038662114";
        var app_uid = "4552307125d8c7ef5c652e7093079525";
        var consolidated = "0";
        var enterprise = "0";
        var prj_readonly = "true";
        var credentials = "eyJhY2Nlc3NfdG9rZW4iOiI1YTAyNDMzZjQ5YzRmMTUyZWMwNDJjY2ZhMGI3N2VhMDA0NGJiOWRlIiwiZXhwaXJlc19pbiI6ODY0MDAsInRva2VuX3R5cGUiOiJiZWFyZXIiLCJzY29wZSI6InZpZXdfcHJvY2Vzc2VzIGVkaXRfcHJvY2Vzc2VzICoiLCJyZWZyZXNoX3Rva2VuIjoiODM3YTNjZmY4NGE0YWExOWJkM2FmYmM4NzRjZWRmYWE2ZGUzNjhhOCIsImNsaWVudF9pZCI6IngtcG0tbG9jYWwtY2xpZW50IiwiY2xpZW50X3NlY3JldCI6IjE3OWFkNDVjNmNlMmNiOTdjZjEwMjllMjEyMDQ2ZTgxIn0=";
        var distribution = "0";
        var SYS_SYS = "jemiris";
        var SYS_LANG = "en";
        var SYS_SKIN = "neoclassic";
        var HTTP_SERVER_HOSTNAME = "http://localhost:8000";
    </script>
    <script type="text/javascript" src="/lib/js/mafe-92a59a3-f9f10aa.js"></script>
    


</head>
<body onresize="resizingFrame();">
<!--<div class="ui-layout-north">-->
     <div class="loader"></div>
     <section class="navBar" id="idNavBar">
        <div class="head"></div>
        <nav>
            <ul id="idNavBarList">

            </ul>
        </nav>

    </section>
    <div class="bpmn_shapes">
    </div>
<!--</div>-->
<div id="p-center-layout"/>
    <!--BODY-->
    <div class="ui-layout-center tab-content" id="div-layout-canvas">
    </div>

    <section class="content" id="idContent">

        <div class="content_controls">
            <div class="head"></div>
            <ul id="contentControlList">
                
            </ul>
        </div>
        <div class="bpmn_shapes_legend">
            <div class="head"></div>
        </div>
    </section>
<SCRIPT src="/jscore/src/PM.js" type=text/javascript></SCRIPT>
<SCRIPT src="/jscore/src/Sessions.js" type=text/javascript></SCRIPT>
</body>
</html>