Post

2 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

Please sign in to leave a comment.

11 comments

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
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
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
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
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
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
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
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