Post

3 followers Follow
0
Avatar

API v2.0 iClarizen.Query() doesn't exist?

Hello,

I’m having trouble trying to execute queries against the new v2.0 api. According to the documentation, the iClarizen service interface should contain a Query method, however the wsdl does not actually define this method. Please advise.

https://success.clarizen.com/hc/en-us/articles/205711818-Web-Service-API-Guide-Version-2#iclarizen

The iClarizen interface contains five (5) methods:
• Execute (BaseMessage)
• Login (Username, Password, LoginOptions)
• Logout
• Metadata (MetadataMessage)
• Query (QueryExpression) – MISSING METHOD

Pickens, Brian M Answered

Official comment

Avatar

Hi Brian,

You can use the "EntityQuery" or the "CZQLQuery" to query the API.

From our success site:

"CZQLQuery — A new query language to easily perform queries via the API. CZQL supports all the query operators previously available via the EntityQuery API and also the new AggregateQuery capabilities."

For examples of how the CZQLQuery works go here. The examples are for the REST API but it also works in the SOAP.

 

I hope this helps,

Elad

Elad Franklin
Comment actions Permalink

Please sign in to leave a comment.

17 comments

0
Avatar

FileInformation also seems to be missing the Content property.

Pickens, Brian M 0 votes
Comment actions Permalink
0
Avatar

Sorry, this does not answer my question. I've already built up my EntityQuery object. However now I need to send it. The example listed in the documentation presumably uses the QueryClient.Query() method, which as I've stated, appears to be non-existant in the 2.0 API. I've pasted the relevant code snippet from your documentation below:

Notice in the below generated interface the Query() method doesn't exist on the iClarizen object as the documentation states (the example of which is in my original post)

Now check your WSDL you provided from which I generated my code in visual studio. Notice there is no Query operation defined:

https://api2.clarizen.com/v2.0/Clarizen.svc

Pickens, Brian M 0 votes
Comment actions Permalink
0
Avatar

I would like to again add, the "byte[] Content" property also seems to missing from the FileInformation object.

Pickens, Brian M 0 votes
Comment actions Permalink
0
Avatar

Hi Brian,

I think the documentation is not up to date and I will make sure it is fixed.

Please try to use "Execute" instead of "Query".

If this doesn't work please share the query you are trying to execute and I will help you make it work.

Regarding the file upload action, I will take a look at the documentation. If you need a working example to upload a file to Clarizen I can share it with you. 

 

I hope this help,

Elad

Elad Franklin 0 votes
Comment actions Permalink
0
Avatar

Okay I've updated my code to use Execute. Now, I'm assuming your code snippet for setting the byte[] data of a FileInformation is also out of date?

Pickens, Brian M 0 votes
Comment actions Permalink
0
Avatar

Hi Brian,

Looks like it is.

As I mentioned, if you want a working example please let me know.

 

Kind regards,

Elad

Elad Franklin 0 votes
Comment actions Permalink
0
Avatar

There are many query examples so you need to be more specific. Try to use the EntityQuery example in the documentation and use Execute instead of Query.

Here is an example how to upload a file to Clarizen and connect it to a project:

 

public class FileUploader
{
private readonly Clarizen _clarizenService;

public FileUploader(Clarizen clarizenService)
{
_clarizenService = clarizenService;
}
/// <summary>
/// Upload a file to Clarizen and link it to a project
/// </summary>
/// <param name="filePath">The location of the file in the local file system</param>
/// <param name="filename">The full file name to be displayed in Clarizen. For example "file.txt"</param>
/// <param name="projectId">External Id of the project the file will be connected to</param>
public void Upload(string filePath, string filename, string projectId)
{
UploadAndLinkFileToWorkItem(filePath, filename, projectId);
}

private void UploadAndLinkFileToWorkItem(string filePath, string filename, string projectId)
{
var documentId = UploadFile(filePath, filename);
LinkFileToWorkItem(documentId, projectId);
}

private EntityId UploadFile(string filePath, string filename)
{
var content = File.ReadAllBytes(filePath);
var createMessage = new CreateMessage
{
Entity = new Entity()
{
Id = new EntityId { TypeName = "Document" },
Values = new[]
{
new FieldValue {FieldName = "Content", Value = content},
new FieldValue {FieldName = "Name", Value = filename}
}
}
};

var results = _clarizenService.Execute(new BaseMessage[] { createMessage });
var createResult = ((CreateResult)results[0]);

return createResult.Id;
}

private void LinkFileToWorkItem(EntityId documentId, string projectId)
{
var createMessage = new CreateMessage
{
Entity = new Entity
{
Id = new EntityId { TypeName = "AttachmentLink" },
Values = new[]
{
new FieldValue {FieldName = "Document", Value = documentId},
new FieldValue{FieldName = "Entity", Value = new EntityId{TypeName = "Project", Value = projectId}}
}
}
};
_clarizenService.Execute(new BaseMessage[] { createMessage });
}
}
Elad Franklin 0 votes
Comment actions Permalink
0
Avatar

I also need an example for downloading a file as well. This was my v1.0 code which doesn't work because the Content property is no more.

DownloadMessage download = new DownloadMessage();
download.DocumentId = new EntityId();
download.DocumentId.TypeName = "Document";
download.DocumentId.Value = documentId;

var sessionHeader = new SessionHeader();
var callOptions = new CallOptions();
var callInfo = new CallInfo();
DownloadResult result = (DownloadResult)clarizenClient.Execute(sessionHeader, callOptions, callInfo, new BaseMessage[] { download })[0];

