ECMS - PHP Code for using Integration Server

This document provides sample code using PHP to send and parse web services Integration Server API.


#!/usr/bin/php

<?php

$host = 'test.imaging.wisc.edu';
$protocol = 'https';
$base_path = '/integrationserver/v1/';

$user = 'not a real username';
$pass = 'not a real password';

$user_header = 'X-IntegrationServer-Username';
$pass_header = 'X-IntegrationServer-Password';
$session_header = 'X-IntegrationServer-Session-Hash';

$base_url = $protocol . '://' . $host . $base_path;


// open a session --------------------------------------------------------------
$cmd = 'connection';
$url = $base_url . $cmd;

$ch = get_configured_curl_handler( $url );

curl_setopt( $ch, CURLOPT_HEADER, 1 );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
	$user_header . ': ' . $user,
	$pass_header . ': ' . $pass,
));

$response = curl_exec( $ch );
$info = curl_getinfo( $ch );

curl_close( $ch );

$headers = get_headers_from_curl_response( $response );
$session = $headers[ $session_header ];

// get the workflow queues --------------------------------------------------------------
$cmd = 'workflowQueue';
$url = $base_url . $cmd;

$ch = get_configured_curl_handler( $url );

curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
	$session_header . ': ' . $session,
	'Accept: application/json',
));

$response = curl_exec( $ch );
$info = curl_getinfo( $ch );

curl_close( $ch );

$response = json_decode( $response );
//print_r( $response );

// get the view of workflow --------------------------------------------------------------
$cmd = 'view/301YWCV_00YQLX10X000Y6S';
$url = $base_url . $cmd . '?' . http_build_query( array( 'category' => 'WORKFLOW' ) );

$ch = get_configured_curl_handler( $url );

//curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'POST' );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
	$session_header . ': ' . $session,
	'Accept: application/json',
));

$response = curl_exec( $ch );
$info = curl_getinfo( $ch );

curl_close( $ch );

$response = json_decode( $response );
print_r( $response );


// close a session --------------------------------------------------------------
$cmd = 'connection';
$url = $base_url . $cmd;

$ch = get_configured_curl_handler( $url );

curl_setopt( $ch, CURLOPT_HEADER, 1 );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'DELETE' );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
	$session_header . ': ' . $session,
));

$response = curl_exec( $ch );
$info = curl_getinfo( $ch );

curl_close( $ch );



// useful functions --------------------------------------------------------------
function get_configured_curl_handler( $url ) {
	$ch = curl_init( $url );

	curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
	curl_setopt( $ch, CURLOPT_VERBOSE, 1 );
	
	return $ch;
}

function get_headers_from_curl_response( $response ) {
	$headers = array();
	$header_text = substr($response, 0, strpos($response, "\r\n\r\n"));

	foreach( explode( "\r\n", $header_text ) as $i => $line ) {
		if ( $i === 0 ) {
			$headers[ 'http_code' ] = $line;
		} else {
			list( $key, $value ) = explode( ': ', $line );
			$headers[$key] = $value;
		}
	}
	return $headers;
}
?>




Keywords:Imaging Imaging System Experience ImageNow perceptive content ecm ecms enterprise content management imaging imagenow perceptive pdp code xample integration server   Doc ID:97810
Owner:CRAIG S.Group:ECMS
Created:2020-02-10 16:01 CDTUpdated:2020-04-29 13:49 CDT
Sites:ECMS
Feedback:  0   0