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:
- Click Repositories in your home page.
- Click New.
- Type a unique name for your repository.
- Click Create repository.
Create the Xtension
Step 1: Create the basic OpenAPI Specification
Create an OpenAPI Specification that:
- Useshttps Hypertext Transfer Protocol Secure: the protocol by which websites and APIs communicate securely over the internet.with the host The domain name of the third-party API's URL.api.github.com.
- Uses basic authentication Identifying the API requestor using a username and password passed in the HTTP header..
- Defines two operations A single request to a third-party API. Operations often become actions in the workflow designer.:
- /user/repos using the get method that takes no parameters A piece of information passed to a third-party API during a request..
- /repos/{owner}/{repo}/contents/{path} using the put method that takes three parameters in the path The part of the URL after the hostname that directs the request to a specific resources within the host. For example, the section after "example.com" in http://example.com/this/is/a/path. and a response The return from a third-party API after a request has been made by the client. body:
- owner in the path for the username that owns the repository.
- repo in the path, which uses x-ntx-dynamic-values to retrieve a list of values from /user/repos.
- path in the path for the file name of the file to add.
- message in the body The part of an HTTP request or response that can contain an arbitrary amount of data, such as the content of a form or web page., for the commit message to add with the upload.
All parameters are required.
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:
- Open your Nintex Automation Cloud tenancy.
- Click Xtensions in the dashboard to open the Xtensions page.
- Click in the Private connector list.
- Click Choose a file. Navigate to the OpenAPI Specification on your computer.
- Wait for Nintex Automation Cloud to validate the file.
- Click Next.
- Nintex Automation Cloud detects the basic authentication security
template.
- Click Next.
- Edit the Name of the Xtension, which becomes the name of the action group in the Workflow designer.
- Edit the Description of the Xtension. This appears in the Private connector list in the Xtensions page.
- Select or upload an icon for the Xtension. This is displayed for each action or event in the Workflow designer.
- 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.
- Click Create workflow in your Nintex Automation Cloud tenancy.
- 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 to add the Name and File variable start variables to
the workflow.
For more information, see Box - New File.
- Drag a GitHub: Upload a file action after the start event.
- Configure the Upload a file action:
- Type the GitHub username for the repository.
- Select which Repository you want to upload the file to.
- Add the Name start variable in the Type a file name field.
- Type a commit message in the Commit message field.
- Select the File variable from the start even as the File to
upload.
- 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
- Upload a new file into your Box folder.
The file is added to the GitHub repository.