# Fetching view data in Azure using CQ API payload configuration issues

**URL:** <https://community.cloudquery.io/t/fetching-view-data-in-azure-using-cq-api-payload-configuration-issues/717>\
**Category:** CloudQuery Plugins\
**Created:** [September 21, 2023, 11:16am UTC](https://community.cloudquery.io/t/fetching-view-data-in-azure-using-cq-api-payload-configuration-issues/717 "2023-09-21T11:16:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![growing-kid](https://avatars.discourse-cdn.com/v4/letter/g/f04885/32.png) [@growing-kid](https://community.cloudquery.io/u/growing-kid)\
**Post date:** [September 21, 2023, 11:16am UTC](https://community.cloudquery.io/t/fetching-view-data-in-azure-using-cq-api-payload-configuration-issues/717/1 "2023-09-21T11:16:52Z")

</div>

Hello folks,

I’m trying to fetch view data in Azure using CloudQuery. I see in the logs that the following API call is being made:

```auto
https://management.azure.com/subscriptions/{subscriptionID}/providers/Microsoft.CostManagement/query

```

The expected columns fetched from the view are very different from the resulting ones. It looks like if the payload of the API is specified in the right way, it returns all the columns as seen in the Azure UI.

Is there a way I can specifically give the payload for the API?

---

<div class="post-metadata">

**Author:** ![kemal](https://sea1.discourse-cdn.com/flex001/user_avatar/community.cloudquery.io/kemal/32/42_2.png) [@kemal](https://community.cloudquery.io/u/kemal)\
**Post date:** [September 21, 2023, 12:07pm UTC](https://community.cloudquery.io/t/fetching-view-data-in-azure-using-cq-api-payload-configuration-issues/717/2 "2023-09-21T12:07:30Z")

</div>

Hi, is this question regarding the `azure_costmanagement_views` or `azure_costmanagement_view_queries`?

Fetching view queries, we need to convert the date range related parameters (`timeframe` and `daterange`) between types, to be able to query data for a saved view. There’s no current way to add additional payload to the query API, but if you have anything in mind, maybe this might be a general feature to be included in the future?

Or did you just want to set arbitrary parameters in the query call?

---

<div class="post-metadata">

**Author:** ![growing-kid](https://avatars.discourse-cdn.com/v4/letter/g/f04885/32.png) [@growing-kid](https://community.cloudquery.io/u/growing-kid)\
**Post date:** [September 21, 2023, 3:14pm UTC](https://community.cloudquery.io/t/fetching-view-data-in-azure-using-cq-api-payload-configuration-issues/717/3 "2023-09-21T15:14:31Z")

</div>

I used both the tables as source in CloudQuery and followed this document to fetch the data: [Azure Cost Optimization with CloudQuery](https://www.cloudquery.io/blog/azure-cost-optimization-with-cloudquery).

Is there a way to convert the date range related parameters (`timeframe` and `daterange`) between types?

It would be great if we could add the payload. As of now, setting arbitrary parameters would also do. How can I do it?

---

<div class="post-metadata">

**Author:** ![kemal](https://sea1.discourse-cdn.com/flex001/user_avatar/community.cloudquery.io/kemal/32/42_2.png) [@kemal](https://community.cloudquery.io/u/kemal)\
**Post date:** [September 21, 2023, 4:33pm UTC](https://community.cloudquery.io/t/fetching-view-data-in-azure-using-cq-api-payload-configuration-issues/717/4 "2023-09-21T16:33:26Z")

</div>

The date range related parameters are converted automatically as the plugin generates the HTTP request to the query endpoint.

What do you mean by payload? The `query` endpoint takes [armcostmanagement.QueryDefinition](https://learn.microsoft.com/en-us/rest/api/cost-management/query/usage?tabs=HTTP#querydefinition) as payload. Which part of the payload do you want to modify?

I looked at the resource code a little bit more. What the plugin does is it transfers the `ReportConfigDefinition` (which is the `query.*` fields under [View](https://learn.microsoft.com/en-us/rest/api/cost-management/views/list?tabs=HTTP#view)) into `QueryDefinition`, and then converts the time range fields (because the time range fields aren’t 100% compatible).

So if you manage to create the View you wish to see in terms of report type etc. in the Azure UI, it should translate automatically to the query results.

---

<div class="post-metadata">

**Author:** ![growing-kid](https://avatars.discourse-cdn.com/v4/letter/g/f04885/32.png) [@growing-kid](https://community.cloudquery.io/u/growing-kid)\
**Post date:** [September 25, 2023, 8:44am UTC](https://community.cloudquery.io/t/fetching-view-data-in-azure-using-cq-api-payload-configuration-issues/717/5 "2023-09-25T08:44:46Z")

</div>

Created a view with the columns required and desired granularity and group by filter.  
Still, I’m able to get only a few columns, whereas the API call to the view gives me a full set of columns that the view has.

**API:**  
`https://management.azure.com/subscriptions/<subscription_id>/providers/Microsoft.CostManagement/query?api-version=2023-03-01`

**Expected Payload** that contains the metadata for the above view that gets passed to the above API:

```json
{"type":"ActualCost","dataSet":{"granularity":"Daily","aggregation":{"totalCost":{"name":"Cost","function":"Sum"},"totalCostUSD":{"name":"CostUSD","function":"Sum"}},"sorting":[{"direction":"ascending","name":"UsageDate"}],"grouping":[{"type":"Dimension","name":"ResourceId"},{"type":"Dimension","name":"ResourceType"},{"type":"Dimension","name":"ResourceLocation"},{"type":"Dimension","name":"ChargeType"},{"type":"Dimension","name":"ResourceGroupName"},{"type":"Dimension","name":"PublisherType"},{"type":"Dimension","name":"ServiceName"},{"type":"Dimension","name":"ServiceTier"},{"type":"Dimension","name":"Meter"}]},"timeframe":"Custom","timePeriod":{"from":"2023-09-15T00:00:00+00:00","to":"2023-09-21T23:59:59+00:00"}} 

```

---

<div class="post-metadata">

**Author:** ![kemal](https://sea1.discourse-cdn.com/flex001/user_avatar/community.cloudquery.io/kemal/32/42_2.png) [@kemal](https://community.cloudquery.io/u/kemal)\
**Post date:** [September 25, 2023, 10:26am UTC](https://community.cloudquery.io/t/fetching-view-data-in-azure-using-cq-api-payload-configuration-issues/717/6 "2023-09-25T10:26:21Z")

</div>

I’m opening an issue for this. Can you tell me which version of the Azure plugin you’ve been using? Thanks.  
The issue I opened is [here](https://github.com/cloudquery/cloudquery/issues/14026)

---

<div class="post-metadata">

**Author:** ![growing-kid](https://avatars.discourse-cdn.com/v4/letter/g/f04885/32.png) [@growing-kid](https://community.cloudquery.io/u/growing-kid)\
**Post date:** [September 25, 2023, 12:15pm UTC](https://community.cloudquery.io/t/fetching-view-data-in-azure-using-cq-api-payload-configuration-issues/717/7 "2023-09-25T12:15:15Z")

</div>

Azure: v9.3.4  
Thank you so much!  
@kemal Is there a way I can track the progress or know till when this might get fixed?

---

<div class="post-metadata">

**Author:** ![kemal](https://sea1.discourse-cdn.com/flex001/user_avatar/community.cloudquery.io/kemal/32/42_2.png) [@kemal](https://community.cloudquery.io/u/kemal)\
**Post date:** [September 27, 2023, 8:49am UTC](https://community.cloudquery.io/t/fetching-view-data-in-azure-using-cq-api-payload-configuration-issues/717/8 "2023-09-27T08:49:09Z")

</div>

You can track the linked issue to see if there’s any progress on it.
