Integrating ColdFusion and the REST API for Harvest (TimeSheet Service); Accessing XML in CF
Note: This blog post is from 2009. Some content may be outdated--though not necessarily. Same with links and subsequent comments from myself or others. Corrections are welcome, in the comments. And I may revise the content as necessary.Often we will find API docs for a given service without any reference to a CFML example. I just experienced that, and while I offered a suggested example to the vendor, I wanted to share it here in case it never gets posted. At least if someone Googles in the future they may find this. Also, I conclude with some insights into learning more about the power of XML processing in CF.
I'll demonstrate here calling the REST API for the Harvest online timesheet application. (If you would want to point me to another alternative timesheet app, no need as I'm happy. I realize there are many. Indeed, I list many of them on my CF411 site section for time tracking tools and services.)
Thanks for taking the time to document this!
I realize this is an old post, but as you say at the beginning, when I searched for Harvest and ColdFusion this was right there waiting to help me. :)
I actually started using Harvest based on a comment you wrote somewhere about it. Now that I have been using it for a few months, I realize that it is great at letting me enter my data without getting in my way, but I wanted more functionality out of the reporting side.
I have never interfaced with a REST web service before, but thanks to this post and the nature of CF in that it makes things so easy, I was able to create a custom export report for myself that I am happy with within a couple of hours.
Thanks!
By the way, your HTML link for "Harvest API docs pages" towards the top of this post has a typo so it isn't clickable.
Glad to have helped, and to have turned you on to Harvest. I still use it daily.
And I fixed that typo (it said a href- instead of a href=. Fixed that, and confirmed there are no other instances of that mistake anywhere else. Thanks.)
If you ever come up with something that you may think would be of generic interest, that you may submit to them or post on your own somewhere, feel free to come in here and leave word about it for others. Until again.
web.archive.org/web/20061104094542/http%3A%2F%2Fwww.adobe.com/devnet/coldfusion/articles/xmlxslt.pdf
Thanks for the nice article Charlie.
https://github.com/n...
So I'm curious if you (or any readers of this blog entry) have put together any cool harvest api calls that perhaps report on info that the current harvest UI just does not provide. I have dozens of requests I want to build to get info I need that the web interface either doesn't provide, or only with lots of steps.
There doesn't seem to be any place where such are listed. (Actually, someone might point out the community hub, https://github.com/h...&-Hacks, but that seems to be more about projects like yours. BTW, have you sought to get yours listed there?)
As for your holding off on sharing on the hub, well, I'd think anything (showing CFML integration there) is better than nothing, and being open source, people understand that it may not necessarily be robust (I think folks judge that by the number of users, number of committers, etc.), so I'd think "go for it". Who knows, it may take time and that would give more chance for others to find your library here or elsewhere. And perhaps they (the harvest hub managers) might even do some vetting themselves before accepting it also.
Anyway, keep up the good work. I may be exploring the library soon for some of my harvest api exploration interests.
- the url used in the call to the API must now be an HTTPS url
- where I showed calling for a day's timesheet entries, using /account/daily/245/2009", you no longer need "/account" there, so it would be daily/245/2009
- there has since been added an additional querystring option, "?slim=1", which the docs say should cause it to "return only tracked time, and no assignments" ?slim=1", but I find that without it, the result is huge and never easily processed. So you should try always to use it, as in /daily/245/2009?slim=1
And to be clear, this is indeed still referring only to the "v1" Harvest API. There is a new V2 API, and the old one will stop working in Jan 2019 (https://www.getharve...)
Note that authentication is quite different in the new API, and you have choices between oauth2 and a "personal access token" (more at https://help.getharv...authentication-api/authentication/authentication/).
I am showing here a quick, simple example of using the token approach (see the docs for more on that, and getting yours), where you would fill in below the values for "your_account_id" and "your_token". The end of the URL shows a rest path which returns info similar to the whoami feature in the v1 API:
<cfhttp url="https://api.harvesta...">
<cfhttpparam type="header" name="Harvest-Account-ID" value="your_acount_id">
<cfhttpparam type="header" name="Authorization" value="Bearer your_token">
<cfhttpparam type="header" name="User-Agent" value="Harvest API Example">
</cfhttp>
<cfdump var="#DeserializeJSON(cfhttp.filecontent)#">
And note that the result that comes back is a json packet, so the dump deserializes to an array of structs for you. You can read the API docs to learn about different rest URLs. For instance, to get info about a project, you just pass in the projectid by using this as the URL:
https://api.harvesta...