locked
Create Azure Stack Subscription with REST API RRS feed

  • Question

  • I'm trying to create a new subscription based on our default provider subscription using the REST API described here:

    https://docs.microsoft.com/en-us/rest/api/azurestack/subscriptions/createorupdate#subscription

    First, it says "Update or Create", but it uses only PUT (update) and no POST (create). But to create according to the example I need to know the subscription ID of the subscription I want to create? Otherwise it complains that I didn't specify subscriptionId.

    This is my code for creating the subscription named "test".

            args = {
                "state" => "Enabled",
                "delegatedProviderSubscriptionId" => <default_provider_subscr_id>,
                "offerId" => "/subscriptions/<default_provider_subscr_id>/resourceGroups/lab-offer-rg/providers/Microsoft.Subscriptions.Admin/offers/lab-offer",
                "displayName" => "Test Subscription",
                "owner" => "#{owner}@#{tenant_name}",
                "subscriptionId" => "", 
                "routingResourceManagerType" => "Default",
            }.to_json
    
            res = request("PUT", "/subscriptions/#{@default_provider_subscr_id}/providers/Microsoft.Subscriptions.Admin/subscriptions/test?api-version=2015-11-01", args)

    This request fails with the following error:

    {
      "error": {
        "code": "InternalServerError",
        "message": "Encountered internal server error. Diagnostic information: timestamp '20180525T113316Z', subscription id 'xxxx-xxxxxxxxxxxxxxxxxx', tracking id '424a9521-d564-4098-84c3-956b52de3c20', request correlation id 'ce036b58-f174-4c0f-a696-01d6cdfa9335'."
      }
    }

    I i skip "subscriptionId" it yields the following error:

    {
      "error": {
        "code": "InvalidRequestContent",
        "message": "The request content was invalid and could not be deserialized: 'Required property 'subscriptionId' not found in JSON. Path '', line 1, position 317.'."
      }
    

    How can I use the API to create a subscription on my Azure Stack?

    Friday, May 25, 2018 11:43 AM

Answers

  • Hi there,

    If I understand your scenario correctly, you're trying to create a subscription for a tenant user, from the admin side. If that's right, then what you're doing seems to be mostly accurate.

    You do have to provide the subscription id of the subscription you'd like to create. this needs to be a GUID. The API will create a subscription with the GUID you've provided. If there are conflicts, the API will error out.

    Please give that a whirl and let us know if it fails!

    Thanks

    --

    Shri 

    Thursday, May 31, 2018 6:21 PM

All replies

  • Hello,

    I'm trying to rerpo this in my environment and will let you know what I find.

    We apologize for any inconvenience and appreciate your time and interest in Azure Stack.

    If you continue experience any issues with ASDK release, feel free to contact us.

           

     Thanks, 


    Gary Gallanes

    Wednesday, May 30, 2018 11:23 PM
  • Hi there,

    If I understand your scenario correctly, you're trying to create a subscription for a tenant user, from the admin side. If that's right, then what you're doing seems to be mostly accurate.

    You do have to provide the subscription id of the subscription you'd like to create. this needs to be a GUID. The API will create a subscription with the GUID you've provided. If there are conflicts, the API will error out.

    Please give that a whirl and let us know if it fails!

    Thanks

    --

    Shri 

    Thursday, May 31, 2018 6:21 PM
  • Hi,

    I'm not quite sure what you mean. So I should just generate a random global unique identifier (global in what way, whole Azure or just our Azure Stack instance?). 

    But when I specify the subscription ID and a name such as this:

            args = {
                "state" => "Enabled",
                "delegatedProviderSubscriptionId" => "#{@default_provider_subscr_id}",
                "offerId" => "/subscriptions/xxxxxxxxxx/resourceGroups/lab-rg/providers/Microsoft.Subscriptions.Admin/offers/lab-offer",
                "displayName" => "Test Subscription",
                "owner" => "#{owner}@#{tenant_name}",
                "subscriptionId" => "aa389ad-4430-18cc-8fac-eeeced8e843d",
                "routingResourceManagerType" => "Default",
            }.to_json
            res = request("PUT", "/subscriptions/#{@default_provider_subscr_id}/providers/Microsoft.Subscriptions.Admin/subscriptions/mysub1?api-version=2015-11-01", args)
    


    Where sub subscriptionId is just a random one. And the name of my subscription is specified to mysub1.

    It fails with the following error:

    {
        "error" => {
               "code" => "MismatchingResourceId",
            "message" => "The specified resource id 'aa389ad-4430-18cc-8fac-eeeced8e843d' does not match the resource id in the request URL 'mysub1'."
        }
    }

    Perhaps I've misunderstood your solution?

    Friday, June 1, 2018 2:00 PM