Unable to Retrieve Azure Namespace Listings via Script, While Successful via Azure Cli

Anonymous
2024-03-15T12:34:00.11+00:00

Hi everyone,

I'm currently working on a JavaScript script aimed at listing down namespaces in using Azure libraries. However, despite following the correct steps, I'm encountering an issue where the script returns an empty list. Interestingly, when I employ the Azure CLI, I'm able to successfully list the namespaces. I've provided screenshots below for reference.

I suspect there might be a discrepancy in the script implementation or a misconfiguration. Notably, during the application registration process, I've ensured to grant the necessary permissions by assigning the user_impersonation scope.

Could you kindly assist me in identifying any potential errors in the script or any missing configurations that might be causing this issue? I'm eager to resolve this and ensure the script functions as intended.

Your guidance and insights would be helpful. Thanksimage

image (1)

Azure Key Vault
Azure Key Vault
An Azure service that is used to manage and protect cryptographic keys and other secrets used by cloud apps and services.
1,124 questions
Azure Event Hubs
Azure Event Hubs
An Azure real-time data ingestion service.
559 questions
{count} votes

1 answer

Sort by: Most helpful
  1. LeelaRajeshSayana-MSFT 13,471 Reputation points
    2024-03-20T19:42:51.8166667+00:00

    Greetings! Welcome to Microsoft Q&A forum. Thank you for posting this question here.

    The CLI command uses DefaultAzureCredential which is based of az login command to fetch the Event Hub namespaces. Your program on the other end is using ClientSecretCredential. I have tested the same code and could fetch the Event Hub namespaces without any issues.

    Since you are using local variables in your code, I recommend removing the OR conditionality check when assigning the subscriptionId in line 31 of the code. It could be possible that there might be a different Subscription ID being pulled from environment variables. Since we have an logical || conditionality check, it will take precedence over the subscription you are trying to set after the operator. In this case, if process.env["EVENTHUB_SUBSCRIPTION_ID"] has a value, that is the subscription being queried upon.

    To test my code, I have used the Client ID and Tenant ID from my application registration overview page which can be access from Microsoft Entra Admin Center. Please find the below image for reference.

    enter image description here

    I have passed the application Client Secret value to the parameter client secret. Please find the below image for reference.

    enter image description here

    In addition to setting these values, please ensure your application has access to Azure Event Hub resource. You can follow the steps in the section Assign a role to the application to grant access.

    Once you have verified and assigned appropriate values, your code should work as expected and fetch the Event Hub namespaces.

    Hope this helps! Please let us know if you need any additional assistance or need further clarification.


    If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.

    0 comments No comments