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:
- Click Repositories in your home page.
- Click New.
- Type a unique name for your repository.
- Click Create repository.
Import base64-encoded files
Step 1: Create the basic OpenAPI Specification
Create an OpenAPI Specification that:
- Uses https 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}/readme} using the get method that takes two 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. :
- 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.
Both parameters are required.
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:
- 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.
- Click Next.
Nintex Automation Cloud detects the basic authentication security
template.
- 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 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.
- Click Create workflow in your Nintex Automation Cloud tenancy.
- 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.
- Drag a GitHub: Download a file action after the Start event.
- Configure the Download a file action:
- In the Repository owner field, type the GitHub username for the repository.
- Select which Repository you want to download the file from.
- Click and select Edit to open the Store a File options.
- In the Location options, select Connector.
- In the Connector field, select a file sync service to store the file temporarily.
- In the Connection field, select the connection to use with the file sync service.
- In the Path and file name field, type the file name to store the
file.
Note: If you select Variable, the file name and file extension are not included in the emailed file.
- Drag a Set a variable value action after the Download a file action.
For more information, see Set a variable value. - 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. - Configure the Send an email action to send the file to the email address from the web form.
- Click Test to test the workflow.
- 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.