Create Task in Asana Node.js - node.js

Using the below in Node trying to create a task within Workspace. I have omitted the AccessToken & WorkspaceID numbers. Suspect I'm doing something really dumb :)
var asana = require('asana');
var client = asana.Client.create().useAccessToken('0/XXXXXXXX');
var newTask = { name: "Your Mission" };
client.tasks.createInWorkspace(1111111111, newTask).then(function(response) {
tasks = response.data;
console.log(tasks);
});
At runtime I get the following output...
Unhandled rejection Error: Invalid Request
at InvalidRequest.AsanaError (/Users/D/Asana_Crons/node_modules/asana/lib/errors/error.js:4:11)
at new InvalidRequest (/Users/D/Asana_Crons/node_modules/asana/lib/errors/invalid_request.js:5:14)
at Request._callback (/Users/D/Asana_Crons/node_modules/asana/lib/dispatcher.js:152:23)
at Request.self.callback (/Users/D/Asana_Crons/node_modules/request/request.js:186:22)
at emitTwo (events.js:125:13)
at Request.emit (events.js:213:7)
at Request.<anonymous> (/Users/D/Asana_Crons/node_modules/request/request.js:1163:10)
at emitOne (events.js:115:13)
at Request.emit (events.js:210:7)
at IncomingMessage.<anonymous> (/Users/D/Asana_Crons/node_modules/request/request.js:1085:12)
at Object.onceWrapper (events.js:314:30)
at emitNone (events.js:110:20)
at IncomingMessage.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1047:12)
at _combinedTickCallback (internal/process/next_tick.js:102:11)
at process._tickCallback (internal/process/next_tick.js:161:9)

The only issue I can see with your code is that the workspace id needs to be a string, not an integer. This is documented in the tasks section of /gen folder in the Asana Node client library.

Related

lambda.invoke call through Node AWS SDK is timing out at 5 minutes while Lambda is completing under 4 minutes

