New Billing API Powershell Support?

I am trying to use the new Ratecard API using Powershell and am running into some major issues trying to get it up. I have found success in using the Usage API in Powershell using the method described in the following link, but was unable to find success using similar methods for the RateCard API:

http://blogs.technet.com/b/keithmayer/archive/2015/06/28/export-azure-subscription-usage-with-new-billing-api-and-powershell.aspx

From the documentation provided in the link below, it seems like it wouldn't take many changes to get RateCard to work: https://msdn.microsoft.com/en-us/library/azure/mt219004.aspx

The exact error I get is as follows and seems to point directly at the syntax of the query not being correct (not authentication issues, etc). I can post my code if needed...: Invoke-RestMethod : { "Message": "Invalid query expression provided. Please provide a valid query expression for the filter." } At C:\Users\eshen\Desktop\BillRate.ps1:46 char:18 + ... usageData = Invoke-RestMethod -Uri $Uri -Method Get -Headers $request ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand [Time frame] N/A [Resource] N/A

July 21st, 2015 7:07pm

Hello Sirry,

Thanks for posting the query here, Error suggests Invoke-RestMethod expression is incorrect

I will suggest these links to Invoke-RestMethod Correct expression.

https://technet.microsoft.com/en-us/library/hh849893.aspx

https://technet.microsoft.com/en-us/library/hh849971.aspx

Hope this will helps!

Best Regards
Prasandhi Kumar
________________________________________________________________________________________________________________
If a post answers your question, please click Mark As Answer on that post and Vote as Helpful.

Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2015 9:02am

(EDIT: It works now.. seems like the offer code I provided doesn't work even though it is listed as a valid code...  I swapped it out and it works now)

Thank you for your reply.

I revisited my code again and today it came back with a different error:

Invoke-RestMethod : { "Message": "Invalid query specified. Please specify valid values for OfferDurableId, Currency, Locale and RegionInfo." }
At C:\Users\eshen\Desktop\BillRate.ps1:46 char:18
+ ... usageData = Invoke-RestMethod -Uri $Uri -Method Get -Headers $request ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Since I am simply trying to get it to work, the URI I use at the moment in powershell is as follows, with values hardcoded in:

$uri = "https://management.azure.com/subscriptions/$subscriptionId/providers/Microsoft.Commerce/RateCard?api-version=2015-06-01-preview&`$filter=OfferDurableId eq MS-AZR-0023P' and Currency eq USD and Locale eq en-US and RegionInfo eq US"

If I an interpreting the message correctly, using Invoke-RestMethod correctly does not seem to be the issue, and it has more to do with finding cvalid input for the 4 fields. 


  • Edited by Sirry 8 hours 1 minutes ago
  • Marked as answer by Sirry 8 hours 1 minutes ago
July 22nd, 2015 6:57pm

(EDIT: It works now.. seems like the offer code I provided doesn't work even though it is listed as a valid code...  I swapped it out and it works now)

Thank you for your reply.

I revisited my code again and today it came back with a different error:

Invoke-RestMethod : { "Message": "Invalid query specified. Please specify valid values for OfferDurableId, Currency, Locale and RegionInfo." }
At C:\Users\eshen\Desktop\BillRate.ps1:46 char:18
+ ... usageData = Invoke-RestMethod -Uri $Uri -Method Get -Headers $request ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Since I am simply trying to get it to work, the URI I use at the moment in powershell is as follows, with values hardcoded in:

$uri = "https://management.azure.com/subscriptions/$subscriptionId/providers/Microsoft.Commerce/RateCard?api-version=2015-06-01-preview&`$filter=OfferDurableId eq MS-AZR-0023P' and Currency eq USD and Locale eq en-US and RegionInfo eq US"

If I an interpreting the message correctly, using Invoke-RestMethod correctly does not seem to be the issue, and it has more to do with finding cvalid input for the 4 fields. 


  • Edited by Sirry Wednesday, July 22, 2015 11:19 PM
  • Marked as answer by Sirry Wednesday, July 22, 2015 11:19 PM
Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2015 10:56pm

(EDIT: It works now.. seems like the offer code I provided doesn't work even though it is listed as a valid code...  I swapped it out and it works now)

Thank you for your reply.

I revisited my code again and today it came back with a different error:

Invoke-RestMethod : { "Message": "Invalid query specified. Please specify valid values for OfferDurableId, Currency, Locale and RegionInfo." }
At C:\Users\eshen\Desktop\BillRate.ps1:46 char:18
+ ... usageData = Invoke-RestMethod -Uri $Uri -Method Get -Headers $request ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Since I am simply trying to get it to work, the URI I use at the moment in powershell is as follows, with values hardcoded in:

$uri = "https://management.azure.com/subscriptions/$subscriptionId/providers/Microsoft.Commerce/RateCard?api-version=2015-06-01-preview&`$filter=OfferDurableId eq MS-AZR-0023P' and Currency eq USD and Locale eq en-US and RegionInfo eq US"

If I an interpreting the message correctly, using Invoke-RestMethod correctly does not seem to be the issue, and it has more to do with finding cvalid input for the 4 fields. 


  • Edited by Sirry Wednesday, July 22, 2015 11:19 PM
  • Marked as answer by Sirry Wednesday, July 22, 2015 11:19 PM
July 22nd, 2015 10:56pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics