1
votes

I am generating API Key for an App Insight. I am using the URL "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/components/{resourceName}/ApiKeys"

I don't have any clear documentation and I found this from the MS SDK: https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/applicationinsights/Microsoft.Azure.Management.ApplicationInsights/src/Generated/APIKeysOperations.cs

However, when I try to generate by mentioning a "name", an error comes in response:

{
    "code": "The API Key needs to have a Role",
    "message": "The API Key needs to have a Role",
    "innererror": {
        "diagnosticcontext": "e1f66da1-9247-459e-a519-6426fa1449d1",
        "time": "2019-09-20T07:48:20.2634617Z"
    }
}

My POST body is as following:

{
    "name": "asimplekeyname"
}

Please help if someone has used this specific API.

1

1 Answers

1
votes

You need to include the following properties in the body.

{ 
   "name":"test3",
   "linkedReadProperties":[ 
      "/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/microsoft.insights/components/<appinsight-name>/api",
      "/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/microsoft.insights/components/<appinsight-name>/agentconfig"
   ],
   "linkedWriteProperties":[ 
      "/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/microsoft.insights/components/<appinsight-name>/annotations"
   ]
}

The three properties correspond the ones in the portal -> your appinsight -> API Access -> Create API key.

api - Read telemetry
agentconfig - Authenticate SDK control channel
annotations - Write annotations

You need to select at least one of them, inculde in the request body.

enter image description here


For example, you just select the first one as below.

enter image description here

The body should be:

{ 
   "name":"test3",
   "linkedReadProperties":[ 
      "/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/microsoft.insights/components/<appinsight-name>/api" 
   ],
   "linkedWriteProperties":[]
}