Iot Hub Resource - Get Keys For Key Name

Get a shared access policy by name from an IoT hub. For more information, see: https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-security.

HTTP
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/IotHubs/{resourceName}/IotHubKeys/{keyName}/listkeys?api-version=2023-06-30

URI Parameters

Name In Required Type Description
keyName
path True

string

The name of the shared access policy.

resourceGroupName
path True

string

The name of the resource group that contains the IoT hub.

resourceName
path True

string

The name of the IoT hub.

subscriptionId
path True

string

The subscription identifier.

api-version
query True

string

The version of the API.

Responses

Name Type Description
200 OK

SharedAccessSignatureAuthorizationRule

This is a synchronous operation. The body contains a JSON-serialized shared access policy, including keys, that you can use to access one or more IoT hub endpoints.

Other Status Codes

ErrorDetails

DefaultErrorResponse

Security

azure_auth

Azure Active Directory OAuth2 Flow

Type: oauth2
Flow: implicit
Authorization URL: https://login.microsoftonline.com/common/oauth2/authorize

Scopes

Name Description
user_impersonation impersonate your user account

Examples

IotHubResource_GetKeysForKeyName

Sample request

HTTP
POST https://management.azure.com/subscriptions/91d12660-3dec-467a-be2a-213b5544ddc0/resourceGroups/myResourceGroup/providers/Microsoft.Devices/IotHubs/testHub/IotHubKeys/iothubowner/listkeys?api-version=2023-06-30

Sample response

JSON
{
  "keyName": "iothubowner",
  "primaryKey": "<primaryKey>",
  "secondaryKey": "<secondaryKey>",
  "rights": "RegistryWrite, ServiceConnect, DeviceConnect"
}

Definitions

Name Description
AccessRights

The permissions assigned to the shared access policy.

ErrorDetails

Error details.

SharedAccessSignatureAuthorizationRule

The properties of an IoT hub shared access policy.

AccessRights

The permissions assigned to the shared access policy.

Value Description
DeviceConnect
RegistryRead
RegistryRead, DeviceConnect
RegistryRead, RegistryWrite
RegistryRead, RegistryWrite, DeviceConnect
RegistryRead, RegistryWrite, ServiceConnect
RegistryRead, RegistryWrite, ServiceConnect, DeviceConnect
RegistryRead, ServiceConnect
RegistryRead, ServiceConnect, DeviceConnect
RegistryWrite
RegistryWrite, DeviceConnect
RegistryWrite, ServiceConnect
RegistryWrite, ServiceConnect, DeviceConnect
ServiceConnect
ServiceConnect, DeviceConnect

ErrorDetails

Error details.

Name Type Description
code

string

The error code.

details

string

The error details.

httpStatusCode

string

The HTTP status code.

message

string

The error message.

SharedAccessSignatureAuthorizationRule

The properties of an IoT hub shared access policy.

Name Type Description
keyName

string

The name of the shared access policy.

primaryKey

string

The primary key.

rights

AccessRights

The permissions assigned to the shared access policy.

secondaryKey

string

The secondary key.