Skip to content
Back to skills

Azure Cost Management Api

ASecurity

In PowerShell, inline JSON for Cost Management API causes \"Unsupported Media Type\" errors:

  • 4 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 3, 2026
ai-agentsshellazureapi

Works with

  • api

Security analysis

A100/100

Scanned September 3, 2026

npx -y skills add fabioc-aloha/Alex_Skill_Mall --skill azure-cost-management-api --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Azure Cost Management Api?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Azure Cost Management Api
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/fabioc-aloha-azure-cost-management-api/badge)](https://www.skillsdirectory.com/skills/fabioc-aloha-azure-cost-management-api)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: azure-cost-management-api
description: "In PowerShell, inline JSON for Cost Management API causes \"Unsupported Media Type\" errors:"
lastReviewed: 2026-04-30
---

# Azure Cost Management API

## The Problem

In PowerShell, inline JSON for Cost Management API causes "Unsupported Media Type" errors:

```powershell
# This fails silently or with 415 error
az rest --method POST --uri $uri --body '{"type":"Usage","timeframe":"MonthToDate"}'
```

The shell mangles the JSON.

## The Solution

Write JSON to a file, then reference with `@`:

```powershell
# 1. Create body file
$body = @{
    type = "Usage"
    timeframe = "MonthToDate"
    dataset = @{
        granularity = "Daily"
        aggregation = @{
            totalCost = @{
                name = "Cost"
                function = "Sum"
            }
        }
    }
} | ConvertTo-Json -Depth 10

$bodyFile = "$env:TEMP\cost-query-body.json"
$body | Out-File -FilePath $bodyFile -Encoding utf8

# 2. Call with file reference
$uri = "/subscriptions/$subscriptionId/providers/Microsoft.CostManagement/query?api-version=2023-03-01"
az rest --method POST --uri $uri --body "@$bodyFile"
```

## Common Queries

### Monthly Cost by Resource Group

```json
{
  "type": "Usage",
  "timeframe": "MonthToDate",
  "dataset": {
    "granularity": "None",
    "aggregation": {
      "totalCost": { "name": "Cost", "function": "Sum" }
    },
    "grouping": [
      { "type": "Dimension", "name": "ResourceGroup" }
    ]
  }
}
```

### Daily Cost Trend

```json
{
  "type": "Usage",
  "timeframe": "MonthToDate",
  "dataset": {
    "granularity": "Daily",
    "aggregation": {
      "totalCost": { "name": "Cost", "function": "Sum" }
    }
  }
}
```

## Verification

```powershell
# Should return JSON with "rows" array
$result = az rest --method POST --uri $uri --body "@$bodyFile" | ConvertFrom-Json
$result.properties.rows | Format-Table
```

## When to Apply

- Any Azure Cost Management API call from PowerShell
- Complex JSON bodies in az rest commands
- Budget alerts and cost analysis scripts

## Tags

`azure` `cost-management` `api` `powershell`

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.