REST API counterpart for 'snap connections <snap-name>'

I am looking for REST API counterpart of snap connections <snap-name>

I know there is GET /v2/connections/ But this is very exhaustive. I am looking for an option that gives me o/p for specific snap. Also issue with /v2/connections is that it does not include the interfaces that are not connected for a snap, whereas snap connections <snap-name> gives this info.

Doing a GET /v2/connections?snap=<snap-name>&select=all should give you all that.

1 Like

The /v2/connections end point takes query parameters to restrict its output. For instance, I can limit the results to only show connections involving a particular snap (either on the plug or slot side):

$ curl --unix-socket /run/snapd.socket  'http://x/v2/connections?snap=hugo' | jq .
{
  "type": "sync",
  "status-code": 200,
  "status": "OK",
  "result": {
    "established": [
      {
        "slot": {
          "snap": "core",
          "slot": "home"
        },
        "plug": {
          "snap": "hugo",
          "plug": "home"
        },
        "interface": "home"
      },
      {
        "slot": {
          "snap": "core",
          "slot": "network-bind"
        },
        "plug": {
          "snap": "hugo",
          "plug": "network-bind"
        },
        "interface": "network-bind"
      }
    ],
    "plugs": [
      {
        "snap": "hugo",
        "plug": "home",
        "interface": "home",
        "apps": [
          "hugo"
        ],
        "connections": [
          {
            "snap": "core",
            "slot": "home"
          }
        ]
      },
      {
        "snap": "hugo",
        "plug": "network-bind",
        "interface": "network-bind",
        "apps": [
          "hugo"
        ],
        "connections": [
          {
            "snap": "core",
            "slot": "network-bind"
          }
        ]
      }
    ],
    "slots": [
      {
        "snap": "core",
        "slot": "home",
        "interface": "home",
        "connections": [
          {
            "snap": "hugo",
            "plug": "home"
          }
        ]
      },
      {
        "snap": "core",
        "slot": "network-bind",
        "interface": "network-bind",
        "connections": [
          {
            "snap": "hugo",
            "plug": "network-bind"
          }
        ]
      }
    ]
  },
  "warning-timestamp": "2020-07-15T21:58:27.667480353Z",
  "warning-count": 1
}

The other supported query parameters are:

  • interface: only show connections involving the named interface
  • select: if set to all, include unconnected plugs/slots in the results.
1 Like

I’m sorry, but the Snapd REST API did not include a proper description of the parameters you can pass to the /v2/connections endpoint. I’ve update the documentation now. Feel free to ask if you have any further questions regarding the API.

Thanks @mborzecki @jamesh
Above information helped me to narrow down the result to the snap I am interested in. But is there a way to combine snap=<name> and select=all parameter as with only snap=<name> the o/p does not include interfaces that are not connected.

The requirement that I have is to find if any interface(s) of the snap is(are) not connected.

Pass the parameters and their values in the request URL, eg: /v2/connections?snap=<snap>&select=all.

Had tried this already seeing your initial reply. I still don’t see un-connected interfaces being included in o/p.

For e.g.:

    Interface      Plug                             Slot            Notes
    content        platform-qa:lib                    -                -
    i2c            platform-qa:i2c                    -                -
    network        platform-qa:network             :network            -

In above case, I only see the network interface in o/p of
'curl -sS --unix-socket /run/snapd.socket http://localhost/v2/connections?snap=platform-qa&select=all'

Are you quoting the URL? If not, you might be putting the curl invocation into the background and setting select=all as an environment variable in your shell.

1 Like

Can you paste the output?

My bad. I was not quoting the URL. Worked post correction.