Download base64 files

In this example, you will download a base64-encoded text file from a repository in the open-source version control service GitHub. The workflow is triggered by a web form where a developer indicates interest in developing for your API, allowing you to automate this initial interaction.

Also see the how-to on Base64 files.

GitHub is an open-source distributed version control service, allowing you to upload files into a project, called a repository, and track their development as people on your team or outside of it submit suggested changes. Repositories usually have a text file explaining their purpose, use or other information. This example downloads this text file to send to an inquiring developer.

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.

Create a GitHub account and repository

If you do not already have a GitHub account, sign up to create your first GitHub account at https://github.com/join.

In your GitHub account:

  1. Click Repositories in your home page.
  2. Click New.
  3. Type a unique name for your repository.
  4. Click Create repository.

Import base64-encoded files

Step 1: Create the basic OpenAPI Specification

Create an OpenAPI Specification that:

For more information on using x-ntx-dynamic-values, see x-ntx-dynamic-values.

 
{
    "swagger": "2.0",
    "info": {
        "version": "1.0.0",
        "title": "GitHub"
    },
    "host": "api.github.com",
    "schemes": [ "https" ],
    "produces": [ "application/json" ],
    "consumes": [ "application/json" ],
    "paths": {
        "/user/repos": {
            "get": {
                "summary": "List repositories",
                "description": "List repositories",
                "operationId": "listRepos",
                "x-ntx-visibility": "internal",
                "security": [
                    {
                        "basicAuth": []
                    }
                ],
                "parameters": [],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {}
                    }
                }
            }
        },
        "/repos/{user}/{repo}/readme": {
            "get": {
                "summary": "Download a file",
                "description": "Download a file",
                "operationId": "GetFile",
                "security": [
                    {
                        "basicAuth": []
                    }
                ],
                "parameters": [
                    {
                        "name": "user",
                        "type": "string",
                        "in": "path",
                        "x-ntx-summary": "Repository owner",
                        "description": "Owner",
                        "required": true
                    },
                    {
                        "name": "repo",
                        "type": "string",
                        "in": "path",
                        "x-ntx-summary": "Select repository",
                        "description": "Repository",
                        "required": true,
                        "x-ntx-dynamic-values": {
                            "operationId": "listRepos",
                            "value-title": "name",
                            "value-path": "name"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "securityDefinitions": {
        "basicAuth": {
            "type": "basic"
        }
    }
}

Step 2: Add the file object to the response schema

In the properties object of the schema in the response, add a content object with:

  • The type of string.
  • The format of byte.
 		
"responses": {
    "200": {
        "description": "OK",
        "schema": {
            "type": "object",
            "properties": {
                "content": {
                    "type": "string",
                    "format": "byte"
                }
            }
        }
    }
}

The OpenAPI Specification

 
{
    "swagger": "2.0",
    "info": {
        "version": "1.0.0",
        "title": "GitHub"
    },
    "host": "api.github.com",
    "schemes": [ "https" ],
    "produces": [ "application/json" ],
    "consumes": [ "application/json" ],
    "paths": {
        "/user/repos": {
            "get": {
                "summary": "List repositories",
                "description": "List repositories",
                "operationId": "listRepos",
                "x-ntx-visibility": "internal",
                "security": [
                    {
                        "basicAuth": []
                    }
                ],
                "parameters": [],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {}
                    }
                }
            }
        },
        "/repos/{user}/{repo}/readme": {
            "get": {
                "summary": "Download a file",
                "description": "Download a file",
                "operationId": "GetFile",
                "security": [
                    {
                        "basicAuth": []
                    }
                ],
                "parameters": [
                    {
                        "name": "user",
                        "type": "string",
                        "in": "path",
                        "x-ntx-summary": "Repository owner",
                        "description": "Owner",
                        "required": true
                    },
                    {
                        "name": "repo",
                        "type": "string",
                        "in": "path",
                        "x-ntx-summary": "Select repository",
                        "description": "Repository",
                        "required": true,
                        "x-ntx-dynamic-values": {
                            "operationId": "listRepos",
                            "value-title": "name",
                            "value-path": "name"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "content": {
                                    "type": "string",
                                    "format": "byte"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "securityDefinitions": {
        "basicAuth": {
            "type": "basic"
        }
    }
}

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.

    Nintex Automation Cloud detects the basic authentication security template.

  1. 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 by a public web form, downloads the readme file from the GitHub repository, and emails it to the email address from the web form.

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

  1. Click Create workflow in your Nintex Automation Cloud tenancy.
  2. Configure the Start event to be a Nintex form, with:
    • A text field for the developer's name.
    • An email field.

    For more information on designing forms in Nintex Automation Cloud, see Design a form.

  3. Drag a GitHub: Download a file action after the Start event.
  4. Configure the Download a file action:
    1. In the Repository owner field, type the GitHub username for the repository.
    2. Select which Repository you want to download the file from.
    3. Click and select Edit to open the Store a File options.
    4. In the Location options, select Connector.
    5. Note:  If you select Variable, the file name and file extension are not included in the emailed file.

    6. In the Connector field, select a file sync service to store the file temporarily.
    7. In the Connection field, select the connection to use with the file sync service.
    8. In the Path and file name field, type the file name to store the file.
  5. Drag a Set a variable value action after the Download a file action.
    For more information, see Set a variable value.
  6. Configure the action to store the file from the Xtension.
    Drag a Send an email action after the Set a variable value action.
    For more information, see Send an email.
  7. Configure the Send an email action to send the file to the email address from the web form.
  8. Click Test to test the workflow.
  9. Save or publish the 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.