@rbaileysr/asana-managed-api
v1.0.9
Published
Managed API wrapper for Asana REST API v1.0.9
Readme
Asana Managed API
A comprehensive Managed API wrapper for Asana REST API v1.0, providing type-safe, hierarchical access to all Asana API endpoints.
Overview
This Managed API wrapper provides a clean, type-safe interface to interact with the Asana API. It follows the same hierarchical pattern as other ScriptRunner Connect Managed APIs, making it easy to use and consistent with the platform's conventions.
Features
- Type-Safe: Full TypeScript support with IntelliSense
- Hierarchical Structure: Organized by resource type (Workspace, Project, Task, etc.)
- Comprehensive Coverage: Supports all major Asana API endpoints
- Error Handling: Built-in error parsing and handling
- Pagination Support: Utilities for handling paginated responses
- Web App Compatible: Works seamlessly in ScriptRunner Connect web app
Installation
The Managed API is already set up in this workspace. To use it in your scripts:
import Asana from './asana';Usage
Basic Examples
Get Current User
import Asana from './asana';
const me = await Asana.User.getMe({
optFields: ['gid', 'name', 'email']
});
console.log(`Logged in as: ${me.name}`);List Workspaces
const workspaces = await Asana.Workspace.listWorkspaces({
optFields: ['gid', 'name', 'isOrganization']
});
workspaces.forEach(ws => {
console.log(`${ws.name} (${ws.gid})`);
});Create a Project
const project = await Asana.Project.createProject({
data: {
name: 'My New Project',
workspace: '1234567890',
notes: 'Project description'
}
});
console.log(`Created project: ${project.gid}`);Create a Task
const task = await Asana.Task.createTask({
data: {
name: 'Complete documentation',
workspace: '1234567890',
projects: ['1234567891'],
notes: 'Write comprehensive documentation'
}
});
console.log(`Created task: ${task.gid}`);Update a Task
const updatedTask = await Asana.Task.updateTask('1234567892', {
data: {
completed: true,
notes: 'Task completed!'
}
});Add a Comment (Story)
const story = await Asana.Story.createStory('1234567892', {
data: {
text: 'Great progress on this task!'
}
});API Groups
The Managed API is organized into the following groups:
Workspace
getWorkspace(options)- Get a specific workspacelistWorkspaces(options?)- List all workspaces
User
getMe(options?)- Get current usergetUser(options)- Get a specific userlistUsers(options?)- List users
Project
getProject(options)- Get a specific projectlistProjects(options?)- List projectscreateProject(request)- Create a new projectupdateProject(projectGid, request)- Update a projectdeleteProject(projectGid)- Delete a projectaddMembers(projectGid, request)- Add members to a projectremoveMembers(projectGid, request)- Remove members from a project
Task
getTask(options)- Get a specific tasklistTasks(options?)- List taskssearchTasks(options)- Search for taskscreateTask(request)- Create a new taskupdateTask(taskGid, request)- Update a taskdeleteTask(taskGid)- Delete a taskaddProject(taskGid, request)- Add a project to a taskremoveProject(taskGid, request)- Remove a project from a taskaddFollowers(taskGid, request)- Add followers to a taskremoveFollowers(taskGid, request)- Remove followers from a taskaddTag(taskGid, request)- Add a tag to a taskremoveTag(taskGid, request)- Remove a tag from a task
Story (Comments)
getStory(options)- Get a specific storylistStories(options)- List stories for a task or projectcreateStory(taskGid, request)- Create a story (comment) on a taskdeleteStory(storyGid)- Delete a story
Tag
getTag(options)- Get a specific taglistTags(options?)- List tagscreateTag(request)- Create a new tagupdateTag(tagGid, request)- Update a tagdeleteTag(tagGid)- Delete a tag
Section
getSection(options)- Get a specific sectionlistSections(options)- List sections for a projectcreateSection(projectGid, request)- Create a new sectionupdateSection(sectionGid, request)- Update a sectiondeleteSection(sectionGid)- Delete a sectionaddTask(sectionGid, request)- Add a task to a section
Attachment
getAttachment(options)- Get a specific attachmentlistAttachments(options)- List attachmentscreateAttachment(request)- Create an attachmentdeleteAttachment(attachmentGid)- Delete an attachment
Custom Field
getCustomField(options)- Get a specific custom fieldlistCustomFields(options?)- List custom fieldscreateCustomField(request)- Create a new custom fieldupdateCustomField(customFieldGid, request)- Update a custom fielddeleteCustomField(customFieldGid)- Delete a custom fieldcreateEnumOption(customFieldGid, request)- Create an enum optionupdateEnumOption(enumOptionGid, request)- Update an enum optiondeleteEnumOption(enumOptionGid)- Delete an enum option
Team
getTeam(options)- Get a specific teamlistTeams(options?)- List teams
Webhook
getWebhook(options)- Get a specific webhooklistWebhooks(options?)- List webhookscreateWebhook(request)- Create a new webhookupdateWebhook(webhookGid, request)- Update a webhookdeleteWebhook(webhookGid)- Delete a webhook
Event
getEvents(options)- Get events from an event stream
Advanced Usage
Using optFields
The optFields parameter allows you to specify which fields to return in the response:
const task = await Asana.Task.getTask({
taskGid: '1234567890',
optFields: ['gid', 'name', 'completed', 'assignee', 'dueOn']
});Pagination
For endpoints that support pagination, use the limit and offset parameters:
const tasks = await Asana.Task.listTasks({
workspace: '1234567890',
limit: 50,
offset: 'eyJ0aW1lc3RhbXAiOjE2NDA5MjE2MDB9'
});Error Handling
The Managed API automatically parses Asana error responses:
try {
const task = await Asana.Task.getTask({ taskGid: 'invalid' });
} catch (error) {
console.error('Error:', error.message);
// Error messages are automatically extracted from Asana's error response
}Direct API Access
For advanced use cases, you can access the underlying API connection:
// Use the fetch method for custom endpoints
const response = await Asana.fetch('/api/1.0/custom/endpoint', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ data: { custom: 'value' } })
});Type Definitions
All TypeScript types are exported from the main module:
import Asana, { Task, Project, CreateTaskRequest } from './asana';
function processTask(task: Task) {
// Type-safe access to task properties
console.log(task.name, task.completed);
}Testing
See the tests/ directory for comprehensive test scripts:
basic-test.ts- Quick verification of core functionalitycreate-test-data.ts- Creates test dataverify-test-data.ts- Verifies test datacleanup-test-data.ts- Cleans up test datacomprehensive-test.ts- Full end-to-end test
API Connection Setup
This Managed API uses the API Connection configured at scripts/api/asana. Ensure:
- API Connection is configured in ScriptRunner Connect web UI
- Base URL is set to
https://app.asana.com - Authentication is configured (Personal Access Token or OAuth)
- Header includes
Authorization: Bearer <token>
Limitations
- Only works with resources in the
scripts/folder (cannot usenode/ornode_modules/) - Requires API Connection to be configured in ScriptRunner Connect
- Some Asana API endpoints may have rate limits
Resources
- Asana API Documentation
- ScriptRunner Connect Documentation
- Test scripts in
tests/directory
Support
For issues or questions:
- Check the test scripts for usage examples
- Review the Asana API documentation
- Check ScriptRunner Connect logs for error details
