I'm try to send email using google gmail API. I've used Request body JSON with bearer token and Content-Type - message/rfc822.
Then I've used link below to send post request but I received the following errors.how to fix this issue ???
Post request Link -
https://www.googleapis.com/upload/gmail/v1/users/kasunysoft#gmail.com/messages/send
Request Body
{
"threadId": "Hi kasunjith",
"payload": {
"mimeType": "message/rfc822",
"headers": [
{
"name": "To",
"value": "hvn#gmail.com"
},
{
"name": "From",
"value":"kasunysoft#gmail.com"
},
{
"name":"Subject",
"value":"Subject Text"
}
]
}
}
I got response
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidArgument",
"message": "Recipient address required"
}
],
"code": 400,
"message": "Recipient address required"
}
}
This means that your format in sending email is not valid. Check the documentation for Users.messages and Users.messages: send for the proper format.
{
"id": string,
"threadId": string,
"labelIds": [
string
],
"snippet": string,
"historyId": unsigned long,
"internalDate": long,
"payload": {
"partId": string,
"mimeType": string,
"filename": string,
"headers": [
{
"name": string,
"value": string
}
],
"body": users.messages.attachments Resource,
"parts": [
(MessagePart)
]
},
"sizeEstimate": integer,
"raw": bytes
}
You can also check out the following SO post for more in depth discussion about you error.
400 error. Recipient address required. JavaScript
How to send a message successfully using the new Gmail REST API?
Related
We are trying to get data from the google search console API with dimension types - web, discover, googleNews, news, image, video. They are all listed in the google API documentation here
But we are getting a successful response from google API only for search types 'web', 'image', and 'news', please see it below
Request URL: https://www.googleapis.com/webmasters/v3/sites/sc-domain%3Amydomain.com/searchAnalytics/query?fields=responseAggregationType%2Crows
Request:
{
"startDate": "2022-06-05",
"endDate": "2022-06-22",
"dimensions": ["query","page","country"],
"type": "web",
"dataState": "all",
"aggregationType": "byPage",
"rowLimit": 5000,
"startRow": 0
}
Response:
Queries Count: 239752
========================================================================================
Request:
{
"startDate": "2022-06-05",
"endDate": "2022-06-22",
"dimensions": ["query","page","country"],
"type": "image",
"dataState": "all",
"aggregationType": "byPage",
"rowLimit": 5000,
"startRow": 0
}
Response:
Queries Count: 1827
====================================================================================
Request:
{
"startDate": "2022-06-05",
"endDate": "2022-06-22",
"dimensions": ["query","page","country"],
"type": "web",
"dimensionFilterGroups": [
{
"groupType": "and",
"filters": [
{
"dimension": "country",
"operator": "contains",
"expression": "GBR"
}
]
}
],
"dataState": "all",
"aggregationType": "byPage",
"rowLimit": 5000,
"startRow": 0
}
Response:
Queries Count: 9073
When we are making the same request with the search type 'discover' or 'googleNews' we are getting an error in the response as below
Request:
{
"startDate": "2022-06-05",
"endDate": "2022-06-22",
"dimensions": ["query","page","country"],
"type": "discover",
"dataState": "all",
"aggregationType": "byPage",
"rowLimit": 5000,
"startRow": 0
}
Response:
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"errors": [
{
"message": "Request contains an invalid argument.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}
We also have tried to make the API request for the full URL without sc-domain parameter as one below
https://www.googleapis.com/webmasters/v3/sites/https%3A%2F%2Fwww.mydomain.com/searchAnalytics/query?fields=responseAggregationType%2Crows
But still, we are getting the same errors.
My question is - what is wrong with our requests and how to get data from the google search console API for the search types 'discover' and 'googleNews'? And is there any way to get more informative error messages from google search console API responses, that will provide a bit more explanation about the reason for the error occurred?
400 Error in People API [people.updateContact]
I'm need updateContact field locations of user in g-suite
i get 400 error "Resource name "people/{xxxxxxx}" is not a valid contact person resource."
request
{
"resourceName": "people/xxxxxxxxxxx",
"etag": "xxxxxxxxxxxxxx",
"locations": [
{
"metadata": {
"primary": true,
"source": {
"type": "PROFILE",
"id": "xxxxxxxxxxxxxxxx"
}
},
"value": "TestA",
"current": true
},
{
"metadata": {
"source": {
"type": "PROFILE",
"id": "xxxxxxxxxxxxxxxxx"
}
},
"value": "TestB"
}
]
}
response
{
"error": {
"code": 400,
"message": "Resource name \"people/{xxxxxxx}\" is not a valid contact person resource.",
"status": "INVALID_ARGUMENT"
}
}
Answer:
The error "Resource name \"people/{xxxxxxx}\" is not a valid contact person resource." appears because the resource name you are providing in your request is not a valid contact person resource.
Fix:
Replace people/{xxxxxxx} with a valid resource. You can obtain these using people.listDirectoryPeople endpoint.
How to Add a subscription for the authenticated user's channel
https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&key={YOUR_API_KEY}
Request Parameters :-
{
"0":
{ "name": " <code>snippet.resourceId.kind</code>", "value": "youtube#channel" },
"1": { "name": " <code>snippet.resourceId.channelId</code>", "value": "UC_x5XG1OV2P6uZZ5FSM9Ttw" }
}
Response Parameters :-
{
"error":
{ "errors":
[ { "domain": "youtube.subscription", "reason": "publisherRequired", "message": "The subscription resource specified in the request must use the <code>snippet.resourceId</code> property to identify the channel that is being subscribed to." } ], "code": 400, "message": "The subscription resource specified in the request must use the <code>snippet.resourceId</code> property to identify the channel that is being subscribed to." }
}
This apears to be a bug in the Youtube api. this can be verifyed by checking the api explorer here .
POST https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&key={YOUR_API_KEY}
{
"0": {
"name": "snippet.resourceId",
"value": "youtube#channel"
},
"1": {
"name": "snippet.resourceId",
"value": "UC_x5XG1OV2P6uZZ5FSM9Ttw"
}
}
Response
{
"error": {
"errors": [
{
"domain": "youtube.subscription",
"reason": "publisherRequired",
"message": "The subscription resource specified in the request must use the <code>snippet.resourceId</code> property to identify the channel that is being subscribed to."
}
],
"code": 400,
"message": "The subscription resource specified in the request must use the <code>snippet.resourceId</code> property to identify the channel that is being subscribed to."
}
}
There is an issue request for this issue and the team has been pinged.
Link of Youtube Data API (V3), you can try here
it's the image example in "try this API" of how i do
POST https://www.googleapis.com/youtube/v3/subscriptions?part=snippet HTTP/1.1
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json
Content-Type: application/json
{
"snippet": {
"resourceId": {
"kind": "youtube#channel",
"channelId": "UCUK0HBIBWgM2c4vsPhkYY4w"
}
}
}
I am sending below response to the service url provided by botFramework request https://telegram.botframework.com/v3/conversations/-263387177/activities/
My intent is that using sendMessage method of telegram I am able to route a text to the telegram channel via microsoft botframework
The http post which I am sending is as below
{
"type": "message",
"locale": "en-Us",
"chat_id":-263387177,
"channelID":"telegram",
"from": {
"id": "GTSFIBot",
"name": "sapeops"
},
"text":"hi , Greetings!",
"replyToId": "1505813737353",
"recipient": {
"id": "DirectLineClient"
},
"conversation": {
"isGroup": true,
"id": "-263387177",
"name": "sapeops group"
},
"channelData": {
"method": "sendMessage",
"parameters": {
"chat_id": -263387177,
"parse_mode": "HTML",
"text": "<B>Greetings! How are you doing?</B>"
},
"chat": {
"id": -263387177,
"title": "sapeops group",
"type": "group",
"all_members_are_administrators": true
}
}
}
I get 502 bad gateway response and a below JSON.
{
"error": {
"code": "ServiceError",
"message": "Telegram API returned a result code indicating non-success"
}
}
I am using the gmail API to get recent hangouts messages/threads. But I can't find a way to view the recipient address. The only field in payload.headers is 'From'
code:
curl -H 'Authorization: Bearer **accessToken**' 'https://www.googleapis.com/gmail/v1/users/me/threads/**threadId**?q=is%3Achat'
response:
{
"id": "xxx",
"historyId": "1008967",
"messages": [{
"id": "xxx",
"threadId": "xxx",
"labelIds": [
"CHAT"
],
"snippet": "+Harry Howard",
"historyId": "1008953",
"internalDate": "1481641738948",
"payload": {
"partId": "",
"mimeType": "text/html",
"filename": "",
"headers": [{
"name": "From",
"value": "xxx"
}],
"body": {
"size": 13,
"data": "K0hhcnJ5IEhvd2FyZA=="
}
},
"sizeEstimate": 100
}]
}
In the case of emails, there is a 'To' field ( and sometimes cc etc).
FYI: I am using node-gmail-api npm module but just testing this with curl
Use Users.threads:list to find all users within a thread. See an example here.
HTTP request
GET https://www.googleapis.com/gmail/v1/users/userId/threads
This request requires authorization with at least one of the following scopes
https://mail.google.com/
https://www.googleapis.com/auth/gmail.modify
https://www.googleapis.com/auth/gmail.readonly
https://www.googleapis.com/auth/gmail.metadata
Response
If successful, this method returns a response body with the following structure:
{
"threads": [
users.threads Resource
],
"nextPageToken": string,
"resultSizeEstimate": unsigned integer
}