Created
November 18, 2014 02:07
-
-
Save azat-co/85f45f4ac8bb85058a42 to your computer and use it in GitHub Desktop.
Asana Hello World Node API Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request') | |
var apiKey = process.env.API_KEY | |
var workspaceId = process.env.WORKSPACE | |
var assigneeEmail = process.env.ASSIGNEE | |
var url ='https://app.asana.com/api/1.0/tasks' | |
// set up the request | |
var headers = { | |
'Authorization': 'Basic '+ new Buffer(apiKey).toString('base64') | |
} | |
var body = { | |
data: { | |
'workspace': workspaceId, | |
'name': 'Hello World!!!', | |
'assignee': assigneeEmail | |
} | |
} | |
// set up HTTPS connection | |
// json option will auto-add the application/json header | |
request.post({url:url, headers: headers, json: body}, function (e, r, body) { | |
// output | |
if (e || body['errors']) | |
console.log('Server returned an error: '+ body['errors'][0]['message']) | |
else { | |
console.log('Created task with id: ' + body['data']['id']) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment