Upload base64 files

In this example, you will upload a base64-encoded file into a repository in the open-source version control service GitHub. The workflow is triggered by a new file arriving in a specified Box folder, allowing you to automate your repository upload process.

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. New and changed files are "committed" to the repository with a message detailing the reason for their change or inclusion. This example uploads a new file into a repository.

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.

Create the Xtension

Step 1: Create the basic OpenAPI Specification

Create an OpenAPI Specification that:

Note: If additionalProperties is not defined for an object, it defaults to true, allowing workflow designers to add arbitrary properties to that object.

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": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "properties": {
                                    "full_name": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/repos/{owner}/{repo}/contents/{path}": {
            "put": {
                "summary": "Upload a file",
                "description": "Upload a file",
                "operationId": "UploadFile",
                "security": [
                    {
                        "basicAuth": []
                    }
                ],
                "parameters": [
                    {
                        "name": "owner",
                        "type": "string",
                        "in": "path",
                        "x-ntx-summary": "GitHub username",
                        "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-path": "name",
                            "value-title": "name"
                        }
                    },
                    {
                        "name": "path",
                        "type": "string",
                        "in": "path",
                        "x-ntx-summary": "Type a file name",
                        "description": "Path",
                        "required": true
                    },
                    {
                        "name": "content",
                        "in": "body",
                        "description": "body",
                        "required": true,
                        "schema": {
                            "type": "object",
							"additionalProperties": false,
                            "properties": {
                                "message": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "content": {
                                    "type": "object",
                                    "properties": {
                                        "url": {
                                            "type": "string"
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "securityDefinitions": {
        "basicAuth": {
            "type": "basic"
        }
    }
}

Step 2: Add the file object to the parameter schema

In the body parameter of the /repos/{owner}/{repo}/contents/{path} operation, add content to the properties of the schema object.

 		
{
    "name": "content",
    "in": "body",
    "description": "body",
    "required": true,
    "schema": {
        "type": "object",
		"additionalProperties": false,
        "properties": {
            "message": {
                "type": "string"
            },
            "content": {
                
            }
        }
    }
}

Step 3: Add the base64-encoding properties to the content object

In the content object, add:

  • type with a value of string.
  • format with a value of byte.
 
{
    "name": "content",
    "in": "body",
    "description": "body",
    "required": true,
    "schema": {
        "type": "object",
		"additionalProperties": false,
        "properties": {
            "message": {
                "type": "string"
                "x-ntx-summary": "Commit message"
            },
            "content": {
                "type": "string",
                "format": "byte"
                "x-ntx-summary": "File to upload"
            }
        }
    }
}

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": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "properties": {
                                    "full_name": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/repos/{owner}/{repo}/contents/{path}": {
            "put": {
                "summary": "Upload a file",
                "description": "Upload a file",
                "operationId": "UploadFile",
                "security": [
                    {
                        "basicAuth": []
                    }
                ],
                "parameters": [
                    {
                        "name": "owner",
                        "type": "string",
                        "in": "path",
                        "x-ntx-summary": "GitHub username",
                        "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-path": "name",
                            "value-title": "name"
                        }
                    },
                    {
                        "name": "path",
                        "type": "string",
                        "in": "path",
                        "x-ntx-summary": "Type a file name",
                        "description": "Path",
                        "required": true
                    },
                    {
                        "name": "content",
                        "in": "body",
                        "description": "body",
                        "required": true,
                        "schema": {
                            "type": "object",
							"additionalProperties": false,
                            "properties": {
                                "message": {
                                    "type": "string"
                                },
                                "content": {
                                    "type": "string",
                                    "format": "byte"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "content": {
                                    "type": "object",
                                    "properties": {
                                        "url": {
                                            "type": "string"
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "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.
  1. Nintex Automation Cloud detects the basic authentication security template.
  2. 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 adds a file to a selected GitHub repository when the file is uploaded into a specific Box folder.

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 Box: New File event:
    • Select the folder where new uploads will trigger the workflow. For example, Approved.
    • 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 GitHub: Upload a file action after the start event.
  4. Configure the Upload a file action:
    1. Type the GitHub username for the repository.
    2. Select which Repository you want to upload the file to.
    3. Add the Name start variable in the Type a file name field.
    4. Type a commit message in the Commit message field.
    5. Select the File variable from the start even as the File to upload.
  5. 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.

    The file is added to the GitHub repository.