0
votes

Azure Media Services v3 - c# Odata Query fails with 400 Bad Request for properties.created gt date works for REST api.

Working REST Version

GET https://management.azure.com/subscriptions/1234/resourceGroups/ResGroup/providers/Microsoft.Media/mediaServices/testurstream/assets?api-version=2018-07-01&$filter=properties/created gt 2018-06-01 and properties/created lt 2019-07-01

Broken .NET Version (Fiddler trace)

GET https://management.azure.com/subscriptions/1234/resourceGroups/ResGroup/providers/Microsoft.Media/mediaServices/testurstream/assets?$filter=properties/created%20gt%20'2018-11-11T10%3A48%3A37Z'&api-version=2018-07-01

Docs state greater than is supported for created.

properties.created Supports: Eq, Gt, Lt Supports: Ascending and Descending

Code Sample:

var query = new ODataQuery<Asset>(item => item.Created > lastFetchTime);
var assets = _client.Assets.List(ResourceGroup, AccountName, query);

Exception:

Microsoft.Azure.Management.Media.Models.ApiErrorException
HResult=0x80131500
Message=Operation returned an invalid status code 'BadRequest'
Source=Microsoft.Azure.Management.Media
StackTrace:
  at Microsoft.Azure.Management.Media.AssetsOperations.<ListWithHttpMessagesAsync>d__5.MoveNext()
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  at Microsoft.Azure.Management.Media.AssetsOperationsExtensions.<ListAsync>d__1.MoveNext()
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  at Microsoft.Azure.Management.Media.AssetsOperationsExtensions.List(IAssetsOperations operations, String resourceGroupName, String accountName, ODataQuery`1 odataQuery)

Fiddler Result

#   Result  Protocol    Host    URL Body    Caching Content-Type    Process Comments    Custom  
13  400 HTTPS   management.azure.com    /subscriptions/1234/resourceGroups/ResGroup/providers/Microsoft.Media/mediaServices/testurstream/assets?$filter=properties/created%20gt%20'2018-11-11T00%3A00%3A00Z'&api-version=2018-07-01 217 private application/json; charset=utf-8 amstestv3:7148          
2

2 Answers

0
votes

Looks like .NET is quoting the string for the 8601 datetime, which is breaking the call.

I checked in Postman also and this works fine: $filter=properties/created gt 2018-01-11T01:00:00Z

But this quoted string throws a similar error message: $filter=properties/created gt '2018-01-11T01:00:00Z'

Let me check on this with our .NET SDK team.

0
votes

Working version - format string directly.

if (lastFetchTime != null)
{
    var dateTime = lastFetchTime.GetValueOrDefault().ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
    var odataQuery = $"properties/created lt {dateTime}";
    query = new ODataQuery<Asset>(odataQuery);
}

var data = _client.Assets.List(ResourceGroup, AccountName, query);