Resolved Using AFNetworking to call Parse REST API

Discussion in 'iOS Programming' started by MacMan988, Feb 27, 2014.

  1. MacMan988, Feb 27, 2014
    Last edited: Feb 27, 2014

    MacMan988 macrumors 6502a

    Joined:
    Jul 7, 2012
    #1
    Hi, I have been trying to use the Parse REST API with AFNetworking but I get the status 400 error. Here is my code.

    Code:
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
        [manager.requestSerializer setValue:@"parse-application-id-removed" forHTTPHeaderField:@"X-Parse-Application-Id"];
        [manager.requestSerializer setValue:@"parse-rest-api-key-removed" forHTTPHeaderField:@"X-Parse-REST-API-Key"];
        [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
        NSDictionary *parameters = @{@"deviceType" : @"ios",
                                     @"deviceToken" : @"device-token-removed",
                                     @"channels" : [NSArray arrayWithObjects:@"", nil]};
    
        [manager POST:@"https://api.parse.com/1/push" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSLog(@"JSON: %@", responseObject);
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"Error: %@", error);
        }];
    And I get the following output in the Xcode console:

    Code:
    Error: Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: bad request (400)" UserInfo=0x60000026b600 {AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x610000030120> { URL: https://api.parse.com/1/push } { status code: 400, headers {
        "Access-Control-Allow-Origin" = "*";
        "Access-Control-Request-Method" = "*";
        "Cache-Control" = "no-cache";
        Connection = "keep-alive";
        "Content-Length" = 130;
        "Content-Type" = "application/json; charset=utf-8";
        Date = "Thu, 27 Feb 2014 08:37:41 GMT";
        Server = "nginx/1.4.4";
        "Set-Cookie" = "_parse_session=BAh7C0kiD3Nlc3Npb25faWQGOgZFRiIlNzczNjllNGRkODQyMjNjODk2NGYxYmZmNTMwNjM2OGNJIhBsYW5kaW5nX3VybAY7AEZJIlUvcXVlc3Rpb25zL2hvdy10by1jaGVjay1pZi1hLXVzZXItaGFzLWEtbm9uLWV4cGlyZWQtaW4tYXBwLXB1cmNoYXNlLXN1YnNjcmlwdGlvbgY7AEZJIhBfY3NyZl90b2tlbgY7AEZJIjFqRml0SkloUGx3ZzlkZlNVd2RpTTBYWTFrSmVOWURMemYxem9TRGQybkNJPQY7AEZJIhV1c2VyX2NyZWRlbnRpYWxzBjsARkkiAYBhZTA3MzI2MmFlOGUwYzllYmUzMzQ3ZmE1YmQwMzM5ODJiMmNmNWM0YzdhYzYwMDE0N2UyNTE0ZjU5ZTEwOTJlODdjOThhZmNkYTkzOGU3NmUyNjFiODEzODhmZjNiY2RjZTY4ZWZmNGYxYWZhZDQ0NTYwNGY3MjNkMWRmNjU5MQY7AFRJIhh1c2VyX2NyZWRlbnRpYWxzX2lkBjsARmkCgcVJIhFyZWZlcnJlcl91cmwGOwBGIgH%2FaHR0cHM6Ly93d3cuZ29vZ2xlLmNvbS91cmw%2Fc2E9dCZyY3Q9aiZxPSZlc3JjPXMmc291cmNlPXdlYiZjZD0yJmNhZD1yamEmdmVkPTBDRElRRmpBQiZ1cmw9aHR0cHMlM0ElMkYlMkZwYXJzZS5jb20lMkZxdWVzdGlvbnMlMkZwZmluc3RhbGxhdGlvbiZlaT1EQUFOVS1QdU11aUJpUWZVMzRGWSZ1c2c9QUZRakNORmZ4VG5UUjBBbTZiSkV4VG5QWUZJZXJScGRfdyZzaWcyPW1ZdWthOU42cGUzWW94UDFpR2tkcXcmYnZtPWJ2LjYxNzI1OTQ4LGQuYUdj--bd8bb3ed497b389496f68c1e24b3dce911174df7; domain=.parse.com; path=/; expires=Sat, 29-Mar-2014 08:37:41 GMT; secure; HttpOnly";


    Any ideas?

    EDIT: I have missed the "data" parameter and this worked once the data and alert parameters are included
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Can you tag this thread as Resolved then?
     

Share This Page