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:
1
$ gem install xapixctl
Copied!
xapixctl 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
  1. 1.
    Log in to your Xapix account.
  2. 2.
    Click the User Profile icon (upper right corner).
  3. 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.
1
xapix-token=<XAPIX_TOKEN>
Copied!

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]
1
# Example Command
2
#
3
xapixctl api-resources --xapix-token=XAPIX_TOKEN
4
#
5
# where XAPIX_TOKEN is your API Access token
Copied!

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.
1
[--xapix-url=XAPIX_URL]
2
# Fallback: environment variable XAPIX_URL. URL to Xapix.
3
# Default: https://cloud.xapix.io/
4
Copied!

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 sync
Sync resources from/to directories
When running commands like apply and publish, you do not need to worry about interrupting the current usage of your endpoints. Anything that is still being processed by a previous version will continue being processed.

xapixctl help

Obtain help on how to use xapixctl on the command line.
1
xapixctl help [command]
Copied!

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.
1
$ xapixctl api-resources
2
Type Required Context
3
Ambassador Project
4
ApiPublishing Project
5
ApiPublishingRole Project
6
AuthScheme Project
7
CacheConnection Project
8
Credential Project
9
DataSource Project
10
Endpoint Project
11
EndpointGroup Project
12
Pipeline Project
13
Project Organization
14
Proxy Project
15
Scheduler Project
16
Schema Project
17
Service Project
18
ServiceInstall Project
19
Stream Project
20
StreamGroup Project
21
StreamProcessor Project
Copied!
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.
1
xapixctl apply --file=FILE
2
--org=ORG
3
[--project=PROJECT]
4
[--verbose]
Copied!

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.
1
$ xapixctl apply -v --org my-org -p my-first-project -f <path>/vehicle_demo_swagger.yaml
Copied!

xapixctl delete

Deletes all resources listed in the file or deletes resources by TYPE and ID.
1
xapixctl delete --org=ORG
2
[TYPE ID]
3
[--project=PROJECT]
4
[--file=FILE]
5
[--verbose]
Copied!

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.
1
xapixctl export --org=ORG
2
--project=PROJECT
3
[--format=FORMAT]
4
[--verbose]
Copied!

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.
1
xapixctl export -o xapix -p some-project
Copied!
Export resources from the project some-project in the organization xapix and save output to the file some_project.yaml.
1
xapctl export -o xapix -p some-project -f yaml > some_project.yaml
Copied!
Export the resources from the project my-first-project in the organization my-org. This is the project created in the Quickstart tutorial.
1
$ xapixctl export --org my-org -p my-first-project
2
id : my-first-project
3
kind: Project
4
name: My First Project
5
6
id : <redacted>
7
kind: Schema
8
name:
9
10
id : allvariants
11
kind: DataSource/REST
12
name: allVariants
13
14
id : findenginebyid
15
kind: DataSource/REST
16
name: findEngineById
17
18
id : findmodelbyid
19
kind: DataSource/REST
20
name: findModelById
21
22
id : findvariantbyid
23
kind: DataSource/REST
24
name: findVariantById
25
26
id : get-xapix-io-api-data-vehicle-demo-engines-engine_id-json
27
kind: Endpoint/REST
28
name: get
29
30
id : my-first-project
31
kind: ApiPublishing
32
name:
Copied!

xapitxctl get

List all the resources (overview) of a specific TYPE.
1
xapixctl get --org=ORG
2
TYPE
3
[--project=PROJECT]
4
[--format=FORMAT]
5
[ID]
Copied!

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.
1
xapixctl get --org my-org -p my-first-project Project
2
id : my-first-project
3
kind: Project
4
name: My First Project
Copied!
Retrieve a list of resources of the type Datasource. Both organization and project slugs are required. These are resources from Connectors in the Quickstart tutorial.
1
$ xapixctl get --org my-org -p my-first-project DataSource
2
id : allvariants
3
kind: DataSource/REST
4
name: allVariants
5
6
id : findenginebyid
7
kind: DataSource/REST
8
name: findEngineById
9
10
id : findmodelbyid
11
kind: DataSource/REST
12
name: findModelById
13
14
id : findvariantbyid
15
kind: DataSource/REST
16
name: findVariantById
Copied!
Retrieve a list of resources in a Datasource called allVariants and output the results in a YAML format.
1
xapixctl get --org my-org -p my-first-project DataSource allvariants -f yaml
Copied!
The output is shown below.
1
---
2
version: v1
3
kind: DataSource/REST
4
metadata:
5
id: allvariants
6
project: my-first-project
7
definition:
8
name: allVariants
9
url: <redacted>
10
httpMethod: get
11
cacheTtl: 7200
12
schema: <redacted>>
13
parameters:
14
- name: cookies
15
type: object
16
properties: []
17
- name: header
18
type: object
19
properties: []
20
- name: path
21
type: object
22
properties: []
23
- name: query
24
type: object
25
properties: []
26
attributes:
27
- name: body
28
type: object[]
29
properties:
30
- name: base_price_EUR
31
type: float
32
sample: 23456.78
33
- name: engine_type_id
34
type: integer
35
sample: 547290
36
- name: extras
37
type: string[]
38
sample: ''
39
- name: fuel_consumption_lkm
40
type: float
41
sample: 12.6
42
- name: in_stock
43
type: boolean
44
sample: true
45
- name: model_id
46
type: integer
47
sample: 947432
48
- name: topspeed_kmh
49
type: integer
50
sample: 220
51
- name: variant_id
52
type: string
53
sample: QLM_KROSUS_4_DOORS_LIMO
54
Copied!

xapixctl publish

Publishes the current status of a given project.
1
xapixctl publish --org=ORG --project=PROJECT
Copied!

Required parameters

--org, -o
  • Slug of the organization in which the project exists which will be published by the command.
--project, -p
  • Slug of project to be published.

xapixctl sync

Sync resources from or to directories
  • sync to-dir will export all resources of a given project to a directory and remove any additional resources from the directory
  • sync from-dir will import all resources into the given project from the directory and remove any additional resources which are not present in the directory
  • exclude flags are available to allow for the exclusion or inclusion of credentials as well as the exclusion of any other resource types from the synchronization
See the help resource in xapixctl for more details
1
xapixctl sync -h
Copied!
Example command structure: sync to-dir
1
xapixctl sync to-dir FOLDER -o=ORG -p=PROJECT --xapix-token=TOKEN --xapix-url=URL
Copied!

Contributing

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