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
Keaton KleinKeaton Klein 

Trouble using LIKE in a API query

I have been using the soap API and the following line has been working great.
qr1 = binding.queryAll("select id, external_id__c from contact where external_id__C like '%" + naidno2 + "%'");
I am now trying to do something similar using the REST API and I am getting a 400 error.  If I remove the wild cards then the query runs just fine but in some cases the wild cards are necessary.
 
xhr8.open("GET", "https://na17.salesforce.com/services/data/v34.0/query/?q=select id, name from contact where cheetah_id__c like '%" + ContactCode + "%'");

 
Best Answer chosen by Keaton Klein
Keaton KleinKeaton Klein
I figured this one out.  In my javascript i edited the xmlhttprequest to utlize the encodeURI function.  Using the line below in place of the line from my initial question works perfectly.
 
xhr8.open("GET", encodeURI("https://na17.salesforce.com/services/data/v34.0/query/?q=select+id,+name+from+contact+where+cheetah_id__c+LIKE+'%" + ContactCodeString + "%'"));