google-api-dotnet-client icon indicating copy to clipboard operation
google-api-dotnet-client copied to clipboard

Exception when calling RequestSync method

Open cjenp opened this issue 4 years ago • 2 comments

Hi, I am trying to implement Request Sync for Smart Home actions. On user account linking I report that the user has 2 devices. I test the devices with the smarthome test suite and all the tests pass. Part of the tests is calling RequestSync when the user add/deletes/renames the device (in my case I am deleting 1 device). I execute the code you see bellow and I can see in logs that I get a new SYNC request from Google and I also successfully return the correct response (I can see that the user now only has 1 device on the Home Graph Viewer). So far so good.

Now, after around 1min, I get a GoogleApiException on the line var response = await requestSyncRequest.ExecuteAsync();

Google.Apis.Requests.RequestError
Precondition check failed. [400]
Errors [
	Message[Precondition check failed.] Location[ - ] Reason[failedPrecondition] Domain[global]
]

I have also tried replacing ExecuteAsync() with Execute(), but I get the same exception. The only thing that solves the problem is setting RequestSyncDevicesRequest.Async__ = true. But from what I can read on the property documentation, this just means I will not receive any error responses. I do not think that ignoring error responses is a good solution, but I do not see any alternative currently. Suggestions?

Implementation

var request = new RequestSyncDevicesRequest {AgentUserId = userId};
var requestSyncRequest = homeGraphServiceService.Devices.RequestSync(request);
var response = await requestSyncRequest.ExecuteAsync();

Environment details

  • Programming language: C#
  • OS: Windows 10
  • Language runtime version: .NET Core 3.1
  • Package version: 1.49.0.2142 (also tested on 1.57.0.2640)

cjenp avatar Jun 22 '22 11:06 cjenp

It's unlikely that this is an issue with the client library (given that it's a fairly simple situation), and the maintainers of this repository don't know the details of every API. I can't see anything wrong with the way you're using the library though.

I would double check that the AgentUserId value is appropriate, and follow one of the Smart Home support routes to ask for more details.

jskeet avatar Jun 22 '22 13:06 jskeet

Hi, thank you for the quick response. I managed to figure it out. For anyone who might have this kind of problem in the future: As intended, RequestSync will trigger the Sync request to your fulfillment solution. The method call await requestSyncRequest.ExecuteAsync(); will complete when you have sucessfully responded to the sync requst.

My problem was that my code for RequestSync was blocking the part of the code that responds to the Sync request. Which means there was a timeout after 1min. This was also indicated by the error BACKEND_FAILURE_URL_TIMEOUT in Logs Explorer.

Thank you again @jskeet and sorry for bothering you :slightly_smiling_face:

cjenp avatar Jun 23 '22 08:06 cjenp