Upload files by streaming

In this example, you will use file streaming to attach a file to a newly-created task in the project management service Asana. The workflow is triggered by a new file arriving in a specified Box folder, allowing you to automate your task management processes.

Also see the how-to on Files as multipart formdata.

Asana is a popular project management tool for teams and individuals, allowing you to create projects and tasks, attach files from cloud services or upload them to Asana directly, and manage discussion around your tasks. All tasks belong to a workspace and are assigned to a member of your Asana team.

The operation A single request to a third-party API. Operations often become actions in the workflow designer. of creating a task returns the task id, which we pass to the next workflow action A task that can be performed or triggered within a workflow, such as moving a file, sending an email, or using third-party API functionality. which attaches the file. Because the OpenAPI Specification A standard, language-agnostic description of RESTful APIs that can be read by both humans and machines. Formerly known as Swagger. does not allow more than one definition for an endpoint The address of a specific resource provided by the third-party API. and HTML method, the attach-file operation cannot provide a drop-down value to select an existing task in the designer, so it can only add files to new tasks. If you wanted to extend this workflow to attach files to existing tasks, you could:

This example uses dynamic-values to allow the designer to select the workspace and assignee for the new task. For more information on dynamic-values, see x-ntx-dynamic-values.

The complete OpenAPI Specification A standard, language-agnostic description of RESTful APIs that can be read by both humans and machines. Formerly known as Swagger. and icon for this example are available here.

Tip: Want the short version? Check out our OpenAPI Specification quick reference for quick definitions of parameter types, authentication, file handling and Specification Extensions.

Register a client ID and secret

To import the completed Xtension A set of instructions for Nintex Automation Cloud to use third-party API functionality with Nintex workflows. An Xtension may include workflow actions, start events, forms or file control. , you must create the client ID and shared secret in your Asana account:

  1. If you do not already have an Asana account, create a free account here.
  2. Inside your Asana account, open your Account settings page.
  3. Click Manage Developer Apps.
  4. Click Add New Application.
  5. Add the App Name, App URL, and the Redirect URL of https://us.nintex.io/connection/api/Token.
  6. Click Create.
  7. Ensure Authorization Code Grant is selected.
  8. Record the Client ID and Client Secret somewhere secure. You will need these to import the Xtension into Nintex Automation Cloud.

Create the Xtension

Step 1: Create the basic OpenAPI Specification

Create an OpenAPI Specification that:

Add "x-ntx-visibility" : "internal" to the /workspaces and /users operations to hide them from the workflow designer, as they're not useful to the designer.

