Post

2 followers Follow
1
Avatar

Querying a Clarizen Timesheet in PHP with Ordering

Hello,

I'm trying to query timesheet data with ordering, but the parameter OrderBy (Ascending|Descending) is not working. Below is my current PHP scripts. Thank you!

$client = new SoapClient(" https://api.clarizen.com/v1.0/Clarizen.svc?WSDL", array('trace' => 1, "cache_wsdl" => WSDL_CACHE_DISK));

// Login

$params = array(

"userName"=>"xxx",

"password"=>"xxx",

"options"=>array(

"ApplicationId"=>"app name",

"PartnerId"=>"partner id"

)

);

$response = $client->Login($params);

$responseJSON = json_encode($response);

echo $responseJSON . "<br/><br/>";

// Set SessionId

$sessionId = $response->LoginResult->SessionId;

$header = new SoapHeader(' http://clarizen.com/api';, 'Session', array("ID"=>$sessionId));

$client->__setSoapHeaders($header);

// Get Projects

$LeftStartDate = array (

"FieldName" => "ReportedDate");

$MinDate = "2012-10-01";

$RightStartDate = array (

"Value" => new SoapVar ($MinDate, XSD_DATETIME, "dateTime", " http://www.w3.org/2001/XMLSchema")));

$StartDateCondition = array (

"LeftExpression" => new SoapVar ($LeftStartDate,SOAP_ENC_OBJECT, "FieldExpression", " http://clarizen.com/api/queries"),

"Operator" => "GreaterThanOrEqual",

"RightExpression" => new SoapVar ($RightStartDate,SOAP_ENC_OBJECT, "ConstantExpression"," http://clarizen.com/api/queries")));

$LeftEndDate = array (

"FieldName" => "ReportedDate");

$MaxDate = "2013-08-01";

$RightEndDate = array (

"Value" => new SoapVar ($MaxDate, XSD_DATETIME, "dateTime", " http://www.w3.org/2001/XMLSchema")));

$EndDateCondition = array (

"LeftExpression" => new SoapVar ($LeftEndDate,SOAP_ENC_OBJECT, "FieldExpression", " http://clarizen.com/api/queries"),

"Operator" => "LessThan",

"RightExpression" => new SoapVar ($RightEndDate,SOAP_ENC_OBJECT, "ConstantExpression"," http://clarizen.com/api/queries")));

$AndCondition = array (

"Conditions" => array ( new SoapVar ( $StartDateCondition,SOAP_ENC_OBJECT, "Compare", " http://clarizen.com/api/queries" ),

new SoapVar ( $EndDateCondition,SOAP_ENC_OBJECT, "Compare", " http://clarizen.com/api/queries" )

));

$params = array(

"Fields" => array(

"ReportedBy.DisplayName",

"CreatedBy.DisplayName",

"Duration.Length",

"RegularHours",

"ReportedDate",

"LastUpdatedOn",

"WorkItem.Name",

"Comment",

"WorkItem.Billable",

" WorkItem.ProjectType.Name",

" WorkItem.Project.ProjectSize.Name",

"WorkItem.Project.ProjectManager.DisplayName",

"WorkItem.Project.Manager.DisplayName"

),

"TypeName" => "Timesheet",

"Orders" => array(

array(

"FieldName" => "ReportedDate",

"OrderBy" => "Descending"

)

),

"Where" => new SoapVar ($AndCondition, SOAP_ENC_OBJECT, "And", " http://clarizen.com/api/queries"),

"Paging" => array(

"PageNumber" => 0,

"PageSize" => 20

)

); 

$request[] = new SoapVar($params, SOAP_ENC_OBJECT, "EntityQuery", " http://clarizen.com/api/queries");

$executeResponse = $client->Execute(array("request"=>$request));

$responseJSON = json_encode($executeResponse);

Gilbeys Caronongan Answered

Please sign in to leave a comment.

3 comments

0
Avatar

I believe the ‘Orders’ array is not properly constructed. The 'Orders' is an array of 'OrderBy' objects, each containing:

'FieldName' & 'Order' string values.

Attached a Fiddler screenshot of the correct structure. You may also check the API reference on  https://api.clarizen.com/v1.0/Docs/index.aspx

Ophir Kenig 0 votes
Comment actions Permalink
0
Avatar

How about the order by nested fields in the 'Orders' parameter? Example, order by "WorkItem.Project.ProjectManager.DisplayName"

Thanks for your help!

Gilbeys Caronongan 0 votes
Comment actions Permalink
0
Avatar

Ordering by nested fields in the API is not supported. Sorry...

Ophir

Ophir Kenig 0 votes
Comment actions Permalink