Face Api Azure - Problem post request

I’m trying to connect to Face Api (Microsoft Azure), but I’m getting problems to send post request.

This is my code:

const uriBase = 'https://westcentralus.api.cognitive.microsoft.com/face/v1.0';
const imageUrl = 'https://i.ytimg.com/vi/XuJwETp1axs/maxresdefault.jpg';

let body = new FormData();
    body.append('url', imageUrl);

    const params = new HttpParams()
      .set('returnFaceId', 'true')
      .set('returnFaceLandmarks', 'false')
      .set('returnFaceAttributes', 'age,gender,headPose,smile,facialHair,glasses,' +
        'emotion,hair,makeup,occlusion,accessories,blur,exposure,noise' );

this.http.post(uriBase, {'url': imageUrl},
      {headers: {
          'Content-Type': 'application/json',
          'Ocp-Apim-Subscription-Key' : subscriptionKey}, params: params})
      .subscribe(
      res => {
        console.log(res);
      },
      (err: HttpErrorResponse) => {
        console.log(err.error);
        console.log(err.name);
        console.log(err.message);
        console.log(err.status);
      }
    );

But I’m getting this error from console:

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

Can anyone help me, please ?

What URI is it requesting? What exactly is returning this error?

I solved my problem with this code

this.subscriptionKey = subscriptionKey;
    const uriBase = "https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect";
    this.sourceImageUrl=sourceImageUrl;
    //Promises allow us to elegantly handle some API call.

    //Set the headers with the subscription key
    const myheader = new HttpHeaders()
      .set('Content-Type', 'application/json')
      .set('Ocp-Apim-Subscription-Key',subscriptionKey);

    // Request parameters.
    var params = {
      "returnFaceId": "true",
      "returnFaceLandmarks": "false",
      "returnFaceAttributes": "age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise",
    };
    //Prepare the body with a json object containing the image URL to be analyzed
    let body = JSON.stringify({ url: sourceImageUrl});

    const httpOptions = {
      headers: myheader,
      params: params,
    };


    return this.http
        .post(uriBase, body, httpOptions);
  }
1 Like