Xapix CLI (xapixctl)

xapixctl is the Xapix command line tool that includes a client library you use to run tasks on a command line or in a batch file. Normally, these tasks are done in the Xapix UI.

With these commands you can create scripts and then automate sets of tasks depending on your requirements.

Installing xapixctl

Installing xapixctl is very simple. Just run the following command and you are ready to go:

$ gem install xapixctl

xapixctrl requires Ruby installed on your system.

Setting environment variables

Before you can use xapixctl, you need to set the environment variables. These include

  • API access token, which is specific to a Xapix user account

  • Xapix URL, which is specific to a project

These environment variables can be set in your OS or they can be set once per session. If they are set in your OS, you need not set them each time you open a session. However, this assumes the same environment variables will be used every time xapixctl is run.

If you have several Xapix accounts and/or several Xapix projects, setting them once per session might be a better option. Instructions for setting these environment variables are provided below.

API Access Token

To use xapixctl, add your API Access Token to your environment variables of your OS.

Obtaining API access token

Steps
Steps
  1. Log in to your Xapix account.

  2. Click the User Profile icon (upper right corner).

  3. In the API Access Token pane, click the Copy icon.

Setting Xapix API access token in the OS

Procedures for setting the API access token in the OS depend on which OS you are using. Consult the relevant documentation.

xapix-token=<your xapix token

Setting API access token per session

To set the API access token for a session, add the following option to a xapixctl command.

  • [--xapix-token=XAPIX_TOKEN]

# Example Command
#
xapixctl api-resources --xapix-token=XAPIX_TOKEN
#
# where XAPIX_TOKEN is your API Access token

Xapix URL

You can set a Xapix URL as an environment variable, such as https://cloud.xapix.io/.

Alternately, you can set it for a one-time only use when running a command as shown below.

[--xapix-url=XAPIX_URL]
# Fallback: environment variable XAPIX_URL. URL to Xapix.
# Default: https://cloud.xapix.io/

Commands List

Command

Description

xapixctl help

Help on the command line.

xapixctl api-resources

Available resource types.

xapixctl apply

Create or update resources.

xapixctl delete

Delete resources in a file.

xapixctl export

Export all resources in a project.

xapitxctl get

Export resources of given type and id.

xapixctl publish

Publish current version of project.

xapixctl help

Obtain help on how to use xapixctl on the command line.

xapixctl help [command]

Optional parameters

[command]

  • Retrieves help for the specified command. If no command is given, a list of commands is provided.

xapixctl api-resources

Lists all available resources.

Parameters

None.

Example

The following shows the output from running the command.

$ xapixctl api-resources
Type Required Context
Ambassador Project
ApiPublishing Project
ApiPublishingRole Project
AuthScheme Project
CacheConnection Project
Credential Project
DataSource Project
Endpoint Project
EndpointGroup Project
Pipeline Project
Project Organization
Proxy Project
Schema Project
Stream Project
StreamGroup Project

This list shows the TYPE and context for the TYPE.

  • Example 1: The TYPE Project is within the context Organization. This means a Project can only be within the context Organization.

  • Example 2: The TYPE Datasource can only be within the context Project.

xapixctl apply

Creates a new resource or updates an existing resource in the specified organization. If no project is given, the command applies to the project or projects specified in the file. New resources are created if none exists.

Resources are matched using TYPE and ID. Updates a resource if a resource has the same TYPE and ID exists.

xapixctl apply --file=FILE
--org=ORG
[--project=PROJECT]
[--verbose]

Required parameters

--file -f

  • YAML or JSON file used to update or create a resource. It can contain multiple projects.

--org -o

  • Slug of an organization to apply the resource.

Optional parameters

--project, -p

  • Slug of project to apply the resource.

--verbose, -v

  • Write message stream to terminal.

Example

Update the project my-first-project in the organization my-org with the resources (which are datasources) in vehicle_demo_swagger.yaml.

$ xapixctl apply -v --org my-org -p my-first-project -f <path>/vehicle_demo_swagger.yaml

xapixctl delete

Deletes all resources listed in the file or deletes resources by TYPE and ID.

xapixctl delete --org=ORG
[TYPE ID]
[--project=PROJECT]
[--file=FILE]
[--verbose]

Required parameters

--org, -o

  • Slug of the organization to which delete command will be applied.

