Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft Face API 1.0 Error Resource Not Found

I am working on a face recognition project with Microsoft Azure Cognitive services. Not quite sure why I am not able to correct my own JSON Malformed syntax I thought I nail this 6 months ago. I want to create a group name, so I call upon 'Person Group API' and everytime I follow MS example I get errors in my code however in the API testing Console no problems here is my code example borrow from MS site :

 { "error": { "code": "ResourceNotFound", "message": "The requested resource was not found." } }

and the code which is run in Console mode :

static async void CreateGroup()
        {
            string key1 = "YourKey"; 
             // azure the one should work 
            var client = new HttpClient();
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            // Request headers
           client.DefaultRequestHeaders.Add
           ("Ocp-Apim-Subscription-Key", key1);

        var uri = "https://westus.api.cognitive.microsoft.com/face/v1.0/
        persongroups/{personGroupId}?" + queryString;

        HttpResponseMessage response;

        // Request body
        string groupname = "myfriends";

        string body = "{\"name\":\"" + groupname + ","+ "\"}";
        // Request body
        using (var content = new StringContent
        (body, Encoding.UTF8, "application/json"))
        {

            await client.PostAsync(uri, content)
                .ContinueWith(async responseTask =>
                {
                    var responseBody = await responseTask.Result
                    .Content.ReadAsStringAsync();
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("Response: {0}", responseBody);
                    Console.WriteLine("");

                    Console.WriteLine("Group Created.... ");
                    Console.WriteLine("Hit ENTER to exit...");
                    Console.ReadKey();
                });

            response = await client.PutAsync(uri, content);
            Console.WriteLine("what is this {0}", response.ToString());
            Console.ReadKey();

        }// end of using statement 


    }// end of CreateGroup
    #endregion

I am guess here but I think its my JSON is malformed again and I just don't know what I am doing wrong again this time. According to the site the field name that I require to send over to ms is 'name' : 'userData' is optional.

like image 378
Waheed Rafiq Avatar asked Nov 30 '25 14:11

Waheed Rafiq


1 Answers

Faced the similar issue, after adding "/detect" in the uri the issue fixed. See the below

var uri = "https://westus.api.cognitive.microsoft.com/face/v1.0/detect

Also make sure the subscription key is valid.

like image 88
Devanathan.S Avatar answered Dec 02 '25 04:12

Devanathan.S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!