Chaining graphql query to generate or remove Persistent URL

Hi all,

I am trying to enable persistent url using the shell script and is able to do so by doing subsequent queries.

First, I get the http service id by passing both the account id and device name using this query :

{
    "query": "{ 
        login {
            account(id: \"${accountId}\") {
                devices(name: \"${deviceName}\"){
                    items{ id name services(name: \"http\") { id name } enabled state }
                }
            }
        } 
    }"
}

Then subsequently I pass that id in the second query, either to set the persistent public url or removing it.

Set the public url :

{
	"query": "mutation SetPublicURL(\$serviceId: String!, \$isEnabled: Boolean!) { setConnectLink(serviceId: \$serviceId, enabled: \$isEnabled) { url password enabled } }",
	"variables": {
		"serviceId": "${serviceId}",
		"isEnabled": ${isEnabled}
	}
}

Remove the public url :

{
	"query": "mutation RemovePublicURL(\$serviceId: String!) { removeConnectLink(serviceId: \$serviceId) }",
	"variables": {
		"serviceId": "${serviceId}"
	}
}

As for the question, is there a way to combine the queries so if I want to set or remove, I can simply send one query to do so?

Regards,
Guruh.

Mutations need to be sent as separate requests. This is a graphQL usage design and not an API specific setting.

Mutations need to be sent as separate requests. This is a graphQL usage design and not an API specific setting.

In other words, if I want to generate and enable persistent url, I need to use the first query to get the http service Id, then pass it to the mutation on the second query subsequently?

First Query

{
    "query": "{ 
        login {
            account(id: \"${accountId}\") {
                devices(name: \"${deviceName}\"){
                    items{ id name services(name: \"http\") { id name } enabled state }
                }
            }
        } 
    }"
}

Second query (the mutation) :

{
	"query": "mutation SetPublicURL(\$serviceId: String!, \$isEnabled: Boolean!) { setConnectLink(serviceId: \$serviceId, enabled: \$isEnabled) { url password enabled } }",
	"variables": {
		"serviceId": "${serviceId}",
		"isEnabled": ${isEnabled}
	}
}

Or is there are more efficient query to do it?

You can do one query to fetch all of your devices without filtering to get a specific device name and iterate over the results instead of a request for each device. In your iteration, you can then make the mutation call to make a change if one is needed.