简体   繁体   中英

Azure ratecard api filter by currency example

I want to get the price of a resource according to its usage, for this, I am trying azure ratecard API . I am using python SDKs provided by Azure and here is the link for azure ratecard APIs https://docs.microsoft.com/en-us/python/api/azure-mgmt-commerce/azure.mgmt.commerce.operations.ratecardoperations?view=azure-python

problem is, we need to pass filter as an argument but I do not know how to pass values in the filter. I know we can use offer id, currency, locale, region for the filter, but how to use them in ratecard api?

Here is what I am trying

from azure.mgmt.commerce import UsageManagementClient

ratecardclient = UsageManagementClient(credentials, subscription_id)
ratecard = ratecardclient.rate_card.get(filter=???)

What I have tried in filter

ratecard = ratecardclient.rate_card.get("OfferDurableId eq 'MS-AZR-0003P' and Currency eq 'INR' and Locale eq 'en-US' and RegionInfo eq 'US'")

ratecard = ratecardclient.rate_card.get(filter="OfferDurableId eq 'MS-AZR-0003P' and Currency eq 'INR' and Locale eq 'en-US' and RegionInfo eq 'US'")

The error that I am getting from the above filters

Traceback (most recent call last):
  File "C:/Users/gsc/PycharmProjects/GsGit_Azure_cot/Azure/ADALAuth.py", line 375, in <module>
    ratecard = ratecardclient.rate_card.get("OfferDurableId eq 'MS-AZR-0003P' and Currency eq 'INR' and Locale eq 'en-US' and RegionInfo eq 'US'")
  File "C:\Users\gsc-30310\PycharmProjects\env_python3.6.8_v1\lib\site-packages\azure\mgmt\commerce\operations\rate_card_operations.py", line 94, in get
    raise models.ErrorResponseException(self._deserialize, response)
azure.mgmt.commerce.models.error_response.ErrorResponseException: Operation returned an invalid status code 'Bad Request'

I have not tried it but looking at the documentation and the source code , I believe you would need to specify OData filter string. Please try something like as filter string:

OfferDurableId eq '{OfferDurableId}' and Currency eq '{Currency}' and Locale eq '{Locale}' and RegionInfo eq '{RegionInfo}'

So your code would be:

from azure.mgmt.commerce import UsageManagementClient

ratecardclient = UsageManagementClient(credentials, subscription_id)
ratecard = ratecardclient.rate_card.get(filter="OfferDurableId eq 'MS-AZR-0003p' and Currency eq 'INR' and Locale eq 'en-US' and RegionInfo eq 'US'")  

From the unitests:

    # OfferDurableID: https://azure.microsoft.com/en-us/support/legal/offer-details/
    rate = self.commerce_client.rate_card.get(
        "OfferDurableId eq 'MS-AZR-0062P' and Currency eq 'USD' and Locale eq 'en-US' and RegionInfo eq 'US'"
    )

https://github.com/Azure/azure-sdk-for-python/blob/master/azure-mgmt-commerce/tests/test_mgmt_commerce.py

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM