0
votes

I'm using the Request package for node in AWS Lambda and I'm trying to get the body of the successful request in the callback function of the request. I know the request is successful because it's creating the resource in Toggl, but it's not showing up in the logs. The setup below works in other Express/Node apps I have, but not here? I'm new to Lambda so it's possible I'm missing something obvious. Lambda says console.log() will log to Cloudwatch, but it's like the callback function isn't being ran. Any ideas?

var request = require('request');


exports.handler = function signupNew(event, context){
  
  request({'url': 'https://www.toggl.com/api/v8/projects', //URL to hit
          'method': 'POST',
          'headers': {
              'Content-Type': 'application/json',
              'Accept': 'application/json'
          },
          'auth': {
            'user': 'xxxxx',
            'pass': 'api_token'
          },
    'json': {
      "project":{
      "name": "Bobby", //name of project,
      "wid":1057436, //Workspace
      "template_id":16368482, //template
      "is_private":false //public?
    }
      }, function(error, response, body){ //response for API call 

          if(error) {
              console.log(error);

          } else {
              //signupPayload.toggl = body;
              console.log(response.statusCode, body);
              context.done(null, body)
          }

      }});



} //end of handler function
1

1 Answers

0
votes

Turns out I was missing a '}' between the callback function and the request. Dumb little error, but at least now there's a nice example on how to do a POST request on Lambda with the request module.