Gmail API, cannot remove "SENT" label from email - gmail-api

I cannot remove the "SENT" label from any email.
I used PHP classes but it doesn't matter because it occurs even in test page of users_messages.modify.
This is my PHP code:
$mods = new Google_Service_Gmail_ModifyMessageRequest();
$mods->setAddLabelIds(['UNREAD']);
$mods->setRemoveLabelIds('SENT');
$message = $gmailService->users_messages->modify($userId, $messageId, $mods);
I think it could be a general Gmail API error.
I can remove all the others labels but not "SENT". Try it with the follow "Request body":
{
"removeLabelIds": ["SENT"],
"addLabelIds": ["UNREAD"]
}
I got this ERROR 400 reply from the server:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidArgument",
"message": "Invalid label: SENT"
}
],
"code": 400,
"message": "Invalid label: SENT"
}
}

According to this google forum, there is no way of removing the SENT label in Gmail API.

Related

Google calendar api gives 404 error and does not return any data

I was trying the following sample
https://ej2.syncfusion.com/react/documentation/schedule/data-binding/#configuring-scheduler-with-google-api-service
I have used my own calendar id and public key
The program runs but displays blank calendar
It is not displaying my events
When I inspected the developer console, I found the following api error
{
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Not Found"
}
],
"code": 404,
"message": "Not Found"
}
Why is it not finding any data?

Google Auth apis returns OPERATION_NOT_ALLOWED 400

I am using this API
https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=[API_KEY]
I have pass correct token and param same as in documentation but still, it returns 400 OPERATION_NOT_ALLOWED
https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=[API_KEY]
Param:-
{
"email": "test#test.com",
"password": "123123",
"returnSecureToken": true
}
Response
{
"error": {
"code": 400,
"message": "OPERATION_NOT_ALLOWED",
"errors": [
{
"message": "OPERATION_NOT_ALLOWED",
"domain": "global",
"reason": "invalid"
}
]
}
}
Go to firebase console -> authentication -> sign-in method
and then enable email/password providers

How to delete draft message using gamil api?

I am using API
var request = gapi.client.gmail.users.drafts.delete({
'userId': userId,
'id': draftId
});
request.execute(function(resp) { });
always getting error
"domain": "global",
"reason": "notFound",
"message": "Not Found"

Gmail api returns 404 error when calling message.get

Gmail API history.list is returning messageId's that return 404 when message.get is called.
I call history.list with "INBOX" label and "history/messagesAdded" fields. I then call message.get with each of the messageId's returned. Some of them return valid messages, others return the following exception:
Google_Service_Exception
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Not Found"
}
],
"code": 404,
"message": "Not Found"
}
}
What would cause this? It seems like we just retrieved the messageId there isn't enough time for them to now be permanently deleted.
As explained in the comments, this can happen if the message was deleted. This can be checked in the messagesDeleted array return by gmail's history.list, just make sure you send the appropriate historyTypes (or doesn't send any at all).
{
"history": [
{
"id": "69014",
"messagesAdded": [
{
"message": {
"id": "165a2cd1a5b308b9",
"threadId": "1659e85b88e80e7b",
}
}
]
},
{
"id": "69024",
"messagesDeleted": [
{
"message": {
"id": "165a2cd1a5b308b9",
"threadId": "1659e85b88e80e7b",
}
}
]
}
}

Server side errors handling with angular-formly

I'm looking for solution on how I can display errors that the server respond, this is the respond for every invalid submission so I want to make the error handler in the app level and not in a controller.
I want to display the errors both on the FORM level and on the field level.
I have a REST API that in case of error return the following JSON object:
{
"message": "Validation error: Validation notEmpty failed,\nValidation error: Validation isEmail failed",
"errors": [
{
"field": "username",
"message": "Validation notEmpty failed"
},
{
"field": "email",
"message": "Validation isEmail failed"
}
]
}
How can I create a service that display the errors in case there is any?
Thanks
So, i created this for another answer. Let me know if this sort of a setup works for you. Here, the error is intended to be displayed on response from the server after button click. You can modify it accordingly.
I have given the field a custom template as follows:
formlyConfigProvider.setWrapper({
name: 'inputWrapper',
template: '<div ng-class="to.changeColor==\'red\'? \'redBorder\' : \'otherBorder\'"><formly-transclude></formly-transclude>{{to.keyVal}}</div>'
});
The form elements are defined through a schema format to allow each element to be individually accessed.
vm.schema={
"schema": {
"coolValue" : [{
"key": "coolValue",
"type": "input",
"wrapper": ['inputWrapper'],
"templateOptions": {
"type" : "text",
"label": 'Cool Value',
"keyVal":"",
"changeColor":"green"
}
}]
}
};
Finally, the onSubmit function
function onSubmit() {
//Do whatever you want here
//Let's say your server returns an error "iNVALID Credentials"
var response={
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization",
}
],
"code": 401,
"message": "Invalid Credentials"
}
};
vm.schema.schema.coolValue[0].templateOptions.changeColor="red";
vm.schema.schema.coolValue[0].templateOptions.keyVal=response.error.message;
}
});
You can essentially pass any error message or response from the server here.
The CSS contains a class to add a red border to the field.You are free to disable this.Feel free to ping if you need anything in this area as well.
Here is a DEMO

Resources