Search code examples
asanaasana-connect

Event Sync Token (412 response status )


I'm using RestTemplate to make the GET call to asana's REST Api. By using postmen when i'm calling:

https://app.asana.com/api/1.0/events?resource=PROJECT_ID

I'm getting a message and a sync token ( this is the same case when the sync token is too old and needs to be renewed ).

By using the RestTemplate, when the sync token is too old \ its the first call i'm making and I need a sync token, I'm getting a 412 response "Prediction Faild". This happens also in postman, but i'm getting along with the "error" message the new sync token.

With the RestTemplate all i'm getting is this error:

Aug 06, 2015 3:56:55 PM org.springframework.web.client.RestTemplate handleResponseError WARNING: GET request foPROJECT_ID21650756795165" resulted in 412 (Precondition Failed); invoking error handler Exception in thread "main" org.springframework.web.client.HttpClientErrorException: 412 Precondition Failed at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:90) at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:494) at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:451) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:409) at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:385) at availo.worker.asana.MainTask.getEvents(MainTask.java:86) at availo.worker.asana.MainTask.getProjects(MainTask.java:76) at availo.worker.asana.MainTask.main(MainTask.java:115)

Any suggestions?

Thanks!


Solution

  • This worked for me. It lets you read the message that comes with the error:

    restTemplate.setErrorHandler(new DefaultResponseErrorHandler(){ protected boolean hasError(HttpStatus statusCode) { return false; }});