Post

0 followers Follow
0
Avatar

Extracting attachments

I would like to use the soap api to extract some attachments from clarizen.  So far, I've gotten SoapClient to dump me out a list of items, each of which looks something like this:

          object(stdClass)#12 (2) {

            ["Id"]=>

            object(stdClass)#13 (2) {

              ["TypeName"]=>

              string(8) "Document"

              ["Value"]=>

              string(36) "bb2ef360-c673-41e7-89fa-11c811a05d6e"

            }

            ["Values"]=>

            object(stdClass)#14 (0) {

            }

          }

When I add an attachment on the website, this list grows, so I'm pretty sure I'm looking in the right spot.  My question is, how can I actually download an attachment to where my script lives?  I know PHP, but I'm a SoapClient newbie

Thanks

Phil

Phil Romov Answered

Please sign in to leave a comment.

12 comments

0
Avatar

Also, I've given the REST API a shot as well, but I am having an issue running files/download.  It says missing DocumentId, even though I am supplying one....  Please see attached screenshot.  Any clues/pointers will be greatly appreciated!

Phil Romov 0 votes
Comment actions Permalink
0
Avatar

Hi Phil,

Thanks for sharing that.

You may also use DownloadMessage with the DocumentId (type name and id) if you do prefer to use the SOAP API.

Hope this helps,

Ophir

Ophir Kenig 0 votes
Comment actions Permalink
0
Avatar

Ophir,

Thanks for the tip!  One other related question:

For documents, right now I can do services/data/query with something like "SELECT Name FROM Document" and then using the id I can go /services/file/download?DocumentID=<id> to get a download link for my files

Is there a similar scheme for Emails?  Or is everything I need located in the Email entity, e.g. "Select Name,Subject,Comment,PlainText,SentBy,<etc> from Email" ?

 

Phil Romov 0 votes
Comment actions Permalink
0
Avatar

One more thing... via the API, can I get the tracking # that is associated with an attachment?  Is it possible to have one attachment be linked to more than one tracking #?

Phil Romov 0 votes
Comment actions Permalink
0
Avatar

I think I can do all of that using czql:

SELECT Name, (SELECT Name from Documents) FROM Task

However, let's say I also want to get the associated emails for this task (which don't seem to have a useful relation like Emails for them)

I want to do something like:

SELECT Name, EmailSubject, EmailOtherFields FROM Task JOIN Email ON Task.id = Email.AttachedTo.id

but it doesn't seem like czql supports joins.  Would I have to first get my list of Task entities, then a separate czql query to get a list of Email entities, and then script the logic to join them in PHP or something similar?  Is there a better way?

Thanks

Phil Romov 0 votes
Comment actions Permalink
0
Avatar

this should work:

SELECT Name, (SELECT Subject from AttachedEmails ) FROM Task

Querying relations is the alternative for joins in the CZQL API. You just need to know the name of the relation (in this case AttachedEmails)

 

Eyal Post 0 votes
Comment actions Permalink
0
Avatar

Hi Phil,

Some more information you may find useful:

  1. Emails are not saved as files. You don't need to 'download' them, you should have all the information on their properties.
  2. As for the Tracking no. you mentioned, I'm not sure what you meant. A Document can be attached to more than one Clarizen object, each of those is described by a different Attachment link object having (the attachment link itself) a unique ID.
  3. Retrieving class (Clarizen type) relations can be done with a metadata call (check the REST manual) like:
    curl https://../services/metadata/describeMetadata? typeNames=WorkItem&flags=relations,fields

Hope this helps,

Ophir

Ophir Kenig 0 votes
Comment actions Permalink
0
Avatar

Ophir, thanks, I've also been using describeEntities and describeEntityRelations.  By tracking # I meant the SYSID.  I really like what you guys have done with czql, making a light query language accessible via rest to avoid the super-verbosity of soap!

Phil Romov 0 votes
Comment actions Permalink
0
Avatar

Speaking of which, is there anything like SELECT *?  Right now I'm doing a describeEntities | grep name to get a list of "columns" I can select, but selecting all columns (element attributes) with a wildcard could be pretty handy...

Phil Romov 0 votes
Comment actions Permalink
0
Avatar

We intentionally not enabled a SELECT * to make sure clients ask only for the fields they really need. However, there are situations where getting all fields is indeed useful and we might revisit this decision in the future. 

Regarding files, if you're dealing with small files (under 5MB in size), you can get their content directly when retrieving the document entities by asking for the "Content" field. This field will contain a base64 encoded version of the file.

 

Eyal Post 0 votes
Comment actions Permalink