Even though it’s rather simple, unfortunately it doesn’t work.
The error I’m getting is: Error: Cannot create Collection from response that does not have resources
And I don’t really understand how to fix it, because apparently it’s not a bad request.
The gid is set properly, I checked it and also tried it out in the interactive demo on the Asana API docs - it works there.
To me it sounds like the Asana library somehow can’t handle the response and tries to convert it to a collection, even though that endpoint doesn’t return one (at least not on the first one, as it should return the sync token.)
What am I doing wrong? Is there a way to tell the client to not convert the response to a collection and just give me the raw response?
Welcome to our community forum. This is a bug with our node client library error handling. Essentially this call expects a sync token to be provided. EX:
When you make an initial request to getEvents you will get a 412 error that contains a a sync token in it. It looks like the following:
{
"errors": [
{
"message": "Sync token invalid or too old. If you are attempting to keep resources in sync, you must fetch the full dataset for this query now and use the new sync token for the next sync."
}
],
"sync": "bdd8....11:0"
}
You will then need to use this to make a follow up request to get events.
Here’s a work around:
// First get events request -> this will return an error with a sync token
client.events.get(project.gid).then(result => {
// Second get events request -> extract the sync token from the first call and use it to fetch the events
client.events.get(project.gid, result["sync"]).then(result => {
console.log(result);
})
})
I don’t personally recommend this approach since it’s hacky → we are using another method in client.events called get which doesn’t throw an error hence why we are able to call result["sync"]. The method you were using getEvents throws an error that does not contain the sync token. Instead the sync token is contained in the result of that call so result._response.sync but since we are not able to extract that sync token we use our get method instead.
Hi @John_Vu,
Thank you for the info. I’ll probably have to use your “hacky” solution as a temporary workaround, but I do plan to use the new library once it’s production ready. My app needs some refactoring as well, so the new Asana JS client might be a good opportunity to do that.
Is there a rough ETA when the new client will be production ready?
We estimate we should have a production ready new Node.js client library by end of summer. We’ll announce it in or forums when it is ready. For now, the workaround should offer you a nice temporary solution to solve your problem.