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
akochakoch 

URL Encode Cross Object Query for REST API

I am trying to integrate Opportunity details including the associated products into a 3rd parts system via the REST API.  Currently we're capturing other information through a GET request and encoding the query in the API.  This has proven difficult to do for the Opportunity details, and I believe this is because a cross object query is required.  For example, the SOQL to do this looks something like:
SELECT Id, Name, ( SELECT PricebookEntry.Product2Id FROM OpportunityLineItems ) FROM Opportunity
Is there a way to encode this into a format that fits with
https://INSTANCE.my.salesforce.com/services/data/v45.0/query/?q=SELECT....

Thanks in advance!
 
Best Answer chosen by akoch
Shivi Srivastava 30Shivi Srivastava 30
Hi akoch,
Below URL works for me, did you try this?
/services/data/v29.0/queryAll/?q=SELECT+Name,(SELECT+PricebookEntry.Product2Id+FROM+OpportunityLineItems)+from+Opportunity+limit+5

All Answers

Shivi Srivastava 30Shivi Srivastava 30
Hi akoch,
Below URL works for me, did you try this?
/services/data/v29.0/queryAll/?q=SELECT+Name,(SELECT+PricebookEntry.Product2Id+FROM+OpportunityLineItems)+from+Opportunity+limit+5
This was selected as the best answer
akochakoch
Awesome!  Yes that worked.  I think my mistake was adding a plus sign before the parentheses.
Thank you Shlvl!