11-20-2014 17:17
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-20-2014 17:17
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hello everyone,
I am trying to add a silent alarm. I am usimg AFNetworking library to send my POST request in JSON format.
but I am getting error , (PLEASE help me
) This is the error I get:
2014-11-20 17:04:53.083 FitBit[1213:461035] error messages getting Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 400" UserInfo=0x145ad8b0 {NSLocalizedRecoverySuggestion={"errors":[{"errorType":"validation","fieldName":"enabled","message":"Enabled is required"}, ......
and here is the code:
NSArray *AlarmParameters = @[@"time", @"enabled",@"recurring",@"weekDays",@"label",@"snoozeLength",@"snoozeCount",@"vibe"]; NSArray *AlarmValues = @[@"11:50-08:00",[NSNumber numberWithBool:true],[NSNumber numberWithBool:true], [NSArray arrayWithObjects:@"MONDAY", @"TUESDAY", @"THURSDAY", nil],@"Test",@9,@2,@"DEFAULT"]; NSDictionary *AlaramDetails = [NSDictionary dictionaryWithObjects:AlarmValues forKeys:AlarmParameters]; NSString *str=urlPath; NSString *oAuthValue = [_oAuthFitBit oAuthHeaderForMethod:@"POST" andUrl:str andParams:nil]; NSURL *url = [NSURL URLWithString:str]; AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url]; [httpClient setParameterEncoding:AFJSONParameterEncoding]; [httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]]; [httpClient setDefaultHeader:@"Authorization" value:oAuthValue]; NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path: [url path] parameters:AlaramDetails]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [operation setCompletionBlockWithSuccess: ^(AFHTTPRequestOperation *operation, id responseObject) { NSError *err = nil; NSDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:&err]; NSLog(@"%@ fitbit response=%@",urlPath,responseDict); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"error messages getting %@",error); }]; [operation start];

11-21-2014 08:06
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


11-21-2014 08:06
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hello.
When error says "Enabled is required" that means that at the point when request hits Fitbit API the enabled parameter is not there or it not properly used/formed.
I see in your code you are setting this parameter, so I guess it get lost sowhere in your code, OR you're not sending it as true or false format, but instead as 1 or 0 format. I suggest you trying to debug the code and figure out how the http request you're making looks like right before it actually get sent.
You can also try using Charles tool. You can send all the requests through this tool when configured it properly and it will tell exactly what http requests you're sending.
Senior Software Developer at Fitbit

