0
votes

Trying to consume Azure media service rest api. (following the tutorial : https://docs.microsoft.com/en-us/azure/media-services/media-services-rest-get-started)

Everything works fine until the point I try to create a Job. Sending the same request as in example (except asset id and token) and getting response : Parsing request content failed due to: Make sure to only use property names that are defined by the type

Request:

    POST https://wamsdubclus001rest-hs.cloudapp.net/api/Jobs HTTP/1.1
    Connection: Keep-Alive
    Content-Type: application/json
    Accept: application/json; odata=verbose
    Accept-Charset: UTF-8
    Authorization: Bearer token -> here i send real token
    DataServiceVersion: 1.0;NetFx
    MaxDataServiceVersion: 3.0;NetFx
    x-ms-version: 2.11
    Content-Length: 458
    Host: wamsdubclus001rest-hs.cloudapp.net

        {
        "Name":"TestJob",
        "InputMediaAssets":[
        {
        "__metadata":{
        "uri":"https://wamsdubclus001rest-hs.cloudapp.net/api/Assets('nb%3Acid%3AUUID%3A5168b52a-68ed-4df1-bac8-0648ce734ff6')"
        }
        }
        ],
        "Tasks":[
        {
        "Configuration":"Adaptive Streaming",
        "MediaProcessorId":"nb:mpid:UUID:ff4df607-d419-42f0-bc17-a481b1331e56",
        "TaskBody":"<?xml version=\"1.0\" encoding=\"utf-8\"?><taskBody><inputAsset>JobInputAsset(0)</inputAsset> <outputAsset>JobOutputAsset(0)</outputAsset></taskBody>"
        }
        ]
        }

Response:

{
"error":{
"code":"",
"message":{
"lang":"en-US",
"value":"Parsing request content failed due to: Make sure to only use property names that are defined by the type"
}
}
}

It seems to be related with __metadata property. when I follow instruction from here : Creating Job from REST API returns a request property name error, the error changes:

"error":{
"code":"",
"message":{
"lang":"en-US",
"value":"Invalid input asset reference in TaskBody - "
}
}
}

Cant figure out whats wrong, thanks

2

2 Answers

1
votes

Let me check on this, but it could be a couple issues that I have run into in the past.

First. Set both the Accept and Content-Type headers to: "application/json; odata=verbose"

Next, double check that you are actually using the long underscore character on the metadata property. I've had issues where that was sending the wrong underscore character and it didn't match the property name.

Let me know if either of those helps.

0
votes

It seems the issue was about "Content-Type". As I am using .net Core it was not easy to set the Conent-type as "application/json; odata=verbose".

1) Tried with RestSharp - dosnt support it, it cuts "odata=verbose" part out

2) Tried with Systsem.Net.Http.HttpClient -> Possible but difficult. To add it as "Accept" :

         MediaTypeWithQualityHeaderValue mtqhv;

         MediaTypeWithQualityHeaderValue.TryParse("application/json;odata=verbose", out mtqhv);

         client.DefaultRequestHeaders.Accept.Add(mtqhv);//ACCEPT header

To add it as "Content-Type" :

request.Content = new StringContent(content,
System.Text.Encoding.UTF8); //CONTENT-TYPE header -> default type will be text/html

request.Content.Headers.Clear();  // need to clear it - it will fail otherwise
request.Content.Headers.TryAddWithoutValidation("Content-Type","application/json;odata=verbose");