Error with calling Speaker Identification API. When i try to return a profile Id i get a Error: Error Domain=NSURLErrorDomain Code=-1012 "(null)"

Eluxsana Subenderan 1 Reputation point
2021-03-29T14:48:39.807+00:00

The following error message is what i get when i try to return a profile Id for enrolment. I have already tried to see if it is an authentication error by using the API console, everything seems to be returning fine over there. Currently I am using the objective c code from the link below as a bridge header for my swift app:

https://westus.dev.cognitive.microsoft.com/docs/services/563309b6778daf02acc0a508/operations/5645c3271984551c84ec6797

This is the error message i receive when i try to return the Profile Id for Enrolment:

"https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles?entities=true 2021-03-23 14:56:16.205386-0400 Reka[50677:760200] Error: Error Domain=NSURLErrorDomain Code=-1012 "(null)" UserInfo={NSErrorFailingURLStringKey=https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles?entities=true, NSUnderlyingError=0x600002755290 {Error Domain=kCFErrorDomainCFNetwork Code=-1012 "(null)" UserInfo={_kCFURLErrorAuthFailedResponseKey=<NSHTTPURLResponse: 0x600002a746a0> { URL: https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles?entities=true } { Status Code: 401, Headers { "Content-Length" = ( 225 ); "Content-Type" = ( "application/json" ); Date = ( "Tue, 23 Mar 2021 18:56:15 GMT" ); "Strict-Transport-Security" = ( "max-age=31536000; includeSubDomains; preload" ); "Www-Authenticate" = ( "AzureApiManagementKey realm=\"https://westus.api.cognitive.microsoft.com/spid/v1.0",name="Ocp-Apim-Subscription-Key",type="header""; ); "apim-request-id" = ( "5ab215e6-1efe-4f92-9468-3dc14a79567e" ); "x-content-type-options" = ( nosniff ); } }}}, NSErrorFailingURLKey=https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles?entities=true}";

Implementation of my code

@implementation PersonIdObject

(int) personIdMethod {
NSLog(@"SomeMethod Ran");

    @autoreleasepool {
     NSString* path = @"https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles";
     NSArray* array = @[
                          // Request parameters
                          @"entities=true",
                       ];

     NSString* string = [array componentsJoinedByString:@"&"];
     path = [path stringByAppendingFormat:@"?%@", string];
     NSLog(@"%@", path);
     NSMutableURLRequest* _request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path]];
     [_request setHTTPMethod:@"POST"];
     // Request headers
     [_request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
     [_request setValue:@"{subscription key}" forHTTPHeaderField:@"sub_key"];
     // Request body
     [_request setHTTPBody:[@"{body}" dataUsingEncoding:NSUTF8StringEncoding]];

     NSURLResponse *response = nil;
     NSError *error = nil;
     NSData* _connectionData = [NSURLConnection sendSynchronousRequest:_request returningResponse:&response error:&error];
     if (nil != error)
     {
         NSLog(@"Error: %@", error);
     }
     else
     {
         NSError* error = nil;
         NSMutableDictionary* json = nil;
         NSString* dataString = [[NSString alloc] initWithData:_connectionData encoding:NSUTF8StringEncoding];
         NSLog(@"%@", dataString);

         if (nil != _connectionData)
         {
             json = [NSJSONSerialization JSONObjectWithData:_connectionData options:NSJSONReadingMutableContainers error:&error];
         }

         if (error || !json)
         {
             NSLog(@"Could not parse loaded json with error:%@", error);
         }

         NSLog(@"%@", json);
         _connectionData = nil;
     }

     //[pool drain];
     return 0;
     }

}

Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
2,061 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
3,602 questions
{count} votes

1 answer

Sort by: Most helpful
  1. YutongTie-MSFT 53,966 Reputation points Moderator
    2021-04-05T08:05:48.083+00:00

    Hello,

    I have seen you posted the same here https://learn.microsoft.com/en-us/answers/questions/339678/index.html

    Could you please check below comment?

    @Eluxsana Subenderan I think you are using the sample code of ObJC from the API console. Based on this code the path or URI should contain the Profile ID as below which is missing in your code snippet above:

    NSString* path = @"https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles/{identificationProfileId}/enroll";

    Thanks!

    Regards,
    Yutong

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.