GetToken function

Works with Azure PowerShell Az module

Before running the ‘GetToken’ you have to Sign in to Azure obviously using ‘Connect-AzAccount’ cmdlet.

Thanks for reading!


Function App - List, Create or Update, Delete Api Keys

In previous post I was complaining how I received a BadRequest error when trying to create or update host secret in Function App using ARM Api. But how I’m actually doing this?

One way is to use Postman and call ARM Api. I’m calling ARM Api using PowerShell Invoke-WebRequest cmdlet in my scripts and then using this in CI/CD to create/update/get/delete api keys on Function Apps in my Azure Tenant.

Actually I’m and following instructions in the docs:

And here’s is a part of my code. Also I’m describing [here](/2020/07/24/badrequest-error-function-app-create-or-update-host-secret/ why I’m building JSON body (variable $body) in this way for Create/Update request.

I’m using ‘GetToken’ function to acquire current session authentication token. Code for the function is here.

Thanks for reading!


BadRequest when Create Or Update Host Secret (aka Api Key) for Function App

When creating or updating host secret (aka ApiKey) for Function App using ARM Api, have you ever received a error message “Properties object is not present in the request body.”? Well I did.

Here’s full error response body I was receiving:

{
    "Code": "BadRequest",
    "Message": "Properties object is not present in the request body.",
    "Target": null,
    "Details": [
        {
            "Message": "Properties object is not present in the request body."
        },
        {
            "Code": "BadRequest"
        },
        {
            "ErrorEntity": {
                "ExtendedCode": "51006",
                "MessageTemplate": "{0} object is not present in the request body.",
                "Parameters": [
                    "Properties"
                ],
                "Code": "BadRequest",
                "Message": "Properties object is not present in the request body."
            }
        }
    ],
    "Innererror": null
}

Message states, I’m sending incorrect body. So what I’m sending in the body? Just a simple JSON:

{
  "Name": "ApiKey",
  "Value": "<my-secret-api-key>"
}

Let’s see in the docs: https://docs.microsoft.com/en-us/rest/api/appservice/webapps/createorupdatehostsecret#request-body.

According to thee docs, I should send just two parameters in the body “name” and “value”:

Name Type Description
name string Key name
value string Key value

Looks easy. But ARM Api keeps telling me something is missing. Not so easy, though. How should correct JSON look like then?

Correct JSON should look like so:

{
  "Properties": {
    "Name": "ApiKey",
    "Value": "<my-secret-api-key>"
  }
}

Thats it! Simple, isn’t it?

Bonus: how to create Function App Host Secret using PowerShell.

Thanks for reading!


Remove tenants from a Switch Directory list

Too many Azure Tenants under Switch Directory in Azure Portal?

Microsoft explained this in detail in the docs: https://docs.microsoft.com/en-us/azure/active-directory/b2b/leave-the-organization

screen #1

 

Leave an organization

Here’s a brief instruction copied from the docs.

  1. Go to your Access Panel Profile page by doing one of the following steps:
    • In the Azure portal, click your name in the upper right and select View account.
    • Open your Access Panel, click your name in the upper right, and next to Organizations, select the settings icon (gear).

screen #2

  1. Under Organizations, find the organization that you want to leave, and select Leave organization.

screen #3

  1. When asked to confirm, select Leave.

Thanks for reading!