Error on send email endpoint. Precondition check failed - gmail-api

I have got an application up and running, and sending emails using the API with no problem at all. But for specific customers, I am getting the following error and I cannot manage to reproduce it. Could you give me further details about the problem? It works for most of my customers
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Precondition check failed.",
"reason" : "failedPrecondition"
} ],
"message" : "Precondition check failed.",
"status" : "FAILED_PRECONDITION"
}
I am using the Java Client library from Google, and this is how my code looks I followed the Google guides:
MimeMessage content = emailService.createEmail(sendEmailRequest);
Message message = createMessageWithEmail(content);
gmail.users().messages().send(ME, message).execute();
The path that the client is hitting is this one {userId}/messages/send and these are the scopes the application asks:
openid email https://www.googleapis.com/auth/gmail.send
Thanks in advance

Related

Positive Scenario Usage of StatusReport google home trait

In Google documentation, they explained how to use "statusReport" trait for query intent when there is an error or exception occurred for a device. I'm facing issue while using it for success status without any exception. I tried sending the response with simple status as SUCCESS, Google Home is saying the response "Sorry Unable to reach device".
The response which I was sending:
{ "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf", "payload": { "devices": { "123": { "online": true, "status": "SUCCESS" } } } }
can anyone help me to solve this issue?
After looking at the code, it is clear that you’re not sending the correct & complete response of the StatusReport trait. Your response contains the online attribute but missing the currentStatusReport attribute (it is required as it defines the current error statuses of the associated device IDs). For more information, visit https://developers.google.com/assistant/smarthome/traits/statusreport?hl=en

Create datasource in azure search returns 403 Forbidden

I have a search service running on azure in a free tier. On this service I already have a datasource, and indexer and an index defined.
I'd like to add another datasource (and index + indexer). When I do this (using postman) I get 403 Forbidden without any other error message.
This is the POST I made to this url - https://my-search-service-name.search.windows.net/datasources?api-version=2016-09-01:
"Content-Type": "application/json",
"api-key": "API-KEY-HERE"
{
"name": "datasource-prod",
"description": "Data source for search",
"type": "azuresql",
"credentials": { "connectionString" : "Server=tcp:xxxx.database.windows.net,1433;Initial Catalog=xxxxx_prod;Persist Security Info=False;User ID=xxxxxx;Password=xxxxxx!;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" },
"container": {"name": "DataAggregatedView"},
"dataChangeDetectionPolicy": {
"#odata.type" : "#Microsoft.Azure.Search.HighWaterMarkChangeDetectionPolicy",
"highWaterMarkColumnName" : "ChangeIndicator"
},
"dataDeletionDetectionPolicy": {
"#odata.type" : "#Microsoft.Azure.Search.SoftDeleteColumnDeletionDetectionPolicy",
"softDeleteColumnName" : "isDeleted",
"softDeleteMarkerValue" : "0"
}
}
Using the same request, with different name and database name worked perfectly and generated the existing (first) datasource. This error (403) - not even got the error message - happens only when I try to define a second datasource.
As I can understand from documentation, free search tier allows 3 datasources. Anyone had this issue? Any help/direction is appreciate!
Thank you.
Make sure you're using the admin API key. It looks like you may be using a query key.

Exception handling from my custom filter in google cloud endpoints

Whenever a cloud endpoint throws an exception app engine handles those exceptions and sends standard response as follows.
{
"error" : {
"message" : "java.lang.ArithmeticException: / by zero",
"code" : 503,
"errors" : [ {
"domain" : "global",
"reason" : "backendError",
"message" : "java.lang.ArithmeticException: / by zero"
} ]
}
}
But I want to handle those exception in my custom filters and set relevant status code to response.
Also sometimes I want to redirect to different url. How could I do that with endpoints?
What you should do is set up an error handler as explained here. That way you can catch all of the standard exceptions thrown by endpoints or whatever custom exceptions you throw yourself.

Better error message when missing required fields from request

When missing a required field currently ProtoRPC returns a message like this:
{
"error": {
"code": 400,
"errors": [
{
"domain": "global",
"message": "Error parsing ProtoRPC request (Unable to parse request content: Message CombinedContainer is missing required field api_key)",
"reason": "badRequest"
}
],
"message": "Error parsing ProtoRPC request (Unable to parse request content: Message CombinedContainer is missing required field api_key)"
}
}
Is it possible to provide a better error message? Ideally, "missing required field api_key" in this example.
According to the Google Code Issue Tracker and Github issues this was once being worked on. However, there does not appear to be any activity.
I'd greatly appreciate any solutions or workarounds.
As of today, the ProtoRPC still returns the same unraised error which makes it harder for one to return a customized error response.
A simple workaround is to make the Message fields optional and enforce the requirement constraint somewhere in the endpoint handler/method.
So instead of;
class Request(Message):
name = StringField(1, required=True)
Set 'name' as optional,
class Request(Message):
name = StringField(1)
The requirement constraint can then be enforced in the endpoint handler method by simple if statements OR by mapping these fields to a Datastore entity that requires these fields, hence will allow exception handling of BadValueError and return a more customized error response.
Example:
try:
account = Account(name=request.name)
account.put()
except BadValueError:
return Response(status=False, message='Missing field "name"')

how to set an OCR language in Google Drive

I need to upload image into Google Drive including the OCR feature.
The problem with the setOcrLanguage method. I need to specify Hebrew language and based on ISO 639-1 codes its should be "heb".
I'm getting the response
"code" : 400,
"errors" : [ {
"domain" : "global",
"location" : "ocrLanguage",
"locationType" : "parameter",
"message" : "Invalid Value",
"reason" : "invalid"
} ],
Any idea what should be the code or where I can get the list of avaliable codes?

Resources