New-AzApiManagementSubscription doesn't seems to work

Eric Franckx 45 Reputation points
2024-12-19T09:51:27.47+00:00

Hi,

I try to use in my Pwoershell script command :

New-AzApiManagementSubscription

to create a sunscription and add it to a Prodcut, but when I try it with different paramaters/syntax:

CreateResult = New-AzApiManagementSubscription `

-Context $Context `
-Name $Name[0] `
-UserId $UserId `
-ProductId $ProductId

I have always an error:
New-AzApiManagementSubscription:

Error Code: ValidationError

Error Message: One or more fields contain incorrect values:

Request Id: 13c84366-503c-4848-9d99-c373521b1e64

Error Details:

    [Code= ValidationError, Message= Subscription scope should be one of '/apis', '/apis/{apiId}', '/products/{productId}', Target= scope]


And can't find a way to solve it.


Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,239 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,707 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. VenkateshDodda-MSFT 23,141 Reputation points Microsoft Employee
    2024-12-19T10:27:20.71+00:00

    @Eric Franckx Thanks for posting your question in Microsoft Q&A, apologize for any inconvenience caused on this.

    The parameter -Scope is required for New-AzApiManagementSubscription which is called out in the documentation as shown below.

    User's image

    As you are trying to create a new subscription and add the particular user and product to it. I would suggest you try modifying your cmdlet to below.

    $apimContext = New-AzApiManagementContext -ResourceGroupName "{ResourceGroupName}" -ServiceName "{APIM INstanceName}"
    New-AzApiManagementSubscription -Context $apimContext -name "{NameOfSubscription}" -Scope "/products/{ProductName}" -UserId "{UserId}"
    

    or based on your requirement.

    Hope this helps, let me know if you have any further questions.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.