i am trying to fetch data in JSON format for the search word 'cancer'.
But i can't figure out how to call the websvice, i tried a few things but they are not working, can anybody help me in this.
Below is the API i should be calling https://api.justgiving.com/docs/resources/v1/Search/FundraiserSearch
Clicking the following URL will get desired data in the browser. https://api.justgiving.com/2be58f97/v1/fundraising/search?q=cancer
apiKey = 2be58f97
Here is the code i am using:
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; NSURL *requestURL = [NSURL URLWithString:@"https://api.justgiving.com/2be58f97/v1/fundraising/search"]; [request setURL:requestURL]; [request setHTTPMethod:@"GET"];
NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Disposition: form-data; name=\"q\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"%@",searchText] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSLog(@"ERROR = %@",error.localizedDescription);
if(error.localizedDescription == NULL)
{
NSString *returnString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"response >>>>>>>>> %@",returnString);
}
else
{
NSString *returnString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"response >>>>>>>>> %@",returnString);
}
}];