Forum Discussion

ChrisBradshaw's avatar
ChrisBradshaw
Iron Contributor
Jan 21, 2021

Can I use "not" filters in Azure Pricing API

I'm using the Azure Pricing API on a project and trying to apply a negative filter. According to the documentation I think I should be able to do a filter like

$filter=not endswith(skuName,'Spot')

to remove Spot Instances from a VM list, but this returns the error

{"Error":{"Code":"BadRequest","Message":"Invalid OData parameters supplied"}}

For example, the following URL (without the "not") works 
https://prices.azure.com/api/retail/prices?$filter=endswith(skuName,%27Spot%27) 

but with the "not" it fails
https://prices.azure.com/api/retail/prices?$filter=not%20endswith(skuName,%27Spot%27)

 

I've tried a number of different combinations of syntax, but this matches the documentation I could find. I've also tried negative filtering on other criteria (for example, list me all the VM offerings that are not from UK South) but they fail as well.

 

Any suggestions on how to do this gratefully received. My workaround is to process the list locally, but obviously that's pulling a lot more data than I need, and adding extra processing at my end.

6 Replies

  • Jan Bakker's avatar
    Jan Bakker
    Iron Contributor

    ChrisBradshaw 

     

    I don't think you can combine not and endswith.

     

    Try ne instead. 

     

    Something like this ?filter=SkuName ne 'Spot' or ?filter=Location ne 'UK-South'

     

    https://docs.microsoft.com/en-us/graph/query-parameters#filter-parameter

    • ChrisBradshaw's avatar
      ChrisBradshaw
      Iron Contributor

      Jan Bakker Unfortunately, the VM Instance size isn't called "Spot", it's called something like "D2s Spot"- so the ne test doesn't pick that up as it's doing an exact match.

      • vincentss's avatar
        vincentss
        Copper Contributor

        ChrisBradshaw 

         

        I am taking the storage data from the pricing api , but i need to exclude the "Azure Netapp files" from my query , please help.

         

        Thanks in advance. 

        Regards Vincent S

Resources