Manually submitting values to the Azure Metering API

Requirements

In this script, we're using curl and jq. curl certainly is on your system, for jq, you might need to fetch it:

#!/bin/bash

curl --silent \
     --url https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 \
     --location \
     --output jq && \
chmod +x jq && \
sudo mv jq /usr/local/bin && \
sudo chown root.root /usr/local/bin/jq

Credentials

I assume you have 2 service principal credentials in the publisher/ISV AAD tenant:

  1. We need a management credential which is authorized to manage customer deployments, using with the ARM API.

    • I created an AAD group, called managed-app-admins, and made the service principal a member of that group.

    • In Partner Center -> Offer -> Plan -> Technical Configuration -> Authorizations, I granted the AAD group Owner of managed apps.

    • As a result, the isv_management_cliend_id below can interact with managed apps.

    • image-20230127212906222

    • So 8cdea44d-38fe-4e3c-bf2a-6b96809d1d27 above is the object ID of the group, and the service principal with app id 8eff18b7-aeeb-4a88-b19c-bf60813a587c is member of that group.

  2. We need a metering credential, which is authorized to submit usage to the metering API.

    • We do not use an identity in the managed app, i.e. we do not SSH/RDP into a VM in the managed resource group to do our work there. Having a VM just for that is too complicated (and expensive).

    • This isv_metering_client_id (app id) service principal is configured under Partner Center -> Offer -> Technical Configuration:

    • image-20230127212946875

The script

So the initial metering request looks like this:

You can see the "status":"Accepted", and a Microsoft-issued "usageEventId".

If you try to emit the same usage a 2nd time, you'll get a different response:

Marketplace here tells us that the submission is Conflict / Duplicate of a previously submitted event.

  • "Azure Marketplace Metered Billing- Picking the correct ID when submitting usage events": To understand the difference between the resourceUri and resourceId in Azure Marketplace, please read my blog article , either in my private or the official blog.

  • https://docs.microsoft.com/en-us/azure/marketplae/marketplace-metering-service-authentication

  • https://docs.microsoft.com/en-us/azure/marketplace/partner-center-portal/pc-saas-registration#get-the-token-with-an-http-post

Last updated