Examples of handling a JSON response

Examples of handling a JSON response

When you execute Acquia CLI commands invoking a Cloud Platform API endpoint, the endpoint returns a machine-readable JSON response.

Acquia recommends you to use the following open source tools to navigate the JSON response:

  • jq: Lightweight and flexible JSON processor. Acquia recommends you to read the manual to discover its possibilities.
  • jid: JSON incremental digger
  • jtbl: Print JSON and JSON Lines data as a table

Finding the last three Cloud events for an application

Use the limit filter in jq to return a subset of the results:

$ acli api:applications:notification-list myapp | jq '[limit(3;.[] | {event, completed_at})]'
[
  {
    "event": "DatabaseBackupDownloaded",
    "completed_at": "2021-02-24T16:13:37+00:00"
  },
  {
    "event": "RemoteIdeCreatedEvent",
    "completed_at": "2021-02-24T13:22:03+00:00"
  },
  {
    "event": "DatabaseBackupDownloaded",
    "completed_at": "2021-02-23T18:23:29+00:00"
  }
]

Filtering out application details for an arbitrary sitegroup

Pass the following select query to search for a partial match in the JSON output:

$ acli api:applications:list | jq '.[] | select(.hosting.id | contains ("thomas"))'

The query returns the following output, where <version> refers to the version of your Drupal application:

{
  "id": 111241,
  "uuid": "da76k877-fc7f-bcf4-2523-c801f469b9dc",
  "name": "thomas",
  "hosting": {
    "type": "ace",
    "id": "prod:thomas"
  },
  "subscription": {
    "uuid": "1054c7fc-8954-4e52-b132-a4f5bc3a7d16",
    "name": "Thomas - Sandbox"
  },
  "organization": {
    "uuid": "d29ej812-7c03-11e4-b588-22000b04072f",
    "name": "My Drupal <version> Application"
  },
  "flags": {
    "remote_admin": false
  },
  "status": "normal",
  "type": "drupal",
  "platform": null,
  "_links": {
    "self": {
      "href": "https://cloud.acquia.com/api/applications/da76k877-fc7f-bcf4-2523-c801f469b9dc"
    },
    "parent": {
      "href": "https://cloud.acquia.com/api/applications"
    }
  },
  "_embedded": {
    "tags": []
  }
}

Finding all Cloud environments for an application

Use jq to filter out the JSON response:

$ acli api:applications:environment-list myapp | jq '.[].name'
"dev"
"prod"
"test"
"ra"
"ama"

Interactively drilling down into the JSON response

Use jid to scan through the JSON response until you find the desired result:

Viewing results in a table

Use the following jtbl to improve the readability of the JSON response. If your output is not complex, pipe it to jtbl to view a formatted table:

$ acli api:distributions:list | jq -c '.[] | {title,version}' | jtbl

The command returns the following output, where <major-version> refers to the current major version of your Drupal application, and <specific-version> refers to the specific version of your Drupal application.

title                              version
---------------------------------  ----------
Drupal <major-version>             <specific-version>
Acquia Connector                   8.x-1.9
Apigee Developer Portal Kickstart  8.x-1.7
Commerce Kickstart                 7.x-2.62
DKAN                               7.x-1.15.4
govCMS                             7.x-3.6
Open Atrium                        7.x-2.69
OpenPublic                         7.x-1.9
Thunder                            8.x-2.9
Web Experience Toolkit             7.x-4.9

Waiting for completion of a database backup

After you initiate the process of creating a database backup through Acquia CLI, the system takes some time to complete the process. You cannot deploy your code or perform other tasks until the process is completed. To wait until the system creates the backup, use the app:task-wait command:

acli app:task-wait "$(acli api:environments:database-backup-create myapp.dev my_db)"

Did not find what you were looking for?

If this content did not answer your questions, try searching or contacting our support team for further assistance.

Back to Section navigation