Wouldn’t it be great if there were a way to control Citrix Cloud from the command line interface (CLI)? Guess what? There is! In this post, I’ll explain how to get started and give you a peek at the magic behind it.

Before we go further, though, the “cx” tool described in this blog post was released as open source and is provided as is. It’s not officially qualified or supported by Citrix. You can raise feedback via GitHub with the developer community. I’ll do my best to respond.

I love Citrix Cloud’s graphical user interface (GUI) and its refreshed branding. But sometimes, as the IT geek I am, I prefer a CLI over the UI. Depending on the scenario, the CLI can provide:

  • More efficient access, particularly for repetitive tasks.
  • A history of past actions.
  • An ever-so-slightly different functionality unavailable in the GUI.
  • The means to automate operations such as regular backup of microapps or a service configuration.

Citrix Cloud has a rapidly growing range of REST APIs, but juggling API complexities such as authentication and bearer tokens, along with finding the right endpoints, can be an inconvenience in day-to-day operations. That’s why AWS has the “aws” CLI, and Azure has “az”.

And for Citrix, there now is the cx tool. The cx tool pulls the latest API specifications from Citrix’s Developer Portal and populates the CLI-command with all available operations. Meanwhile, the complexity of REST APIs remain hidden away.

Here are some highlights of the current set of “cx”-CLI features :

  • A simple and efficient way to interact with Citrix Cloud.
  • Support for many Citrix Cloud services, including Citrix Application and Delivery Management (ADM), App Personalization, Citrix Virtual Apps and Desktops, Global App Configuration, Citrix Virtual Apps and Desktops Standard for Azure, microapps, Citrix Endpoint Management reporting APIs, Citrix Secure Browser, Virtual Apps Essentials, Workspace Environment Management, and various Citrix Cloud platform APIs.
  • Always up to date because the CLI synchronizes the latest published APIs from Citrix’s Developer Portal.
  • Responses can be formatted as either JSON, YAML, Table, CSV, raw, or binary.
  • Powerful query and filter syntax powered by JMESPath.
  • Handles authentication and caches tokens transparently.
  • Secrets are stored using the user’s OS keyring service (Windows Credential Locker, macOS Keychain, etc.).
  • Autocompletion for Bash and Zsh.

Getting Started with the cx CLI

It’s easy to get started with cx CLI:

  1. Make sure you have Python 3.6 or later installed on your machine. Windows, Mac or Linux will work.
  2. Install the cx tool:
    `python3 -m pip install cxcli`
  3. Create a Citrix Cloud API Client “Secure Client” (To summarize: Log in to Citrix Cloud → Upper left corner menu → Identity and Access Management → API Access → Type a name → Create Client).
  4. Configure cx with the obtained API client credentials:
    cx --configure

That’s it.

You can explore the available commands and service via:

cx -h

You can show details about a particular command and service like this:

cx systemlog -h

And as a first step, try pulling the latest Citrix Cloud system logs for security auditing:

cx systemlog GetRecords

Or as a Citrix Virtual Apps and Desktops service admin, you may want to access session information. To do that, store your SiteId in a variable (the example below uses Bash):

site_id=$(cx cvadrestapis Me_GetMe --cliquery "Customers[0].Sites[0].Id" --output-as rawprint)
cx cvadrestapis Sessions_GetSessions --siteid $site_id

Meanwhile, as a microapp admin you can export integration bundles to back up or store them in your version control system:

cx microapps export_bundle --geo us --bundleExportType default --integrationExportConfig-id 1 --output-binary integration.mapp

Making backups is only fun when you can restore them, too. Here’s how to import a microapp integration bundle, providing the configuration options required for initialization (the example below uses Bash):

echo '{ "integrationImportConfig": { "type": "GWSC", "baseUrl": "https://mybaseurl/"} }' > config.txt
cx microapps import_bundle --geo us --config config.txt --bundle integration.mapp

The Secret Sauce Behind cx? APIs!

Citrix has seen tremendous growth in its developer community recently. It was only 18 months ago that I had organized the first Citrix Converge developer event. I remember trying to squeeze in one more chair in a Silicon Valley meeting room and worrying about ordering enough pizzas to entertain 140 of the most forward-thinking microapp builders out there.

The second Citrix Converge was completely different, as we broadened the scope to include Citrix’s complete product line. Amazingly, we counted a staggering 1,800 virtual attendees; all these curious developers need APIs, to automate, integrate and monitor Citrix solutions.

We’ll continue to support the developer community by extending the number of public Citrix REST APIs. This is essential to enabling integration between discrete microservices so you can build and tailor Citrix solutions to your business needs. APIs are documented on Citrix’s Developer Portal using the OpenAPI standard (formerly known as Swagger) to show parameters, enable live calls, and provide the specification itself for download by developers. Meanwhile, cx uses the same specification to parse command line parameters. That means whenever the API specification is updated, the cxli-tool will reflect the latest changes.

We Welcome Your Feedback!

Is this tool useful to you? What else do you need? Are you missing a feature? Would you like a certain Citrix service to publish its APIs? Would you like a certain use-case to be exposed via APIs? Would you also like a PowerShell SDK to make scripting Citrix Cloud easier? Let us know in the comments below.