function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
pbattissonpbattisson 

Rest query not working in different scenarios (apigee and iOS)

Hey Everyone

 

I was wondering if anybody had any idea as to why the following query is working in apigee and not in my iOS app.

 

iOS query:

 

https://na7.salesforce.com/services/data/v20.0/query/?q=Select Id, Name, Phone, Type, Website, AccountNumber, Site, AnnualRevenue, BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry, ShippingStreet, ShippingCity, ShippingState, ShippingPostalCode, ShippingCountry, Description, NumberOfEmployees, Fax, Industry, Rating, Sic, TickerSymbol, Active__c, CustomerPriority__c, NumberofLocations__c, SLA__c, SLAExpirationDate__c, SLASerialNumber__c, UpsellOpportunity__c From Account order by Name -H "Authorization: OAuth myloongtoekngoeshere"

 apigee (which provides its own token)

 

https://na7.salesforce.com/services/data/v20.0/query?q=Select Id, Name, Phone, Type, Website, AccountNumber, Site, AnnualRevenue, BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry, ShippingStreet, ShippingCity, ShippingState, ShippingPostalCode, ShippingCountry, Description, NumberOfEmployees, Fax, Industry, Rating, Sic, TickerSymbol, Active__c, CustomerPriority__c, NumberofLocations__c, SLA__c, SLAExpirationDate__c, SLASerialNumber__c, UpsellOpportunity__c From Account order by Name

 Thanks for any help guys and girls.

 

Paul

 

 

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

Looking through ZKSwitchboard, i don't think clientId is a sid, you want the sessionId property instead.

All Answers

SuperfellSuperfell

the IOS one has .../query/?q=

the apigee one has .../query?q=

 

note the extra slash after query in the iOS version.

 

pbattissonpbattisson

Nice but no cigar.

NSString *queryString = @"Select Id, Name, Phone, Type, Website, AccountNumber, Site, AnnualRevenue, BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry, ShippingStreet, ShippingCity, ShippingState, ShippingPostalCode, ShippingCountry, Description, NumberOfEmployees, Fax, Industry, Rating, Sic, TickerSymbol, Active__c, CustomerPriority__c, NumberofLocations__c, SLA__c, SLAExpirationDate__c, SLASerialNumber__c, UpsellOpportunity__c From Account order by Name";
    
    NSString *queryURL = [NSString stringWithFormat:@"https://na7.salesforce.com/services/data/v20.0/query?q=%@",queryString];
    NSURL *url = [NSURL URLWithString:queryURL];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request addValue:[NSString stringWithFormat:@"OAuth %@", switcher.clientId] forHTTPHeaderField:@"Authorization"];
    NSURLResponse *resp = nil;
    NSError *err = nil;
    
    NSData *jsonData = [NSURLConnection sendSynchronousRequest:request returningResponse:&resp error:&err];

Where switcher is my ZKServerSwitchBoard instance and the error I receive is:

 

Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x6b4c400 {NSUnderlyingError=0x6b1c6a0 "bad URL", NSLocalizedDescription=bad URL}

 

Thanks

 

Paul

 

SuperfellSuperfell

You need to URL encode the queryString part.

pbattissonpbattisson

Already tried both ASCII and UTF8 which both give

 

Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)" UserInfo=0x4e225a0 {NSErrorFailingURLKey=https://na7.salesforce.com/services/data/v20.0/query?q=Select%20Id,%20Name,%20Phone,%20Type,%20Website,%20AccountNumber,%20Site,%20AnnualRevenue,%20BillingStreet,%20BillingCity,%20BillingState,%20BillingPostalCode,%20BillingCountry,%20ShippingStreet,%20ShippingCity,%20ShippingState,%20ShippingPostalCode,%20ShippingCountry,%20Description,%20NumberOfEmployees,%20Fax,%20Industry,%20Rating,%20Sic,%20TickerSymbol,%20Active__c,%20CustomerPriority__c,%20NumberofLocations__c,%20SLA__c,%20SLAExpirationDate__c,%20SLASerialNumber__c,%20UpsellOpportunity__c%20From%20Account%20order%20by%20Name, NSErrorFailingURLStringKey=https://na7.salesforce.com/services/data/v20.0/query?q=Select%20Id,%20Name,%20Phone,%20Type,%20Website,%20AccountNumber,%20Site,%20AnnualRevenue,%20BillingStreet,%20BillingCity,%20BillingState,%20BillingPostalCode,%20BillingCountry,%20ShippingStreet,%20ShippingCity,%20ShippingState,%20ShippingPostalCode,%20ShippingCountry,%20Description,%20NumberOfEmployees,%20Fax,%20Industry,%20Rating,%20Sic,%20TickerSymbol,%20Active__c,%20CustomerPriority__c,%20NumberofLocations__c,%20SLA__c,%20SLAExpirationDate__c,%20SLASerialNumber__c,%20UpsellOpportunity__c%20From%20Account%20order%20by%20Name, NSUnderlyingError=0x4e20560 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1012.)"}

 

:smileysad:

SuperfellSuperfell

Would really need to see the raw HTTP request/response i think at this point.

SuperfellSuperfell

-1012 seems to be  kCFURLErrorUserCancelledAuthentication you should probably double check that you're sending the correct Authorization header.

pbattissonpbattisson
SuperfellSuperfell

Looking through ZKSwitchboard, i don't think clientId is a sid, you want the sessionId property instead.

This was selected as the best answer
pbattissonpbattisson

Using the session Id has helped sort it out along with setting some more header fields (namely content-type).

 

Thanks for all the help Simon. Much appreciated. 

 

Paul