We have a REST resource apex class, and its sole purpose is to eliminate the problem of hitting Salesforce page view limits. The way it is currently setup doesn't seem to be eliminating this issue. Basically, it's supposed to act as a web service endpoint. We have a PHP relay that will call this apex class using curl. So far, the only way we've been able to give access to this class is publicly by allowing public access to this apex class in our site. What we've been trying to do to work around this is to try and use session IDs, but I'm running into a brick wall here.
This is the PHP code we are using to access the class:
$sessionIdURL = "https://test.salesforce.com/services/oauth2/token"; $sessionIdPostFields = "grant_type=password&client_id=our_client_id&client_secret=our_secret_key&username=our_username&password=our_password_w_security_token"; $c = curl_init(); curl_setopt($c, CURLOPT_URL, $sessionIdURL); curl_setopt($c, CURLOPT_POSTFIELDS, $sessionIdPostFields); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); $sfResponse = curl_exec($c); curl_close($c); $accessToken = $sfResponse["access_token"]; $cc = curl_init(); curl_setopt($cc, CURLOPT_URL, $url); curl_setopt($cc, CURLOPT_POSTFIELDS, $postFields); curl_setopt($cc, CURLOPT_RETURNTRANSFER, true); curl_setopt($cc, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($postFields), 'Authorization: ' . $accessToken) ); $response = curl_exec($cc); curl_close($cc); print_r($response);
I was able to get a session ID successfully. So then I decided to try and implement it with a call to our REST resource. However, whenever I remove public access to our apex class in the site manager it doesn't work. I've even tried setting up access to the Connected App I made for it on our site, but it still won't work unless the site allows public access to the apex class. What might I be doing wrong?