App Service not saving environment variable SENDGRID_API_KEY – value returns null

Youc 20 Reputation points
2025-05-09T04:10:50.41+00:00

Subject: App setting variable SENDGRID_API_KEY not recognized in Azure App Service – value returns null

Description: Hi Microsoft Support,

We have deployed a .NET-based email API (isupplier-emailapi) using Azure App Service under the resource group youUIGrp. We have set the SENDGRID_API_KEY both through the Azure Portal (under Environment Variables) and CLI:

az webapp config appsettings set --name isupplier-emailapi --resource-group youUIGrp --settings "SENDGRID_API_KEY=SG.xxxxxx"

However, our deployed application cannot read this environment variable at runtime. It returns null, resulting in an error: "Missing SENDGRID_API_KEY"

We’ve also tried:

Setting via CLI multiple formats (--settings key=value, JSON, etc.)

Restarting the app

Verifying the variable appears in the App Settings list

The value is still not picked up. Could you please investigate and fix this for us? We’re happy to provide access or any additional details you need.

Thank you,

Kate Trieu

******@youc.com.au

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,931 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Harshitha Veeramalla 1,301 Reputation points Microsoft External Staff Moderator
    2025-05-19T12:30:29.92+00:00

    Hi @Youc,

    Use the below CLI command to verify that your environment variable is correctly configured.

    az webapp config appsettings list --name AppName --resource-group RGName
    
    • The above command will list all application settings configured for your App Service. Check for SENDGRID_API_KEY in the output.User's image
    • Use the below line of code to retrieve the variable in your .NET application from the Environment Variable.
    var sendGK= Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
    

    If you want to retrieve the value using IConfiguration, then you can use the below code

    var sendGK= Configuration["SENDGRID_API_KEY"];
    

    Another option to check if your setting is available is in KUDU AppSettings and environment variables.

    URL - https://AppName.scm.azurewebsites.net

    User's image

    • If you are able to see the setting and still facing the issue. Try to set the value in KeyVault and retrieve it using KeyVault Reference in App Settings.
    "SENDGRID_API_KEY": "@Microsoft.KeyVault(SecretUri=https://KVName.vault.azure.net/secrets/SecretName/)"
    

    Hope this helps


    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions, please reply back.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.