57230

400 error. Recipient address required. JavaScript

Question:

I make a simple request step-by-step in Gmail API.

According to all instructions I made this call:

var request = gapi.client.gmail.users.messages.send({ 'userId': 'me', "payload": { "headers": [ { "name": "To", "value": "########@gmail.com" } ]}, 'raw': 'SEVMTE8gTVkgREVBUiBGUklFTkQ=' }); request.then(()=>{console.log('yep')})

But receive an error:

{ "error": { "errors": [ { "domain": "global", "reason": "invalidArgument", "message": "Recipient address required" } ], "code": 400, "message": "Recipient address required" } }

Answer1:

The correct format in sending to emails in Gmail API is stated in <a href="https://developers.google.com/gmail/api/v1/reference/users/messages/send" rel="nofollow">Users.messages: send</a>:

function sendMessage(userId, email, callback) { // Using the js-base64 library for encoding: // https://www.npmjs.com/package/js-base64 var base64EncodedEmail = Base64.encodeURI(email); var request = gapi.client.gmail.users.messages.send({ 'userId': userId, 'resource': { 'raw': base64EncodedEmail } }); request.execute(callback); }

For a more vivid sample on how to use this method, check this <a href="https://stackoverflow.com/questions/24460422/how-to-send-a-message-successfully-using-the-new-gmail-rest-api" rel="nofollow">SO post</a>:

<blockquote>

the complete message needs to be passed in the raw parameter, see the example:

From: John Doe <jdoe@machine.example> To: Mary Smith <mary@example.net> Subject: Saying Hello Date: Fri, 21 Nov 1997 09:55:06 -0600 Message-ID: <1234@local.machine.example>

This is a message just to say hello. So, "Hello". So after base64 encoding the complete message, passing it in the raw parameter without using any other parameter, it works fine.

</blockquote>

Recommend

  • Uploading to Amazon S3 via ng-file-upload; Error 400
  • C# Webbrowser Programmatically Close JS Confirm Box
  • Gmail API Watch() not working
  • What happens when I divide by zero?
  • list SqlStatementSource of all “Execute SQL Task” in SSIS package
  • Why does not work changing UIButton text via dot syntax?
  • Compress html output from zend framework 2
  • Why I am getting 400 error on https://www.googleapis.com/appsactivity/v1/activities?
  • read values from form post in jquery or javascript
  • apply a javascript function to draggable copy
  • Consuming a WCF service in a Java Client using wsHttpBinding
  • Exception gevent.hub.LoopExit: LoopExit('This operation would block forever',)
  • Updating Dojo provide
  • Defined variables not working in javascript files when I use getScript
  • jwtBearer bearer token with rc-1 update to ASP.Net 5
  • Trying to get the char code of ENTER key
  • How can I display the parent menu item's description using Wordpress walkers?
  • Using Sax parsing to edit and write XML in VB6
  • How to revert to previous XCode version?
  • Should I or shouldn't I use the CachingConnectionFactory with hornetq 2.4.1
  • Debug.DrawLine not showing in the GameView
  • Make VS2015 use angular-cli ng at build time in a .NET project
  • Email verification using google app script and google forms
  • Yii2: Config params vs. const/define
  • NHibernate Validation Localization with S#arp Architecture
  • How can I send an e-mail from a vbs script
  • Azure Cloud Service Web Role web pages do not load
  • Accessing IRQ description array within a module and displaying action names
  • Where to put my custom functions in Wordpress?
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • Upload files with Ajax and Jquery
  • Numpy divide by zero. Why?
  • AngularJs get employee from factory
  • Proper way to use connect-multiparty with express.js?
  • Hits per day in Google Big Query
  • How do you join a server to an Active Directory (domain)?
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Getting Messege Twice Using IMvxMessenger
  • Linking SubReports Without LinkChild/LinkMaster
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass