New-AzApiManagementSubscription

Creates a subscription.

Syntax

New-AzApiManagementSubscription
   -Context <PsApiManagementContext>
   [-SubscriptionId <String>]
   -Name <String>
   -UserId <String>
   -ProductId <String>
   [-PrimaryKey <String>]
   [-SecondaryKey <String>]
   [-AllowTracing]
   [-State <PsApiManagementSubscriptionState>]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
New-AzApiManagementSubscription
   -Context <PsApiManagementContext>
   [-SubscriptionId <String>]
   -Name <String>
   [-UserId <String>]
   -Scope <String>
   [-PrimaryKey <String>]
   [-SecondaryKey <String>]
   [-AllowTracing]
   [-State <PsApiManagementSubscriptionState>]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]

Description

The New-AzApiManagementSubscription cmdlet creates a subscription.

Examples

Example 1: Subscribe a user to a product

PS C:\>$apimContext = New-AzApiManagementContext -ResourceGroupName "Api-Default-WestUS" -ServiceName "contoso"
PS C:\>New-AzApiManagementSubscription -Context $apimContext -UserId "777" -ProductId "999"

This command subscribes an existing user to a product.

Example 2: Create a subscription for all Api Scope

PS C:\>$apimContext = New-AzApiManagementContext -ResourceGroupName "Api-Default-WestUS" -ServiceName "contoso"
PS C:\>New-AzApiManagementSubscription -Context $context -Scope "/apis" -Name "GlobalApiScope"

Example 3: Create a subscription for Product Scope

PS C:\>$apimContext = New-AzApiManagementContext -ResourceGroupName "Api-Default-WestUS" -ServiceName "contoso"
PS C:\>New-AzApiManagementSubscription -Context $context -Scope "/products/starter" -Name "UnlimitedProductSub"

Parameters

-AllowTracing

Flag which determines whether Tracing can be enabled at the Subscription Level. This is optional parameter and default is $null.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-Context

Specifies a PsApiManagementContext object.

Type:PsApiManagementContext
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-DefaultProfile

The credentials, account, tenant, and subscription used for communication with azure.

Type:Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer
Aliases:AzContext, AzureRmContext, AzureCredential
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Name

Specifies the subscription name.

Type:String
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-PrimaryKey

Specifies the subscription primary key. If this parameter is not specified the key is generated automatically. This parameter must be 1 to 300 characters long.

Type:String
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-ProductId

Specifies the ID of the product to which to subscribe.

Type:String
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-Scope

The Scope of the Subscription, whether it is Api Scope /apis/{apiId} or Product Scope /products/{productId} or Global API Scope /apis or Global scope /. This parameter is required.

Type:String
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-SecondaryKey

Specifies the subscription secondary key. This parameter is generated automatically if it is not specified. This parameter must be 1 to 300 characters long.

Type:String
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-State

Specifies the subscription state. The default value is $Null.

Type:Nullable<T>[Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementSubscriptionState]
Accepted values:Suspended, Active, Expired, Submitted, Rejected, Cancelled
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-SubscriptionId

Specifies the subscription ID. This parameter is generated if not specified.

Type:String
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-UserId

Specifies the subscriber ID.

Type:String
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False

Inputs

PsApiManagementContext

String

Nullable<T>[[Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementSubscriptionState, Microsoft.Azure.PowerShell.Cmdlets.ApiManagement.ServiceManagement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]

Outputs

PsApiManagementSubscription