AsanaConnect
This Integration uses Asana PATs to connect to projects tied to the Asana account.
Case Management · Asana Connect
Details
| ID | AsanaConnect |
|---|---|
| Provider | Asana |
| Category | Case Management |
| From Version | 6.0.0 |
| Docker Image | demisto/py3-tools:1.0.0.114656 |
| Supported Modules | Agentix XSIAM |
README
asana-get-project
Get the project from Asana
Base Command
asana-get-project
Input
| Argument Name | Description | Required |
|---|---|---|
| project_id | id of the project in asana. id can be found in the asana project url. (e.g. https://app.asana.com/0/XXXXXXXXXXX/list). | Required |
Context Output
There is no context output for this command.
asana-create-task
creates a task in the given project
Base Command
asana-create-task
Input
| Argument Name | Description | Required |
|---|---|---|
| project_id | id of the project in asana. id can be found in the asana project url. (e.g. https://app.asana.com/0/XXXXXXXXXXX/list). | Required |
| name | name of the task to create. | Required |
Context Output
There is no context output for this command.
asana-get-all-projects
gets the list of projects on asana
Base Command
asana-get-all-projects
Input
| Argument Name | Description | Required |
| — | — | — |
Context Output
There is no context output for this command.
Configuration parameters
accesstoken— Access Token (required)
Commands (3)
-
asana-create-taskcreates a task in the given project
-
asana-get-all-projectsgets the list of projects on asana
-
asana-get-projectGet the project from Asana
import demistomock as demisto # noqa: F401 from CommonServerPython import * # noqa: F401 import asana def get_asana_client(token): try: client = asana.Client.access_token(token) except Exception as err: return_error(str(err)) return client def get_projects_in_workspace(wid, client): res = [] projects = client.projects.get_projects({"workspace": wid}, opt_pretty=True) for project in projects: res.append(project) return res def get_all_projects(token): """Gets all projects of the user in Asana' :type token: ``str`` :param token: PAT of the account used in this integration :return: list of the projects on Asana :rtype: ``list`` """ res = [] try: client = get_asana_client(token) workspaces = client.workspaces.find_all() # pylint: disable=no-member for workspace in workspaces: projects = get_projects_in_workspace(workspace["gid"], client) res.extend(projects) return CommandResults(outputs_prefix="asana", outputs_key_field="projects", outputs=res) except Exception: demisto.results("Request failed") def get_project(pid, token): """Retrieves metadata of the particular project' :type id: ``str`` :param id: project id in Asana :type name: ``str`` :param name: name for the task to be created :type token: ``str`` :param token: PAT of the account used in this integration :return: 'ok' if test passed, anything else will fail the test. :rtype: ``str`` """ project = {} try: client = get_asana_client(token) project = client.projects.find_by_id(pid) # pylint: disable=no-member return CommandResults(outputs_prefix="asana", outputs_key_field="project", outputs=project) except Exception: demisto.results("Request failed") def create_task_in_project(pid, name, token): """Creates a task in the specific Asana project' :type id: ``str`` :param id: project id in Asana :type name: ``str`` :param name: name for the task to be created :type token: ``str`` :param token: PAT of the account used in this integration :return: 'ok' if test passed, anything else will fail the test. :rtype: ``str`` """ try: client = get_asana_client(token) client.tasks.create({"projects": pid, "name": name}) # pylint: disable=no-member demisto.results(f"Task {name} successfully added to project") except Exception: demisto.results("Task creation failed") def test_module(token): """Tests API connectivity and authentication' Returning 'ok' indicates that the integration works like it is supposed to. Connection to the service is successful. Shows the http error 'No Authorization' if it fails. :type token: ``str`` :param token: PAT of the Asana account used in this integration :return: 'ok' if test passed, anything else will fail the test. :rtype: ``str`` """ get_asana_client(token) return "ok" def main(): """main function, parses params and runs command functions :return: :rtype: """ params = demisto.params() access_token = params.get("accesstoken") try: if demisto.command() == "test-module": demisto.results(test_module(access_token)) elif demisto.command() == "asana-get-project": pid = demisto.args()["project_id"] res = get_project(pid, access_token) return_results(res) elif demisto.command() == "asana-create-task": pid = demisto.args()["project_id"] name = demisto.args()["name"] create_task_in_project(pid, name, access_token) elif demisto.command() == "asana-get-all-projects": res = get_all_projects(access_token) return_results(res) except Exception as err: return_error(str(err)) if __name__ in ["__builtin__", "builtins", "__main__"]: main()