Create site using CLI but want to be able to get the site ID back immediately from the response?

I'm sure I know the answer here but...

I'm trying to script the following actions:

  1. Create new site (will include user's name)
  2. Create new outbound route on that specific site
  3. Change site for user's WebRTC phone to use the new one

For #2 I need the site ID. I'm hoping there's some way to just get the ID returned from the response of #1 to feed into the command at #2. But it looks like potentially I need to add a new query to something like /api/v2/telephony/providers/edges/sites using the site plain-text name and extract the ID from there.

Is there an "easy" way to achieve all this?

Hi Vaun,

When you create the new site the CLI should return the response object containing the ID of the new site. You can pipe the response object to something like jq to extract the site ID.

Regards,
Declan

Hi

If using powershell you can use format like example below.
I have used this style elsewhere, piped an input to GC command and the response is captured with pipe to Set-Variable.

In my example, the variable $json has the Did json body required to create entry. The response from that (not surprisingly in example), is stored in the $response variable (you do not put the $ on the Set-Variable command though)

 $json | gc.exe telephony providers edges didpools create -p $ProfileName | Set-Variable -Name response

A variation is below to get a particular user json, strip down to just id and name, and store that in $response.
If doing this version the gc command has to be first in pipe list and surrounded by parentheses

$aVar = "c00d27e0-84ed-4d24-b475-78421f85383c"
$response = (gc.exe users get $aVar --profile sg) | ConvertFrom-Json | Select-Object -Property id,name | ConvertTo-Json

Simon

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.