Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Gregg Mojica
11,506 PointscURL AFNetworking
I'm really stumped on this. I need to convert this cURL command into objective-c. I am using the AFNetworking library to go about this but it returns bad request (error 400) each time. I'd appreciate help.
cURL command:
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer XXXXXXXXXXXXX" -d '{"quantity_delta": -5,"adjustment_type": "SALE"}' https://connect.squareup.com/v1/me/inventory/00CC0141-C50C-4A7A-9FAA-368EC79DA652
AFNetworking Objective-C Code:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager.requestSerializer setValue:@"Bearer XXXXXXXXXXXXX" forHTTPHeaderField:@"Authorization"];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSDictionary *parameters = @{@"quantity_delta": [NSNumber numberWithInt:-1], @"adjustment_type": @"SALE"};
NSLog(@"Parameters are %@", parameters);
[manager POST:@"https://connect.squareup.com/v1/me/items/00CC0141-C50C-4A7A-9FAA-368EC79DA652" parameters:@{@"quantity_delta": [NSNumber numberWithInt:-1], @"adjustment_type": @"SALE"} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];