Azure / azure-cli

Azure Command-Line Interface
MIT License
4.01k stars 2.98k forks source link

az eventgrid event-subscription create not working in Powershell #8465

Closed andrefsoliveira closed 5 years ago

andrefsoliveira commented 5 years ago

Hi all,

i'm trying to create a new eventgrid topic webhook subscription to trigger a logicapp endpoint using Azure CLI (v2.0.57) via Windows Powershell, but it's not working as expected.

I'm do the same thing on the azure portal and also on CloudShell web interface and it's works perfectly.

The command is the follow:

az eventgrid event-subscription create --name "sopas" --source-resource-id "/subscriptions/id/resourceGroups/name/providers/Microsoft.EventGrid/topics/name" --endpoint-type "webhook" --endpoint "https://prod-16.westeurope.logic.azure.com:443/workflows/xxx/triggers/manual/paths/invoke?api-version=2016-10-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=xxx" --debug --verbose

The error on windows powershell is the follow:

az : ERROR: The attempt to validate the provided endpoint https://prod-16.westeurope.logic.azure.com/workflows/371848cd5a2242cda3f88bfcce80962a/triggers/manual/paths/invoke failed. For more details, visit 
https://aka.ms/esvalidation.
At line:3 char:1
+ az eventgrid event-subscription create --name "sopas" --source-resour ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (ERROR: The atte...s/esvalidation.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

'sp' is not recognized as an internal or external command,
operable program or batch file.
'sv' is not recognized as an internal or external command,
operable program or batch file.
'sig' is not recognized as an internal or external command,
operable program or batch file.

Am I doing something wrong ?

Can someone help ?

Thanks!

tjprescott commented 5 years ago

You need to properly escape the & character in your string for Powershell, which is typically the backtick ( ` )

andrefsoliveira commented 5 years ago

Hi,

Thanks for your help, but applying your suggestion it's continuing not working...

`$endpoint = 'https://prod-84.westeurope.logic.azure.com:443/workflows/0387649c1ce9414fbff9d962887d06c6/triggers/manual/paths/invoke?api-version=2016-10-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=xZyMAeBkrc0e8avVEA2X96_Ythdz3EeyZcP6v0pxSZCo'

$endpoint = $endpoint.Replace('&', '`&')

az eventgrid event-subscription create --name "SalesForce" --endpoint-type "webhook" --source-resource-id "/subscriptions/9b6d94c3-9572-42cb-aa1d-82td8ff8879f8/resourceGroups/dev.ls.serverless/providers/Microsoft.EventGrid/topics/dev-mpiupdates" --endpoint "$endpoint" --debug --verbose`

The result is the same:

` az : ERROR: The attempt to validate the provided endpoint https://prod-84.westeurope.logic.azure.com/workflows/0387649c1ce9414fbff9d962887d06c6/triggers/manual/paths/invoke failed. For more details, visit https://aka.ms/esvalidation. At line:8 char:1

'sp' is not recognized as an internal or external command, operable program or batch file. 'sv' is not recognized as an internal or external command, operable program or batch file. 'sig' is not recognized as an internal or external command, operable program or batch file.

The powershell version is: 5.1.17134.407

tjprescott commented 5 years ago

From the error, it is clear that Powershell is splitting your line by the & character before it reaches the CLI. Unfortunately, we are unable to provide support for shell-specific issues like this. You will need to figure out how to disable this Powershell feature or escape your strings to avoid such behavior.

Alternatively, consider running your scripts in Linux bash or Windows CMD.exe, which have far fewer issues like this and are easier to overcome when they do occur.