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

iOS

Curl Command -H Square API

I'm developing an iOS app using the Square Connect API. I need to connect with the following command:

    curl -H "Authorization: Bearer ACCESS_KEY"
    https://connect.squareup.com/v1/me/payments

What's the iOS equivalent of this? Amit Bijlani Stone Preston

2 Answers

Finally figured it out!

NSString *pswd = @"XXXXXXXXX";

NSURL *url = [NSURL URLWithString:@"https://connect.squareup.com/v1/me/payments"];
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:url];

NSString *authValue = [NSString stringWithFormat:@"Bearer %@", pswd];
[request setValue:authValue forHTTPHeaderField:@"Authorization"];

I don't think iOS/ObjC has an implementation of curl in the most technical sense, but I'm pretty confident that the NSURLConnection and NSMutableURLRequest classes should get you where you want to go.

I haven't taken very much iOS here, so I'm not sure if that will solve your problem. If you run into issues, post back here, and I'll try to help you further. :)

I've used both classes attempting to connect to the API and each time it returns validation failed or something to that avail. Can you post a code example? Thanks!!

Will this Stack Overflow post help?

hmmm...still didn't work. Can you provide a code example? I used the code from that SO post but it didn't work. Maybe I'm doing something totally stupid.

I wish I could help more, but I don't know much about it either. :( I'm sorry about that. Other than doing the obvious Google search, I'm not sure how to solve your problem.

OK, thanks for your help. I'll keep searching...

Wait a second...I think I found something.

Thanks for your help, I finally figured it out!