Search code examples
ioscurlterminalnsurlsquare

Curl command, -H option, and 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?


Solution

  • I finally figured it out. Posting this here for others to use for referance.

    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"];