Can I use "not" filters in Azure Pricing API

Contributor

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.

2 Replies

@Chris Bradshaw 

 

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'

 

Use query parameters to customize responses - Microsoft Graph | Microsoft Docs

@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.