locked
Howto to rename subscription key parameter RRS feed

  • Question

  • Hi,

    A while ago Vlad posted this:

    • Subscription key parameter renaming. By default we expect subscription key to be provided as a value of ocp-apim-subscription-key request header or subscription-key URL query parameter.  We added the ability to customize the names of these parameters. You can now rename either one or both of them. At the moment, this feature is available via API only.

    But I can't find any mention of this in the docs. Can anyone provide more details?

    Best regards,

    Peter

    • Edited by Peter148 Monday, December 29, 2014 2:20 PM
    Monday, December 29, 2014 2:20 PM

Answers

  • Hi Peter,

    I believe the question has been answered on Yammer. I am re-posting the answer here:

    Somehow we failed to update the docs with this feature – sorry about that. Custom name(s) for the query and/or header parameters containing subscription key can be set on an existing API like this:

    PATCH /apis/{id}?api-version={{api-version}}

    Authorization: {token}
    Content-Type: application/json
    If-Match: “*"

    {
    "subscriptionKeyParameterNames":
    {
    "query": “customQueryParameterName",
    "header": “customHeaderParameterName"
    }
    }

    Note that “subscriptionKeyParameterNames” property is optional and can also be added to the request body when creating an API. When “subscriptionKeyParameterNames” property is present, it must contain at least one of the two propertie

    Tuesday, December 30, 2014 9:37 PM

All replies

  • Hi Peter,

    I believe the question has been answered on Yammer. I am re-posting the answer here:

    Somehow we failed to update the docs with this feature – sorry about that. Custom name(s) for the query and/or header parameters containing subscription key can be set on an existing API like this:

    PATCH /apis/{id}?api-version={{api-version}}

    Authorization: {token}
    Content-Type: application/json
    If-Match: “*"

    {
    "subscriptionKeyParameterNames":
    {
    "query": “customQueryParameterName",
    "header": “customHeaderParameterName"
    }
    }

    Note that “subscriptionKeyParameterNames” property is optional and can also be added to the request body when creating an API. When “subscriptionKeyParameterNames” property is present, it must contain at least one of the two propertie

    Tuesday, December 30, 2014 9:37 PM
  • Here's a PowerShell snippet showing how to do it:

    $apimSharedAccessSignature = '<GET THIS FROM APIM>'
    ### Get all APIs
    Invoke-RestMethod -Uri "https://myApimInstance.management.azure-api.net/apis?api-version=2014-02-14-preview" -Headers @{'Authorization' = $apimSharedAccessSignature}
    
    ### Get an API by Name
    Invoke-RestMethod -Uri 'https://myApimInstance.management.azure-api.net/apis?$filter=name eq ''My Api Name''&api-version=2014-02-14-preview' -Headers @{'Authorization' = $apimSharedAccessSignature}
    
    ### Update the API
    Invoke-WebRequest -Method Patch -Uri 'https://myApimInstance.management.azure-api.net/apis/<API ID GOES HERE>?api-version=2014-02-14-preview' -Headers @{
    'Content-Type' = 'application/json'
    'Authorization' = $apimSharedAccessSignature
    'If-Match'      = '*'
    } -Body @'
    {
      "subscriptionKeyParameterNames":
      {
        "query": “subscription-key",
        "header": “api-key"
      }
    }
    '@


    • Edited by Craig.Martin Thursday, September 15, 2016 4:43 PM
    Friday, August 26, 2016 8:51 PM
  • Follow-up question: is it also possible to rename the header name?  In the generated code samples the header properly shows up, but the value '{subscription key}' still shows up, for example:

    Here is the Curl Sample:

    @ECHO OFF
    
    curl -v -X GET "https://api.msrc.microsoft.com/cvrf/{id}?api-version=2016-08-01"
    -H "api-key: {subscription key}"
    
    --data-ascii "{body}" 
    

    And here is the Curl Template:

    @ECHO OFF
    
    curl -v -X {{method}} "{{scheme}}://{{host}}{{path}}{{query | escape }}"
    {% for header in headers -%}
    -H "{{ header.name }}: {{ header.value }}"
    {% endfor -%}
    {% if body -%} 
    --data-ascii "{{ body | replace:'"','^"' }}" 
    {% endif -%}

    Wondering if it is possible to update header.value so that the code sample templates don't have to be hacked up.

    Confirmed this is not possible today.  You can vote for the feedback here if you're interested:
    https://feedback.azure.com/forums/248703-api-management/suggestions/16255765-rename-subscription-key-header-details-descriptio
    • Edited by Craig.Martin Monday, September 19, 2016 4:18 PM confirmed the functionality is not present today
    Thursday, September 15, 2016 5:09 PM
  • For those getting here looking for how it's done today: Use Set-AzureRmApiManagementApi to do so.

    https://winterdom.com/2018/01/23/api-management-subscription-key-names


    Jean-Paul Smit | Didago IT Consultancy
    Blog | Twitter | LinkedIn
    MCTS BizTalk 2006/2010 + Certified SOA Architect

    Please indicate "Mark as Answer" if this post has answered the question.

    Tuesday, November 12, 2019 11:34 AM