Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.

Moderators: ArturoRobles, ArturoRobles

Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.

I use PM version 3.1. The PHP example at ... doc_uid.7D

for downloading a generated output document, does not work. I can get the document information , but when downloading, It redirect me to the login page . It seems that downloading needs authentication while in the example nothing is done to authenticate when downloading the document.

thank you for helping me

Hello surena,

By directly going to the link you won't be able to download, as you are not logged into ProcessMaker. The example reads the content of the file in the code and copies the data into another file on your local server which you will be able to access. The other way is to download the output document as an attachment in your browser, add the following code:
Code: Select all
if ($oRet->status == 200) {
   $link = 'http://' .$_SERVER['SERVER_NAME']. '/sysworkflow/en/neoclassic/' . $oRet->response->app_doc_link;
   //Download binary PDF file:
   $handle = fopen($link, "rb") or die("Error: Unable to open file:\n$link");
   $contents = stream_get_contents($handle) or die("Error: Unable to get file:\n$link");
   //serve up the PDF file for download as attachment in user's browser:
   header('Content-Description: File Transfer');
   header('Content-Type: application/octet-stream');
   header('Content-Disposition: attachment; filename="' . $oRet->response->app_doc_filename . '"');
   header('Content-Transfer-Encoding: binary');
   header('Expires: 0');
   header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
   header('Pragma: public');
   header('Content-Length: ' . strlen($contents));
   print $contents
   die;            //die here so that ?> at end of script isn't printed
Hope this helps.

Best Regards,
Zainab Sabunwala
Last edited by zainab on Wed Apr 05, 2017 3:09 am, edited 1 time in total.
I checked the sid=XXXXXXXXXXXX solution , but it did not work. I get the sessionid with login webservice and append it to the end of document url, but when downloading the document it gives me 302 result code and redirects me to login page
This one took me a while to figure this out. Here is what you need to do.
Edit the processmaker/workflow/engine/config/env.ini file with a plain text editor on your ProcessMaker server and add the following line:
Code: Select all
disable_download_documents_session_validation = 1
The URL to download an Output Document should be:

For example:
http://localhost:320/sysworkflow/en/neo ... 246mt4r7f2

If you want to prevent your web browser from using a cached copy of the document, then you can randomly generate a number using rand() and add random=XXXXXXX to the URL, like this:
http://localhost:320/sysworkflow/en/neo ... 246mt4r7f2

There are two ways to get the PHPSESSID, you can either login with web services as shown in ... atic_Login or you can add the following trigger to your process:
Code: Select all
$userId = @@USER_LOGGED;
$result = executeQuery($sql);
@@sessionId = $result[1]['LOG_SID'];
In your script, call PUT /cases/{app_uid}/execute-trigger/{tri_uid} to execute the above trigger and then call GET /cases/{app_uid}/variables to get the value of the sessionId variable.
Hello Amos,

I am struggling with the similar kind of problem. I am basically generating an output document and sending the link of output document via email. When the receiver clicks on the link he is redirected to the login page. I tried your method and it still redirects me to the login page. Kindly help me here. Any idea why this could be happening?

Best Regards,
Zainab Sabunwala
If you are sending the link in an email, then the login session has already expired when it is clicked. It is better to not include the PHPSESSID=XXXXXXXX part if using it in a link in an email.
If you don't care about security than use this setting in your env.ini file:
Code: Select all
disable_download_documents_session_validation = 1  
Another option is to create a custom script and add a link in your email to execute that custom script which automatically logins with web services and then redirects to:
REST API Question

I am currently looking at developing a portlet for[…]

Everybody wants to be famous, but nobody wants to […]

Hi, I attached a sample config file, Please check […]

Error clicking on Participated

Hi, I attached a sample config file, Please check […]