Optional parameters

[TYPE ID]

  • Provide the TYPE of API resource (see xapix api-resource) and the ID of the resource (see xapixctl get).

--project, -p

  • Slug of project to which the delete command will be applied.

--file, -f

  • File which provides the resources to be deleted.

--verbose, -v

  • Write message stream to terminal.

xapixctl export

Exports a list of all resources of a given TYPE in a given project.

xapixctl export --org=ORG
--project=PROJECT
[--format=FORMAT]
[--verbose]

Required parameters

--org, -f

  • slug of organization from which to export a list of all resources of a given TYPE.

--project, -p

  • slug of project from which to export a list of all resources of a given type.

Optional parameters

--format, -f

  • Format of exported resources. Can be either JSON or YAML.

--verbose, -v

  • Write message stream to terminal.

Examples

Export resources from the project some-project in the organization xapix.

xapixctl export -o xapix -p some-project

Export resources from the project some-project in the organization xapix and save output to the file some_project.yaml.

xapctl export -o xapix -p some-project -f yaml > some_project.yaml

Export the resources from the project my-first-project in the organization my-org. This is the project created in the Quickstart tutorial.

$ xapixctl export --org my-org -p my-first-project
id : my-first-project
kind: Project
name: My First Project
id : <redacted>
kind: Schema
name:
id : allvariants
kind: DataSource/REST
name: allVariants
id : findenginebyid
kind: DataSource/REST
name: findEngineById
id : findmodelbyid
kind: DataSource/REST
name: findModelById
id : findvariantbyid
kind: DataSource/REST
name: findVariantById
id : get-xapix-io-api-data-vehicle-demo-engines-engine_id-json
kind: Endpoint/REST
name: get
id : my-first-project
kind: ApiPublishing
name:

xapitxctl get

List all the resources (overview) of a specific TYPE.

xapixctl get --org=ORG
TYPE
[--project=PROJECT]
[--format=FORMAT]
[ID]

Required parameters

--org, -o

  • Organization to which the request is done.

TYPE

  • Requests on an organization are done on a project. Requests on a project can be done on a TYPE within the Project context.

For a list of types, see xapixctl api-resources.

Optional parameters

--project, -p

  • Project to which the request is done.

--format, -f

  • Format of exported resources. Can be either JSON or YAML.

ID

  • TYPE id.

Examples

Retrieve the name of a project, if only the slug is available.

xapixctl get --org my-org -p my-first-project Project
id : my-first-project
kind: Project
name: My First Project

Retrieve a list of resources of the type Datasource. Both organization and project slugs are required. These are resources are from data sources in the Quickstart tutorial.

$ xapixctl get --org my-org -p my-first-project DataSource
id : allvariants
kind: DataSource/REST
name: allVariants
id : findenginebyid
kind: DataSource/REST
name: findEngineById
id : findmodelbyid
kind: DataSource/REST
name: findModelById
id : findvariantbyid
kind: DataSource/REST
name: findVariantById

Retrieve a list of resources in a Datasource called allVariants and output the results in a YAML format.

xapixctl get --org my-org -p my-first-project DataSource allvariants -f yaml

The output is shown below.

---
version: v1
kind: DataSource/REST
metadata:
id: allvariants
project: my-first-project
definition:
name: allVariants
url: <redacted>
httpMethod: get
cacheTtl: 7200
schema: <redacted>>
parameters:
- name: cookies
type: object
properties: []
- name: header
type: object
properties: []
- name: path
type: object
properties: []
- name: query
type: object
properties: []
attributes:
- name: body
type: object[]
properties:
- name: base_price_EUR
type: float
sample: 23456.78
- name: engine_type_id
type: integer
sample: 547290
- name: extras
type: string[]
sample: ''
- name: fuel_consumption_lkm
type: float
sample: 12.6
- name: in_stock
type: boolean
sample: true
- name: model_id
type: integer
sample: 947432
- name: topspeed_kmh
type: integer
sample: 220
- name: variant_id
type: string
sample: QLM_KROSUS_4_DOORS_LIMO

xapixctl publish

Publishes the current status of a given project.

xapixctl publish --org=ORG --project=PROJECT

Required parameters

--org, -0

  • Slug of the organization in which the project exists which will be published by the command.

--project, -p

  • Slug of project to be published.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/xapix-io/xapixctl.