5

I'm having some trouble accessing API endpoints using a valid token that I just got from the OAuth process.

I'm passing data as I think I should and am trying to access any endpoint at this point (Actually, I need to create a case, but even getting /limits to work would be nice)

$url = $domain . '/services/data/v34.0/sobjects/limits';

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
    array("Authorization: OAuth $token",
        "Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, '');

return curl_exec($curl);

My developer instance is at na16.salesforce.com and if I understand it correctly, I need to be using that domain for my API calls.

I feel like maybe I'm just missing an extra header item that I need to send or something, but I'm having no luck finding what that needs to be.

Perhaps I need to create some kind of session first? Either way, I'm having no luck figuring out what that is after a whole lot of searching.

The code above is the entirely of my call to the API. What is missing here?

  • I am having this exact issue for many days now. Did you find any resolution? Thanks – dgig Jun 26 '15 at 14:31
  • Yes, unfortunately I don't really know why it started working. The code is exactly the same as above and it works fine now. Sorry I can't be much more help. – Scheda Jun 26 '15 at 15:04
  • Haha, I've seen that answer more than once ;) - thanks for the response. – dgig Jun 26 '15 at 15:06
  • make sure you're using the access token, and not the refresh token. – superfell Oct 8 '15 at 22:52
0

Re this line:

curl_setopt($curl, CURLOPT_HTTPHEADER,
    array("Authorization: OAuth $token", "Content-type: application/json"));

I think the Auth header should be Bearer + Token

curl_setopt($curl, CURLOPT_HTTPHEADER,
        array("Authorization: Bearer $token", "Content-type: application/json"));

See a more detailed example here

  • Unfortunately I've tried that as well. The docs seem to say you can use either and they both give the same response. – Scheda Jun 23 '15 at 1:18
  • Have you tried using a session id - you can use that as the token and it works as well - that way, you can hopefully work out if it's the code, or the oauth process – BritishBoyinDC Jun 23 '15 at 3:38
  • No, I haven't. Thanks for the suggestion. I'll try that today. – Scheda Jun 23 '15 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.