Post

1 follower Follow
0
Avatar

Facing issue during query to Clarizen objects from salesforce through http call out

Hi,

I am referring the Clarizen Rest Api Guide  https://success.clarizen.com/entries/57664667-Clarizen-REST-API to make call out to Clarizen. However I became successful to send login request and received "UserId,sessionId,organizationId,serverTime,licenseType" as the response with [Status=OK, StatusCode=200] .

But I am facing the issue when I want to make a query to fetch Timesheet object fields after getting successfully Login response.

This is the exception which I am receiving during the callout 

"errorCode": "LoginFailure", 

"message": "Authentication cookie is missing. Did you forget to login?", 

"referenceId": "hmHpu9JvvEKr~SiJGCaAVw"

This is my code which I have used to make query

String strRequest = '{typeName:"Timesheet",fields:["createdBy"]}'; 

httpReq.setHeader('Content-Length', String.valueOf(strRequest.length())); 

httpReq.setHeader('Content-Type', 'text/JSON');

httpReq.setMethod('POST'); 

httpReq.setEndpoint(' https://api2.clarizen.com/v1.0/services/data/entityQuery'); 

httpReq.setHeader('SESSIONID', 'USID='+sessioinId); 

httpReq.setBody(strRequest);

Http http = new Http();

HttpResponse res = http.send(httpReq);

Please help me.

I have tried by modifying the request in so many ways but same exception I am getting.

Thank you in advance

John Gray Answered

Please sign in to leave a comment.

17 comments

0
Avatar

the session ID should be placed in a cookie:

httpReq.setHeader("Cookie", "USID=" + sessionId);

Eyal Post 0 votes
Comment actions Permalink
0
Avatar

Hi Eyal,

Can you please suggest where is the mistake in the Json format  - 

{typeName:"Timesheet",fields:["createdBy","ApprovalDate","CreatedOn","Duration","EntityType","ReportedBy","ReportedDate"],where:{ _type: "Compare",leftExpression: {fieldName: "ApprovalDate"},  operator: equal, rightExpression: {value: "2014-08-14"}}}

since I am getting the exception like -

{
"errorCode": "Internal",
"message": "An internal error has occurred, the error was logged and will be examined.",
"referenceId": "4A2N0rm_Wk2TKQzwhf00Xg"
}

Thanks!!

John Gray 0 votes
Comment actions Permalink
0
Avatar

That's invalid JSON. Wrap the equal in quotes: operator: "equal"

Eyal Post 0 votes
Comment actions Permalink
0
Avatar

Hi Eyal,

I have found the mistake.It is working now.

Thanks!!

John Gray 0 votes
Comment actions Permalink
0
Avatar

Hi Eyal,

Can you please specify how to use multiple conditions in "WHERE" clause using "AND/OR" operator.

Thanks!!

John Gray 0 votes
Comment actions Permalink
0
Avatar

Something like this should work:

..

where: {

_type: “And”,

conditions: [{<.. first condition…>},{<…second condition…>}]

}

 

Eyal Post 0 votes
Comment actions Permalink
0
Avatar

Hi Eyal,

This is my body

strJSON= '{typeName: "TimeSheet",'+

'fields: ["Duration","ReportedBy.DisplayName"],'+

'where:{ _type: "Compare",'+

'leftExpression: {fieldName: \'ReportedDate\'}, '+

' operator: \'Equal\','+

' rightExpression: {value: "2014-08-13"}'+

'},'+

'{ _type: "Compare",'+

'leftExpression: {fieldName: \'ReportedDate\'}, '+

' operator: \'Equal\','+

' rightExpression: {value: "2014-08-14"}'+

'}'+

'}';

John Gray 0 votes
Comment actions Permalink
0
Avatar

        "where": {

                "_type": "Or",

          "conditions": [

            {

              "leftExpression": {

                "fieldName": "ReportedDate"

              },

              "operator": "Equal",

              "rightExpression": {

                "value": "2014-08-13"

              }

            },

            {

              "leftExpression": {

                "fieldName": "ReportedDate"

              },

              "operator": "Equal",

              "rightExpression": {

                "value": "2014-08-14"

              }

            }

          ]

        }

 

Eyal Post 0 votes
Comment actions Permalink
0
Avatar

Hi Eyal,

First of all thanks for your quick response.

Can you please take a look to the Json

strJSON2 = '{typeName: "TimeSheet",'+

["createdBy.Name","ApprovalDate","CreatedOn","Duration","EntityType","ReportedBy.DisplayName","ReportedDate","ApprovedBy.DisplayName"],'+

'fields: ["Duration","ReportedBy.DisplayName"],'+

'where:{ _type: "AND",'+

'conditions: [{leftExpression: {fieldName: \'ReportedDate\'}, '+

' operator: \'Equal\','+

' rightExpression: {value: "2014-08-13"}},{leftExpression: {fieldName: \'ReportedDate\'},operator: \'Equal\', rightExpression: {value: "2014-08-14"}}]'+

'}'+

'}';

 

But it is giving the exception-

"errorCode": "Internal",
"message": "An internal error has occurred, the error was logged and will be examined.",
"referenceId": "z1DFpD4ojE6oHy8tixOMEg"

John Gray 0 votes
Comment actions Permalink
0
Avatar

please send the json "as is" (final output) so I won't have to re-build it. 

Eyal Post 0 votes
Comment actions Permalink
0
Avatar

Hi Eyal,

Thanks a ton!!!

It is working which you have just sent. 

John Gray 0 votes
Comment actions Permalink
0
Avatar

Also, try to use "And" (Note the case) and see if this works. 

Eyal Post 0 votes
Comment actions Permalink
0
Avatar

Hi Eyal,

Yes , I ave used "AND" , and it is working.

Thanks!!

John Gray 0 votes
Comment actions Permalink
0
Avatar

Hi Eyal,

First of all thanks a lot.What you suggest I have done and got successful to make query and fetch the appropriate data from Clarizen.

I need one more suggestion.

I have got the list of data as the response of query  which present in "1st page" with the page size "100".

 

"paging": {
"pageNumber": 1,
"pageSize": 100,
"hasMore": true
}

If I want to receive all the possible results of the query, not only which are present in "1st page".

What will be the way to receive that.

Please suggest.

Thanks!! 

 

John Gray 0 votes
Comment actions Permalink
0
Avatar

No problem. Always glad to help!

You have 2 options:

  • Implement paging and get the next page when "hasMore" is true

  • If you don't want to implement paging, just increase the page size to a larger number. But this is still limited and you may need to ask for the next page if your results grow.

 

To implement paging perform the query this way:

First request:

'{typeName:"Timesheet", field: ..., .. , paging: { pageSize: 1000 }};

Subsequent requests:

while (resultPaging.hasMore)

{

  //Send the same query again with a different page

   '{typeName:"Timesheet", field: ..., .. , paging: resultPaging};

}

where resultPaging is the paging object you received in the previous result.

 

Eyal Post 0 votes
Comment actions Permalink