if (result.Success)
{
return result.FileInformation.Content;
}
else
{
return null;
}
Pickens, Brian M 0 votes
Comment actions Permalink
0
Avatar

Hi Brian,

You should look a the "Url" property and download the file using that URL.

 

I hope this helps,

Elad

Elad Franklin 0 votes
Comment actions Permalink
0
Avatar

Hi Elad,

 

Could you provide some sample SOAP request for executing query using execute method in API v2 version. Most of the samples provided are of C# or java code.

Regards,

Venkata Chakradhar P

Venkata Chakradhar 0 votes
Comment actions Permalink
0
Avatar

Hi Venkata,

What kind of examples are you looking for? Any specific coding language that is not C# nor Java?

Elad Franklin 0 votes
Comment actions Permalink
0
Avatar

I am looking for SOAP request samples. Application works on the SOAP webservices.

As Query method is not available in v2 version and as per this discussion thread Entity Query should be instead. So I need sample SOAP request for Entity Query in execute method.

In v1 for query we are using the below sample query request soap message. I am looking for similar SOAP message for v2 version under execute method.

<Query xmlns="http://clarizen.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<queryExpression xmlns:q1="http://clarizen.com/api/queries" xsi:type="q1:EntityQuery">
<q1:Paging>
<q1:PageNumber>0</q1:PageNumber>
<q1:PageSize>1000</q1:PageSize>
</q1:Paging>
<q1:Fields>
<string>ExternalID</string>
<string>Description</string>
<string>C_ExpenseType</string>
<string>C_ProjectCode</string>
<string>C_Quantity</string>
<string>C_Rate</string>
<string>LocalAmount</string>
<string>ExchangeRate</string>
<string>Receipt</string>
<string>C_ReceiptDate</string>
<string>C_ReceiptQuantity</string>
<string>C_UnitOfMeasure</string>
<string>C_R12Category</string>
<string>C_R12Subcategory</string>
<string>C_R12Task</string>
<string>C_R12Language</string>
<string>C_R12Studio</string>
<string>C_ERPCategoryName</string>
<string>C_RechargeBU</string>
<string>C_RechargeDP</string>
<string>C_RechargeGA</string>
<string>C_RechargeLE</string>
<string>C_RechargeST</string>
</q1:Fields>
<q1:Orders>
<q1:OrderBy>
<q1:FieldName>ExternalID</q1:FieldName>
<q1:Order>Ascending</q1:Order>
</q1:OrderBy>
</q1:Orders>
<q1:TypeName>Expense</q1:TypeName>
<q1:Where xsi:type="q1:Compare">
<q1:LeftExpression xsi:type="q1:FieldExpression">
<q1:FieldName>ExpenseSheet</q1:FieldName>
</q1:LeftExpression>
<q1:Operator>Equal</q1:Operator>
<q1:RightExpression xsi:type="q1:ConstantExpression">
<q1:Value xsi:type="EntityId">
<TypeName>ExpenseSheet</TypeName>
<Value>45rmcnfhdt1diwqwuhif64j7e2942</Value>
</q1:Value>
</q1:RightExpression>
</q1:Where>
</queryExpression>
</Query>

 

 

Venkata Chakradhar 0 votes
Comment actions Permalink
0
Avatar

Hi,

You can use the "EntityQuery" or the "CZQLQuery" to query the API.

From our success site:

"CZQLQuery — A new query language to easily perform queries via the API. CZQL supports all the query operators previously available via the EntityQuery API and also the new AggregateQuery capabilities."

For examples of how the CZQLQuery works go here. The examples are for the REST API but it also works in the SOAP.

For EntityQuery you can see examples in previous posts in this thread.

 

I hope this helps,

Elad

 

Elad Franklin 0 votes
Comment actions Permalink
0
Avatar

Hi Team,

We have tested the below SOAP UI Request in Execute method similar to Query method and it is working. 

Below is the sample request. Hope it would help.

<Execute xmlns="http://clarizen.com/api">
<request>
<BaseMessage xsi:type="EntityQuery">
<TargetOrganizationIds xsi:nil="true" />
<Paging xsi:nil="true" />
<Fields>
<string>Description</string>
<string>CreatedOn</string>
<string>CreatedBy</string>
<string>LastUpdatedOn</string>
<string>LastUpdatedBy</string>
</Fields>
<Orders xsi:nil="true" />
<Relations xsi:nil="true" />
<TypeName>Expense</TypeName>
<Where xsi:type="Or">
<Conditions>
<Condition xsi:type="Compare">
<LeftExpression xsi:type="FieldExpression">
<FieldName>ExpenseSheet</FieldName>
</LeftExpression>
<Operator>Equal</Operator>
<RightExpression xsi:type="ConstantExpression">
<Value xsi:type="xsd:string">xxxxxxxxxxxxxxxxxx</Value>
</RightExpression>
</Condition>
</Conditions>
</Where>
</BaseMessage>
</request>
</Execute>

 

Regards,

Venkat P

Venkata Chakradhar 0 votes
Comment actions Permalink
0
Avatar

Hi Elad,

Couple of weeks back we tried to "EntityQuery" using SOAP API v2 and it worked as expected and I have posted the same request in this thread. But when we are testing this again we are getting error as "Cannot create an abstract class.". So want to know if there is any change at Clarizen end for entity query.

Venkata Chakradhar 0 votes
Comment actions Permalink