I have a Lambda function that is set to timeout at 5 minutes, and occasionally when I invoke the function using the node SDK, I am getting a timeout error after 5 minutes.
However, when I have checked the CloudWatch logs after getting the client-side error, and am seeing the function successfully complete after ~3:30 minutes of execution time.
I have also noticed that the client side will log the timeout 2 minutes before the CloudWatch logs read that the function completed (ie, client side error timestamps at 4:08 and the CloudWatch successful end timestamps at 4:10), but I am assuming that is a lag between log writes, not run time. Thought I would mention it just in case that is something worth thinking more about.
From what I can tell, when the function runs under two minutes, it is consistently getting a positive response.
Code looks like this:
let aws_config = new AWS.Config({
region: 'us-east-1',
credentials: credentials,
httpOptions: {
proxy: process.env.HTTP_PROXY,
timeout: 300000
}
})
var lambda = new AWS.Lambda(aws_config);
lambda.invoke(params, (err, data: Result) => {
...
}
Error looks like this:
{ TimeoutError: Connection timed out after 300000ms
at ClientRequest.<anonymous> (.../node_modules/aws-sdk/lib/http/node.js:83:34)
at Object.onceWrapper (events.js:273:13)
at ClientRequest.emit (events.js:182:13)
at ClientRequest.EventEmitter.emit (domain.js:442:20)
at Socket.emitRequestTimeout (_http_client.js:661:40)
at Object.onceWrapper (events.js:273:13)
at Socket.emit (events.js:182:13)
at Socket.EventEmitter.emit (domain.js:442:20)
at Socket._onTimeout (net.js:449:8)
at ontimeout (timers.js:425:11)
message: 'Connection timed out after 300000ms',
code: 'TimeoutError',
time: 2018-10-05T20:08:35.719Z,
region: 'us-east-1',
hostname: 'lambda.us-east-1.amazonaws.com',
retryable: true } 'TimeoutError: Connection timed out after 300000ms\n at ClientRequest.<anonymous> (.../node_modules/aws-sdk/lib/http/node.js:83:34)\n at Object.onceWrapper (events.js:273:13)\n at ClientRequest.emit (events.js:182:13)\n at ClientRequest.EventEmitter.emit (domain.js:442:20)\n at Socket.emitRequestTimeout (_http_client.js:661:40)\n at Object.onceWrapper (events.js:273:13)\n at Socket.emit (events.js:182:13)\n at Socket.EventEmitter.emit (domain.js:442:20)\n at Socket._onTimeout (net.js:449:8)\n at ontimeout (timers.js:425:11)'
Have you looked into
context.callbackWaitsForEmptyEventLoop = false;
Here'e a related SO posting:
Why does AWS Lambda function always time out?

how to pass a object inside the logger.log() file in winston#3.0.0 in nodejs

i have a http request in a variable queryData = qs.parse(requestBody);
when i try to parse through winston
logger.log("info","requestbody",+queryData);
even tried
logger.log("info","requestbody %s", queryData);
logger.log("info","requestbody",{queryData});
didn't worked
am getting error like:
{ TypeError: Cannot create property 'Symbol(level)' on string 'Registering Device typeac'
at DerivedLogger.log (/home/grl/www/node_modules/winston/lib/winston/logger.js:130:20)
at createOcfRes (/home/aol/www/iot-node-server.js:285:10)
at IncomingMessage.<anonymous> (/home/aol/www/iot-node-server.js:115:9)
at emitNone (events.js:86:13)
at IncomingMessage.emit (events.js:186:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9) level: 'error', timestamp: '19-07-2018 20:20:19' }

httpsProxyAgent is not defined

I am integrating linkedin authentication with my node.js by passport-linkedin.
It works fine initially. I am redirected to login/signup page. User is entering their details but then when it is coming to authentication I get the error
InternalOAuthError: Failed to obtain access token
at Strategy.OAuth2Strategy._createOAuthError (C:\Users\SU40006113\Desktop\second\node_modules\passport-oauth2\lib\strategy.js:379:17)
at C:\Users\SU40006113\Desktop\second\node_modules\passport-oauth2\lib\strategy.js:166:45
at C:\Users\SU40006113\Desktop\second\node_modules\oauth\lib\oauth2.js:199:18
at ClientRequest.<anonymous> (C:\Users\SU40006113\Desktop\second\node_modules\oauth\lib\oauth2.js:170:5)
at emitOne (events.js:116:13)
at ClientRequest.emit (events.js:211:7)
at TLSSocket.socketErrorListener (_http_client.js:387:9)
at emitOne (events.js:116:13)
at TLSSocket.emit (events.js:211:7)
at emitErrorNT (internal/streams/destroy.js:64:8)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
I checked on stack overflow and got to know that it is because of corporate proxy. I added
var HttpsProxyAgent = require('https-proxy-agent');
if (process.env['https_proxy']) {
httpsProxyAgent = new HttpsProxyAgent(process.env['https_proxy']);
}
and
options.agent = httpsProxyAgent;
in oauth2.js. But now I am getting this error
ReferenceError: httpsProxyAgent is not defined
at exports.OAuth2._request (C:\Users\SU40006113\Desktop\second\node_modules\oauth\lib\oauth2.js:126:19)
at exports.OAuth2.getOAuthAccessToken (C:\Users\SU40006113\Desktop\second\node_modules\oauth\lib\oauth2.js:197:8)
at loaded (C:\Users\SU40006113\Desktop\second\node_modules\passport-oauth2\lib\strategy.js:164:20)
at NullStore.verify (C:\Users\SU40006113\Desktop\second\node_modules\passport-oauth2\lib\state\null.js:9:3)
at Strategy.OAuth2Strategy.authenticate (C:\Users\SU40006113\Desktop\second\node_modules\passport-oauth2\lib\strategy.js:210:26)
at attempt (C:\Users\SU40006113\Desktop\second\node_modules\passport\lib\middleware\authenticate.js:361:16)
at authenticate (C:\Users\SU40006113\Desktop\second\node_modules\passport\lib\middleware\authenticate.js:362:7)
at Layer.handle [as handle_request] (C:\Users\SU40006113\Desktop\second\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\SU40006113\Desktop\second\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\SU40006113\Desktop\second\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\SU40006113\Desktop\second\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\SU40006113\Desktop\second\node_modules\express\lib\router\index.js:281:22
at Function.process_params (C:\Users\SU40006113\Desktop\second\node_modules\express\lib\router\index.js:335:12)
at next (C:\Users\SU40006113\Desktop\second\node_modules\express\lib\router\index.js:275:10)
at Function.handle (C:\Users\SU40006113\Desktop\second\node_modules\express\lib\router\index.js:174:3)
at router (C:\Users\SU40006113\Desktop\second\node_modules\express\lib\router\index.js:47:12)
I have installed https-proxy-agent.
What's causing the error?

Error: An unexpected error has occurred. Firebase Functions

I have updated firebase-functions to version 1.0.2, firebase-tools to 3.18.4, firebase-admin to 5.12.0
I am uploading a function that generate thumbnails taken from https://github.com/firebase/functions-samples/tree/master/quickstarts/thumbnails
[debug] [2018-04-26T09:00:12.812Z] <<< HTTP RESPONSE 400
[debug] [2018-04-26T09:00:12.812Z] <<< HTTP RESPONSE BODY <?xml version='1.0' encoding='UTF-8'?><Error><Code>InvalidArgument</Code><Message>Invalid argument.</Message></Error>
[debug] [2018-04-26T09:00:12.813Z] TypeError: Cannot create property 'error' on string '<?xml version='1.0' encoding='UTF-8'?><Error><Code>InvalidArgument</Code><Message>Invalid argument.</Message></Error>'
at module.exports (C:\Users\NASA\AppData\Roaming\npm\node_modules\firebase-tools\lib\responseToError.js:11:16)
at Request._callback
(C:\Users\NASA\AppData\Roaming\npm\node_modules\firebase-tools\lib\api.js:47:25)
at Request.self.callback
(C:\Users\NASA\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\request\request.js:186:22)
at Request.emit (events.js:180:13)
at Request.emit (domain.js:421:20)
at Request.<anonymous>
(C:\Users\NASA\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\request\request.js:1163:10)
at Request.emit (events.js:180:13)
at Request.emit (domain.js:421:20)
at IncomingMessage.<anonymous>
(C:\Users\NASA\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\request\request.js:1085:12)
at Object.onceWrapper (events.js:272:13)
[error] Error: An unexpected error has occurred.
You said that:
You have updated firebase-functions to version 1.0.2
The code is cloned from the Cloud Function sample without any change
So most probably your problem comes form the fact that Cloud Functions V1.0.0 and above have changed, see the doc https://firebase.google.com/docs/functions/beta-v1-diff#storage
You should change from
exports.generateThumbnail = functions.storage.object().onFinalize((object) => {
to
exports.generateThumbnail = functions.storage.object().onFinalize((object, context) => {
and adapt accordingly the lines based on object, following the doc.

Bad Request at respond node_modules/elasticsearch/src/lib/transport.js:264:15

I am very dummy on ElasticSearch and I have little experience with NodeJs. I have created few cruds using NodeJs + MongoDb. I have to change from MongoDb to ElasticSearch (this is mandatory). Please, I don't want to compare MOngoDb with ElasticSearch so don't try that.
I am following the example found here
https://blog.raananweber.com/2015/11/24/simple-autocomplete-with-elasticsearch-and-node-js/
I have started succesfully ElasticSearch. I can see:
nodejs express.js-elasticsearch-autocomplete-demo-master # curl --noproxy -XGET 'http://127.0.0.1:9200/?pretty'
{
"name" : "-em7X-s",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "cqJUaPcFREe4wX_YyYWoFg",
"version" : {
"number" : "5.2.1",
"build_hash" : "db0d481",
"build_date" : "2017-02-09T22:05:32.386Z",
"build_snapshot" : false,
"lucene_version" : "6.4.1"
},
"tagline" : "You Know, for Search"
}
However, when I try to start the sample above or access I get the error bellow respectvely:
/dev/samples/express.js-elasticsearch-autocomplete-demo-master $ npm start
> autocompleter#0.0.0 start /home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master
> node ./bin/www
Elasticsearch INFO: 2017-02-16T20:00:48Z
Adding connection to http://localhost:9200/
Unhandled rejection Error: Bad Request
at respond (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/elasticsearch/src/lib/transport.js:264:15)
at checkRespForFailure (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/elasticsearch/src/lib/transport.js:223:7)
at HttpConnector.<anonymous> (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/elasticsearch/src/lib/connectors/http.js:155:7)
at IncomingMessage.wrapper (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/lodash/index.js:3095:19)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:905:12)
at nextTickCallbackWith2Args (node.js:441:9)
at process._tickCallback (node.js:355:17)
Unhandled rejection Error: [illegal_argument_exception] request [/randomindex/_suggest] contains unrecognized parameter: [type]
at respond (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/elasticsearch/src/lib/transport.js:264:15)
at checkRespForFailure (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/elasticsearch/src/lib/transport.js:223:7)
at HttpConnector.<anonymous> (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/elasticsearch/src/lib/connectors/http.js:155:7)
at IncomingMessage.wrapper (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/lodash/index.js:3095:19)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:905:12)
at nextTickCallbackWith2Args (node.js:441:9)
at process._tickCallback (node.js:355:17)
Unhandled rejection Error: [illegal_argument_exception] request [/randomindex/_suggest] contains unrecognized parameter: [type]
at respond (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/elasticsearch/src/lib/transport.js:264:15)
at checkRespForFailure (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/elasticsearch/src/lib/transport.js:223:7)
at HttpConnector.<anonymous> (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/elasticsearch/src/lib/connectors/http.js:155:7)
at IncomingMessage.wrapper (/home/demetrio/dev/samples/express.js-elasticsearch-autocomplete-demo-master/node_modules/lodash/index.js:3095:19)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:905:12)
at nextTickCallbackWith2Args (node.js:441:9)
at process._tickCallback (node.js:355:17)
I am very confused what to check. Any suggestion will be appreciated. My final target is to understand how to connect to ElasticSearch from NodeJs application

Resources