Create a custom connector with the CLI

The paconn command-line tool helps you create custom connectors for Copilot Studio and Power Platform.

Note

Install Python and paconn

  1. Install Python 3.5 or later from [https://www.python.org/downloads](Python downloads). Select the Download link for any version of Python greater than Python 3.5. For Linux and macOS, follow the appropriate link on the page. You can also install Python by using an OS-specific package manager of your choice.

  2. Run the installer to begin installation and check the box Add Python X.X to PATH.

  3. Ensure the installation path is in the PATH variable by running:

    python --version

  4. After Python is installed, install paconn by running:

    pip install paconn

    If you get errors saying Access is denied, consider using the --user option or running the command as an Administrator (Windows).

Custom connector directory and files

A custom connector consists of two to four files:

  • an Open API or Swagger definition
  • an API properties file
  • an optional icon for the connector
  • an optional C# script file

You find the files in a directory that uses the connector ID as its name.

Sometimes, the custom connector directory includes a settings.json file. Although this file isn't part of the connector definition, you can use it as an argument store for the CLI.

API definition (Swagger) file

The API definition file describes the API for the custom connector by using the OpenAPI specification. This specification is also known as the Swagger file. For more information about how an API definition file helps you create a custom connector, see Create a custom connector from an OpenAPI definition. Also, review the tutorial in the Extend an OpenAPI definition for a custom connector article.

API properties file

The API properties file contains properties for the custom connector that aren't part of the API definition. It includes information such as the brand color and authentication information. A typical API properties file looks like the following sample:

{
  "properties": {
    "capabilities": [],
    "connectionParameters": {
      "api_key": {
        "type": "securestring",
        "uiDefinition": {
          "constraints": {
            "clearText": false,
            "required": "true",
            "tabIndex": 2
          },
          "description": "The KEY for this API",
          "displayName": "KEY",
          "tooltip": "Provide your KEY"
        }
      }
    },
    "iconBrandColor": "#007EE6",
    "scriptOperations": [
        "getCall",
        "postCall",
        "putCall"
    ],
    "policyTemplateInstances": [
      {
        "title": "MyPolicy",
        "templateId": "setqueryparameter",
        "parameters": {
            "x-ms-apimTemplateParameter.name": "queryParameterName",
            "x-ms-apimTemplateParameter.value": "queryParameterValue",
            "x-ms-apimTemplateParameter.existsAction": "override"
        }
      }
    ]    
  }
}

Here's more information on each property:

  • properties: The container for the information.

  • connectionParameters: Defines the connection parameter for the service.

  • iconBrandColor: The icon brand color in HTML hex code for the custom connector.

  • scriptOperations: A list of the operations that execute with the script file. An empty scriptOperations list indicates that all operations execute with the script file.

  • capabilities: Description of the connector's capabilities, such as cloud-only and on-prem gateway.

  • policyTemplateInstances: An optional list of policy-template instances and values the custom connector uses.

Icon file

The icon file is a small image representing the custom connector icon.

Script file

The Visual C# Script (CSX) script file deploys for the custom connector and executes for every call to a subset of the connector's operations.

Settings file

Instead of providing the arguments in the command line, use a settings.json file to specify them. A typical settings.json file looks like this sample:

{
  "connectorId": "CONNECTOR-ID",
  "environment": "ENVIRONMENT-GUID",
  "apiProperties": "apiProperties.json",
  "apiDefinition": "apiDefinition.swagger.json",
  "icon": "icon.png",
  "script": "script.csx",
  "powerAppsApiVersion": "2016-11-01",
  "powerAppsUrl": "https://api.powerapps.com"
}

Expect these items in the settings file. If an option is missing but required, the console prompts for the missing information.

  • connectorId: The connector ID string for the custom connector. Download and update operations require the connector ID parameter, while the create and validate operations don't. The create command creates a new custom connector with a new ID. If you need to update an existing custom connector by using the same settings file, ensure you update the settings file with the new connector ID from the create operation.

  • environment: The environment ID string for the custom connector. All operations require this parameter, except the validate operation.

  • apiProperties: The path to the API properties file. Create and update operations require the API properties file. When this option is present during the download, the file downloads to its location; otherwise the file saves as apiProperties.json.

  • apiDefinition: The path to the swagger file. The create, update, and validate operations require the API definitions file. When this option is present during the download operation, the file downloads to its location; otherwise the file saves as apiDefinition.swagger.json.

  • icon: The path to the optional icon file. If there's no specification for this parameter, the create and update operations use the default icon. When this option is present during the download operation, the file downloads to its location; otherwise the file saves as icon.png.

  • script: The path to the optional script file. The create and update operations only use the value within the specified parameter. When this option is present during the download operation,the file downloads to its location; otherwise the file saves as script.csx.

  • powerAppsUrl: The API URL for Power Apps. This parameter is optional and set to https://api.powerapps.com by default.

  • powerAppsApiVersion: The API version to use for Power Apps. This parameter is optional and set to 2016-11-01 by default.

Command line operations

Sign in

Sign in to Power Platform by running:

paconn login

This command prompts you to sign in by using the device code authentication process. Follow the prompt for authentication. This command doesn't support service principal authentication.

Sign out

Sign out by running:

paconn logout

Download custom connector files

Always download the connector files into a subdirectory with the connector ID as the directory name. When you specify a destination directory, this directory becomes the parent for the new subdirectory. If you don't specify a destination directory, the subdirectory is created in the current directory. In addition to the three connector files, the download operation creates a fourth file called settings.json that contains the parameters used to download the files.

Download the custom connector files by running:

paconn download

or

paconn download -e [Power Platform Environment GUID] -c [Connector ID]

or

paconn download -s [Path to settings.json]

If you don't specify the environment or connector ID, the command prompts you for the missing arguments. If the download succeeds, the command outputs the download location for the connector.

You can also specify all the arguments by using a settings.json file.

Arguments
   --cid -c       : The custom connector ID.
   --dest -d      : Destination directory.
   --env -e       : Power Platform environment GUID.
   --overwrite -w : Overwrite all the existing connector and settings files.
   --pau -u       : Power Platform URL.
   --pav -v       : Power Platform API version.
   --settings -s  : A settings file containing required parameters.
                    When a settings file is specified some command 
                    line parameters are ignored.

Create a new custom connector

You can create a new custom connector from the connector files by running the create operation. Create a connector by running:

paconn create --api-prop [Path to apiProperties.json] --api-def [Path to apiDefinition.swagger.json]

or

paconn create -e [Power Platform Environment GUID] --api-prop [Path to apiProperties.json] --api-def [Path to apiDefinition.swagger.json] --icon [Path to icon.png] --secret [The OAuth2 client secret for the connector]

or

paconn create -s [Path to settings.json] --secret [The OAuth2 client secret for the connector]

When you don't specify the environment, the command prompts for it. However, you need to provide the API definition and API properties file as part of the command-line argument or a settings file. Provide the OAuth2 secret for a connector by using OAuth2. The command prints the connector ID for the newly created custom connector on successful completion. If you're using a settings.json file for the create command, ensure you update it with the new connector ID before you update the newly created connector.

Arguments
   --api-def     : Location for the Open API definition JSON document.
   --api-prop    : Location for the API properties JSON document.
   --env -e      : Power Platform environment GUID.
   --icon        : Location for the icon file.
   --script -x   : Location for the script file.
   --pau -u      : Power Platform URL.
   --pav -v      : Power Platform API version.
   --secret -r   : The OAuth2 client secret for the connector.
   --settings -s : A settings file containing required parameters.
                   When a settings file is specified some command 
                   line parameters are ignored.

Update an existing custom connector

Like the create operation, you can update an existing custom connector by using the update operation. Update a connector by running:

paconn update --api-prop [Path to apiProperties.json] --api-def [Path to apiDefinition.swagger.json]

or

paconn update -e [Power Platform Environment GUID] -c [Connector ID] --api-prop [Path to apiProperties.json] --api-def [Path to apiDefinition.swagger.json] --icon [Path to icon.png] --secret [The OAuth2 client secret for the connector]

or

paconn update -s [Path to settings.json] --secret [The OAuth2 client secret for the connector]

When you don't specify the environment or connector ID, the command prompts for the missing argument(s). However, you need to provide the API definition and API properties file as part of the command-line argument or a settings file. Provide the OAuth2 secret for a connector by using OAuth2. The command prints the updated connector ID on successful completion. If you use a settings.json file for the update command, ensure you specify the correct environment and connector ID.

Arguments
   --api-def     : Location for the Open API definition JSON document.
   --api-prop    : Location for the API properties JSON document.
   --cid -c      : The custom connector ID.
   --env -e      : Power Platform environment GUID.
   --icon        : Location for the icon file.
   --script -x   : Location for the script file.
   --pau -u      : Power Platform URL.
   --pav -v      : Power Platform API version.
   --secret -r   : The OAuth2 client secret for the connector.
   --settings -s : A settings file containing required parameters.
                   When a settings file is specified some command 
                   line parameters are ignored.

Validate a swagger JSON

The validate operation takes a swagger file and verifies whether it follows all the recommended rules. Validate a swagger file by running:

paconn validate --api-def [Path to apiDefinition.swagger.json]

or

paconn validate -s [Path to settings.json]

The command prints the error, warning, or success message depending on the result of the validation.

Arguments
   --api-def     : Location for the Open API definition JSON document.
   --pau -u      : Power Platform URL.
   --pav -v      : Power Platform API version.
   --settings -s : A settings file containing required parameters.
                   When a settings file is specified some command 
                   line parameters are ignored.

Best practice

Download all the custom connectors and use Git or any other source control system to save the files. If there's an incorrect update, redeploy the connector by rerunning the update command with the correct set of files from the source control system.

Test the custom connector and the settings file in a test environment before deploying in the production environment. Always double check that the environment and connector ID are correct.

Limitations

The paconn CLI is limited to creation, update, and download of a custom connector in Copilot Studio, Power Automate, and Power Apps environments. When you don't specify an environment, you only have the option to select a Power Automate environment. For a non-custom connector, the swagger file isn't returned.

Note

stackOwner property and API properties file

Currently, there's a limitation that prevents you from updating your connector's artifacts in your environment by using Paconn when the stackOwner property is present in your API properties file. As a workaround, create two versions of your connector artifacts:

  • Create one version that contains the stackOwner property and submit it for certification.
  • Create a second version that omits stackOwner to enable you to make updates in your own environment.

We're working to remove the limitation and will update this section once complete.

Reporting issues and feedback

If you encounter any bugs with the tool, submit an issue in the Issues section of our GitHub repo.

If you believe you found a security vulnerability that meets Microsoft's definition of a security vulnerability, submit a report to MSRC. For more information, see MSRC frequently asked questions on reporting.

Provide feedback

We greatly appreciate feedback on issues with our connector platform, or new feature ideas. To provide feedback, go to Submit issues or get help with connectors and select your feedback type.