"Recipient address required" even after encoding the raw message - google-apis-explorer

I'm having an issue with sending emails via the Gmail API. I followed the instructions as specified by various sources:
400 error. Recipient address required. JavaScript
400 Error. Recipient address required. curl
Message:
From: 'John Doe' <john.doe#gmail.com>\n
To: 'Jane Doe' <jane.doe#gmail.com>\n
Subject: This is a subject\n
Did you receive this message?
(I tried both with and without ', including specifying the email address directly)
I encoded this as base64 (url safe) and add it to the "raw" field of the body. Note that I pass the full JSON as the body.
{
"raw":"RnJvbTogJ0pvaG4gRG9lJyA8am9obi5kb2VAZ21haWwuY29tPgpUbzogJ0phbmUgRG9lJyA8amFuZS5kb2VAZ21haWwuY29tPgpTdWJqZWN0OiBUaGlzIGlzIGEgc3ViamVjdApEaWQgeW91IHJlY2VpdmUgdGhpcyBtZXNzYWdlPw=="
}
(I tried both with and without padding)
I'm using the following HTTP headers:
"headers":{
"content-type":"message/rfc822",
"authorization":"Bearer ya..."
}
After doing a POST request to https://gmail.googleapis.com/upload/gmail/v1/users/john.doe#gmail.com/messages/send I get the following response:
{
"error": {
"code": 400,
"message": "Recipient address required",
"errors": [
{
"message": "Recipient address required",
"domain": "global",
"reason": "invalidArgument"
}
],
"status": "INVALID_ARGUMENT"
}
}
EDIT:
The official Google docs aren't really helpful regarding language neutrality.
https://developers.google.com/gmail/api/guides/sending

As it turns out, you cannot send email with a service account. The official Google support page literally tells you to use a third party service:
https://cloud.google.com/compute/docs/tutorials/sending-mail/
So I just went old-school and use SMTP. Works great.

Related

Unauthorized WebHook callback channel Google push notifications

I am trying to monitor my files in Google Drive.
By getting notifications to the delivery channel.
I've tried everything and tried hundreds of times but every time he tells me:
`
I am using Postman.
Post https://www.googleapis.com/drive/v2/changes/watch
Body:
{"id": "01234567-89ab-cdef-012345***789ab",
"kind":"drive#startPageToken",
"type": "webhook",
"address": "https://nwafith.com/api/notifications"
}
Response
{
"error": {
"errors": [
{
"domain": "global",
"reason": "push.webhookUrlUnauthorized",
"message": "Unauthorized WebHook callback channel: https://www.nwafith.com/api/notifications"
}
],
"code": 401,
"message": "Unauthorized WebHook callback channel: https://www.nwafith.com/api/notifications"
}
}
In the Domain verification
I added:
www.nwafith.com
nwafith.com
Everything looks right but I don’t know exactly where the problem is.
I hope for help
Unauthorized WebHook callback channel:
Means that you have not properly authorized your domain in Google developer console.
Solution:
Go to the Google Developers Console
Select your project
Under 'APIS & AUTH' select 'Push'
Click 'Add domains'
Enter the needed domains (Only the domain is needed: https://www.nwafith.com)
Click the 'Add domains' button
After that it should work.

Getting 401 unauthorised when calling calendar api of office 365

I am trying to access the office 365 calendar api to create an event. The steps i followed are
Created app and registered it in azure
Gave permisissions to the app
Hitting https://login.microsoftonline.com/{{tenantid}}/oauth2/token to get the access token
body :
{
"grant_type":"client_credentials",
"client_id": "*****",
"client_secret": "****",
"resource":"https://outlook.office.com"
}
Response :
{
"token_type": "Bearer",
"expires_in": "3600",
"ext_expires_in": "262800",
"expires_on": "1532026206",
"not_before": "1532022306",
"resource": "https://outlook.office.com",
"access_token":"******"
}
When i pass this access token to https://outlook.office.com/api/v2.0/me/events which creates events. it gives me 401 unauthorised. Body of the request is as shown below. Someone please assist.
{
"Subject": "Discuss the Calendar REST API",
"Body": {
"ContentType": "HTML",
"Content": "I think it will meet our requirements!"
},
"Start": {
"DateTime": "2019-02-02T18:00:00",
"TimeZone": "Pacific Standard Time"
},
"End": {
"DateTime": "2019-02-02T19:00:00",
"TimeZone": "Pacific Standard Time"
},
"Attendees": [
{
"EmailAddress": {
"Address": "arulvelug#hexabot.onmicrosoft.com",
"Name": "Arulvelu G"
},
"Type": "Required"
}
]
}
To do authorization of office 365 and use REST API via Postman, here is a solution for your reference:
First: get security Token
Access [https://login.microsoftonline.com/extSTS.srf] via Http Post method. The content of the http request is as follows.
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:a="http://www.w3.org/2005/08/addressing"
xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-
utility-1.0.xsd">
<s:Header>
<a:Action
s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</a:Action>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1">https://login.microsoftonline.com/extSTS.srf</a:To>
<o:Security s:mustUnderstand="1"
xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<o:UsernameToken>
<o:Username>[username]</o:Username>
<o:Password>[password]</o:Password>
</o:UsernameToken>
</o:Security>
</s:Header>
<s:Body>
<t:RequestSecurityToken xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">
<wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
<a:EndpointReference>
<a:Address>[endpoint]</a:Address>
</a:EndpointReference>
</wsp:AppliesTo>
<t:KeyType>http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey</t:KeyType>
<t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType>
<t:TokenType>urn:oasis:names:tc:SAML:1.0:assertion</t:TokenType>
</t:RequestSecurityToken>
</s:Body>
</s:Envelope>
The demonstration screenshot in Postman:
And the response content will include a security token as below, we can use this security token to get Access Token of office 365.
Second: get Access Token
Here i show you how to get access token, I get it of my SharePoint using the security token.
Access [https://yourdomain.sharepoint.com/_forms/default.aspx?wa=wsignin1.0] via http Post method. The content of the request is the security token that we have got above as below.
And the response as below:
We can see that there are two cookie, rtFa and FedAuth in response header, and these two cookie need to be added to the request in subsequent request.
Third: get Request Digest
Access [https://yourdomain.sharepoint.com/_api/contextinfo] via http Post method with that two cookies which we have got above.
And the response as below:
This is the final Token we want!
Then we can use REST API of our app in O365, like SharePoint , we only need to add this token and the previous two cookie, as shown in the following figure.

"Invalid JSON","error":"invalid_value"

Hi I am trying to use workato to create a task for Podio. I have successfully connected to Podio using their HTTP OAUTH2 connection, but when I try to actually create the task using JSON, I receive this from Podio:
This is from HTTP:
400 Bad Request:
{"error_parameters":{},"error_detail":null,"error_propagate":false,"request":{"url":"http://api.podio.com/task/","query_string":"","method":"POST"},"error_description":"Invalid
JSON","error":"invalid_value"}
The Code is as follows:
Request URL : https://api.podio.com/task/item/"the item id" <--This is where I would place the itemID of the item in Podio
Request header:
Authorization: OAuth2 [[User.SiteAccessToken]]
Content-type: application/json
Request Body:
{
"text": "Regarding Absence Request for Vacation",
"responsible":"{"type":profile, "id": "this is my profileID" }",
"description": "Your request for Vacation has been denied, please contact your manager."
}
but when I run this, I get this error message:
400 Bad Request:
{"error_parameters":{},"error_detail":null,"error_propagate":false,"request":{"url":"http://api.podio.com/task/item/436023600","query_string":"","method":"POST"},"error_description":"Invalid
JSON","error":"invalid_value"}
Now within the the request body or header does it need to have which app I am referring to not just the item ID. Not sure what it's looking for, if you could please assist with some guidance, that would be greatly appreciated.
I discovered that the issue was indeed the syntax within the JSON sent in the request body.
The quotes around the curly braces for responsible needed to be removed and I needed quotes with profile, and it should have gone like this:
{
"text": "Regarding Absence Request for Vacation",
"responsible": {"type":"profile", "id": 123 },
"description": "Your request for Vacation has been denied, please contact your manager."
}

Google Search Console 401 Bad Request issue without using Client Library

So, Here are 3 steps.
I called oAuth2 with following url:
https://accounts.google.com/o/oauth2/v2/auth
?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fwebmasters%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fwebmasters.readonly
&client_id=___.apps.googleusercontent.com
&redirect_uri=urn:ietf:wg:oauth:2.0:oob
&response_type=code
&approval_prompt=force
&access_type=offline
I get the code, suppose: 4/QVgPaCMqp94____qBC4NY_d54IcRj7U9mJc
Then I'm making a request for access_token, by making a POST request to https://accounts.google.com/o/oauth2/token with client_id, client_secret, redirect_uri, grant_type, and I get a JSON like:
'access_token' => ya29.CjHzAgC4js6Guv-1pt_rE____q8XIxiXOXOaSZW9NLRjKCTI3izBi,
'expires_in' => 3600,
'refresh_token' => 1/dL3ENA-EVI0rEb6D-OGqw_____iFe2ZNdEq4,
Now, I am making a request with that access_token or in cases of expiry with a renewed access_token to Google Search Console, which I have added in scopes.
My request is similar to this: https://developers.google.com/webmaster-tools/v3/urlcrawlerrorssamples/list#try-it
But I get an 401 unauthorized error, with a json like following:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
Considering I have done the process correctly, I think I have missing some parameters or providing some wrong value.
I have not used Google Client Library, instead used the REST API framework directly.
Can anybody give some clue please? Thank you.
The reason is, URL query parameter must be ?access_token= and not ?key= The later can be used only in case of direct API access and not oAuth.

authorization_invalid_request error when preparing DocuSign envelope for tab modification

I am trying trying to create a draft envelope from a template and then modify some of the tabs in the template. I'm getting an AUTHORIZATION_INVALID_REQUEST response.
My initial request is to the following URL https://demo.docusign.net/restapi/v2/accounts/<account id>/envelopes
and the payload is as follows:
{
"status": "created",
"emailSubject": "2015-01-27T16:25:43.133-05:00 Docusign Template Request",
"emailBlurb": "email blurb",
"templateId": "<template id>",
"brandId": "<brand id>",
"templateRoles": [
{
"name": "<name>",
"email": "<email>",
"roleName": "<role>",
"clientUserId": "",
"emailNotification": {
"supportedLanguage": "en",
"emailSubject": "<subject>",
"emailBody": "special email body"
}
}
],
"allowReassign": "true",
"enableWetSign": "false",
"messageLock": "false"
}
That produces the following response:
{
"envelopeId": "<envelope id>",
"uri": "/envelopes/<envelope id>",
"statusDateTime": "2015-01-28T22:09:43.9770000Z",
"status": "created"
}
Then I send a recipient view request to the following URL:
https://demo.docusign.net/restapi/v2/envelopes/<envelope id>/views/recipient using the envelope id received in the above response.
This results in the following response:
{
"errorCode": "AUTHORIZATION_INVALID_REQUEST",
"message": "The authorization request is malformed."
}
Note that if I had set the first request above to a status of "sent" (and thus did not create a draft envelope), the second request would have been successful.
However according to DocuSign documentation (p. 163 of the API guide), the modify tabs API call "modifies one or more tabs for a recipient to a draft envelope". Accordingly to perform a tab modification I need a draft envelope, not a sent one. But when I create a draft envelope, the views/recipient call fails as above.
I can add tabs successfully to a "sent" envelope. But I would rather modify tabs and am having trouble doing that.
You're not hitting a valid DocuSign Endpoint. Where did you get the /v2/envelopes/<envelope id>/views/recipient URL from? That's not a proper URL hence the error message you are getting.
After you create the envelope if you want to modify a given recipient's tabs then you need to make the following API call:
Modify Tabs for Recipient
Note that this is a PUT call not a POST, and URI is:
/accounts/{accountId}/envelopes/{envelopeId}/recipients/{recipientId}/tabs
For example, if you wanted to modify tabs for recipient who is recipientId = 3 you would make a call similar to (notice the 3 in the URL):
PUT https://demo.docusign.net/restapi/v2/accounts/12345/envelopes/{envelopeId}/
recipients/3/tabs
X-DocuSign-Authentication: <DocuSignCredentials><Username>{name}</Username><Password>{password}</Password><IntegratorKey>{integrator_key}</IntegratorKey></DocuSignCredentials>
Accept: application/json
Content-Type: application/json
{
"approveTabs":[{
<Tab information removed>
}],
"titleTabs":[{
<Tab information removed>
}],
"signHereTabs":[{
<Tab information removed>
}]
}
I'm not sure if this qualifies as an "answer" to my question, but it does appear that the problem has somehow been resolved. I let it rest for a couple days while I attended to other matters, then yesterday afternoon suddenly it started working, with no changes on my part. The specific part that wasn't working was attempting a PUT on an envelope in order to modify the tags. That is not supposed to work unless the envelope is a draft; my envelopes have all been drafts. Wasn't working a couple days ago, and now it is. #Pete and #Dorian: you might want to try it again if you haven't already; if you're not doing anything else wrong it might work now.