For more information on using x-ntx-dynamic-values and x-ntx-visibility see:

 
{
    "swagger": "2.0",
    "info": {
        "version": "1.0.0",
        "title": "Asana"
    },
    "host": "app.asana.com",
    "basePath": "/api/1.0",
    "schemes": [ "https" ],
    "produces": [ "application/json" ],
    "consumes": [ "application/json" ],
    "security": [
        {
            "oauth2": []
        }
    ],
    "paths": {
        "/workspaces": {
            "get": {
                "summary": "List workspaces",
                "description": "Lists all workspaces the authenticated user can access",
                "operationId": "ListWorkspaces",
                "x-ntx-visibility": "internal",
                "parameters": [],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "string"
                                    },
                                    "name": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/users": {
            "get": {
                "summary": "List users who can access this workspace",
                "description": "Lists all users who can access this workspace",
                "operationId": "ListUsers",
                "x-ntx-visibility": "internal",
                "parameters": [],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "string"
                                    },
                                    "name": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/tasks": {
            "post": {
                "summary": "Create a task",
                "description": "Create a task assigned to the selected user",
                "operationId": "CreateTask",
                "consumes": [ "multipart/form-data" ],
                "parameters": [
                    {
                        "name": "task",
                        "in": "body",
                        "schema": {
                            "required": [ "workspace", "assignee", "name" ],
                            "properties": {
                                "workspace": {
                                    "type": "string",
                                    "x-ntx-summary": "Workspace to add task to",
                                    "x-ntx-dynamic-values": {
                                        "operationId": "ListWorkspaces",
                                        "value-collection": "data",
                                        "value-path": "id",
                                        "value-title": "name"
                                    }
                                },
                                "assignee": {
                                    "x-ntx-summary": "Person to assign the task to",
                                    "type": "string",
                                    "x-ntx-dynamic-values": {
                                        "operationId": "ListUsers",
                                        "value-collection": "data",
                                        "value-path": "id",
                                        "value-title": "name"
                                    }
                                },
                                "name": {
                                    "type": "string",
                                    "x-ntx-summary": "Title of the task"
                                },
                                "notes": {
                                    "type": "string",
                                    "x-ntx-summary": "Task detail"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "201": {
                        "description": "Created Task",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "data": {
                                    "type": "object",
                                    "properties": {
                                        "id": {
                                            "type": "string",
                                            "x-ntx-summary": "Task id"
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/tasks/{task_id}/attachments": {
            "post": {
                "summary": "Attach a file to a task",
                "description": "Attach a file to a specified task",
                "operationId": "AttachFile",
                "consumes": [ "multipart/form-data" ],
                "parameters": [
                    {
                        "name": "task_id",
                        "type": "string",
                        "in": "path",
                        "x-ntx-summary": "Task id",
                        "description": "Task",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Ok"
                    }
                }
            }
        }
    },
    "securityDefinitions": {
        "oauth2": {
            "type": "oauth2",
            "flow": "accessCode",
            "authorizationUrl": "https://app.asana.com/-/oauth_authorize",
            "tokenUrl": "https://app.asana.com/-/oauth_token",
            "scopes": {}
        }
    }
}

Step 2: Set the operation to consume multipart/form-data

In the HTTP method object of the /tasks/{task_id}/attachments operation, add a consumes array with the value multipart/form-data.


"paths": {
    "/tasks/{task_id}/attachments": {
        "post": {
            "summary": "Attach a file to a task",
            "operationId": "AttachFile",
            "produces": [ "application/json" ],
            "consumes": [ "multipart/form-data" ]
        }
    }
}

Step 3: Define the file parameter

In the parameters array of the /tasks/{task_id}/attachments operation, define a parameter object for the file:

  • in with a value of formData.
  • type with a value of file.
  • require with a value of true.
  • name with a value of file.
  • description with a value of The file to attach.
 
"parameters": [
    {
        "name": "task_id",
        "type": "string",
        "in": "path",
        "x-ntx-summary": "Task id",
        "description": "Task",
        "required": true
    },
    {
        "in": "formData",
        "name": "file",
        "type": "file",
        "required": true,
        "description": "The file to attach."
    }
]

The OpenAPI Specification

 
{
    "swagger": "2.0",
    "info": {
        "version": "1.0.0",
        "title": "Asana"
    },
    "host": "app.asana.com",
    "basePath": "/api/1.0",
    "schemes": [ "https" ],
    "produces": [ "application/json" ],
    "consumes": [ "application/json" ],
    "security": [
        {
            "oauth2": []
        }
    ],
    "paths": {
        "/workspaces": {
            "get": {
                "summary": "List workspaces",
                "description": "Lists all workspaces the authenticated user can access",
                "operationId": "ListWorkspaces",
                "x-ntx-visibility": "internal",
                "parameters": [],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "string"
                                    },
                                    "name": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/users": {
            "get": {
                "summary": "List users who can access this workspace",
                "description": "Lists all users who can access this workspace",
                "operationId": "ListUsers",
                "x-ntx-visibility": "internal",
                "parameters": [],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "string"
                                    },
                                    "name": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/tasks": {
            "post": {
                "summary": "Create a task",
                "description": "Create a task assigned to the selected user",
                "operationId": "CreateTask",
                "consumes": [ "multipart/form-data" ],
                "parameters": [
                    {
                        "name": "task",
                        "in": "body",
                        "schema": {
                            "required": [ "workspace", "assignee", "name" ],
                            "properties": {
                                "workspace": {
                                    "type": "string",
                                    "x-ntx-summary": "Workspace to add task to",
                                    "x-ntx-dynamic-values": {
                                        "operationId": "ListWorkspaces",
                                        "value-collection": "data",
                                        "value-path": "id",
                                        "value-title": "name"
                                    }
                                },
                                "assignee": {
                                    "x-ntx-summary": "Person to assign the task to",
                                    "type": "string",
                                    "x-ntx-dynamic-values": {
                                        "operationId": "ListUsers",
                                        "value-collection": "data",
                                        "value-path": "id",
                                        "value-title": "name"
                                    }
                                },
                                "name": {
                                    "type": "string",
                                    "x-ntx-summary": "Title of the task"
                                },
                                "notes": {
                                    "type": "string",
                                    "x-ntx-summary": "Task detail"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "201": {
                        "description": "Created Task",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "data": {
                                    "type": "object",
                                    "properties": {
                                        "id": {
                                            "type": "string",
                                            "x-ntx-summary": "Task id"
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/tasks/{task_id}/attachments": {
            "post": {
                "summary": "Attach a file to a task",
                "description": "Attach a file to a specified task",
                "operationId": "AttachFile",
                "consumes": [ "multipart/form-data" ],
                "parameters": [
                    {
                        "name": "task_id",
                        "type": "string",
                        "in": "path",
                        "x-ntx-summary": "Task id",
                        "description": "Task",
                        "required": true
                    },
                    {
                        "in": "formData",
                        "name": "file",
                        "type": "file",
                        "required": true,
                        "description": "The file to attach."
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Ok"
                    }
                }
            }
        }
    },
    "securityDefinitions": {
        "oauth2": {
            "type": "oauth2",
            "flow": "accessCode",
            "authorizationUrl": "https://app.asana.com/-/oauth_authorize",
            "tokenUrl": "https://app.asana.com/-/oauth_token",
            "scopes": {}
        }
    }
}

Create the workflow

Step 1: Add your Xtension

Import the OpenAPI Specification you created into Nintex Automation Cloud:

  1. Open your Nintex Automation Cloud tenancy.
  2. Click Xtensions in the dashboard to open the Xtensions page.
  3. Click  in the Private connector list.
  4. Click Choose a file. Navigate to the OpenAPI Specification on your computer.
  5. Wait for Nintex Automation Cloud to validate the file.
  6. Click Next.
  1. Nintex Automation Cloud detects the OAuth 2.0 security template.
  2. Type the Client ID in the Client ID field.
  3. Type the shared secret in the Client Secret field.
  4. Click Next.
  1. Edit the Name of the Xtension, which becomes the name of the action group in the Workflow designer.
  2. Edit the Description of the Xtension. This appears in the Private connector list in the Xtensions page.
  3. Select or upload an icon for the Xtension. This is displayed for each action or event in the Workflow designer.
  4. Click Publish.

Step 2: Create your workflow

Create a workflow that is triggered when a new file is uploaded to a specific Box folder. The workflow creates a new task in Asana for a specified person to review the file, then attaches the file to the new Asana task.

For more information on creating workflows, see the Workflow Designer.

To create the workflow:

  1. Click Create workflow in your Nintex Automation Cloud tenancy.
  2. Configure the Start event to be a Box: New File event:
    • Select the folder where new uploads will trigger the workflow. For example, Review.
    • Click Add button to add the Name and File variable start variables to the workflow.

    For more information, see Box - New File.

  3. Drag a Create a task action after the start event.
  4. Configure the Create a task action:
    • Select the workspace to add the task to.
    • Select the person to assign the task to.
    • Type a name for the task.

      Tip: Add the Name variable to make each task name unique.

    • Add notes directing the assignee to review the attached file.
    • Create a collection variable to store the returned Task id.
  5. Drag an Attach a file to a task action after Create a task.
  6. Configure the Attach a file to a task action:
    • Use the task id collection variable as the Task id.
    • Select the File variable from the start event in The file to attach.
  7. Publish your workflow.

Tip:  If you want to troubleshoot an Xtension, select Development as the Assigned Use when you publish the workflow. Development workflows display more detailed error messages in their instance details. Republish your workflow as Production when you're ready to use it.

Step 3: Test your workflow

  1. Upload a new file into your Box folder.

    A new task is created in Asana with the file attached.