0

I am trying to call this web service via a wordpress plugin:

https://na25.salesforce.com/services/apexrest/echosign_dev1/template/load/a1t31500002HmjV?email=VAR

Adobe said I need to have a valid session ID so I did this:

Created a connected app Used Oath2 to get an access token (which if I echo it I can see the auth is working because I get back my token) Now using a submit to CURL that address as so

$sf_sig = 'https://na25.salesforce.com/services/apexrest/echosign_dev1/template/load/a1t31500002HmjV?email='. $email;

    //open connection
    $ch = curl_init();
    $ch2 = curl_init();

    //ch2 
    curl_setopt($ch2, CURLOPT_URL, $sf_sig);
    curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch2, CURLOPT_HTTPHEADER, array("Authorization: OAuth $access_token"));
    curl_setopt($ch2, CURLOPT_POST, true);
    curl_setopt($ch2, CURLOPT_POSTFIELDS, '');


    //create the multiple cURL handle
    $mh = curl_multi_init();

    //add the two handles
    curl_multi_add_handle($mh,$ch);
    curl_multi_add_handle($mh,$ch2);

    $active = null;
    //execute the handles
    do {
        $mrc = curl_multi_exec($mh, $active);
    } while ($mrc == CURLM_CALL_MULTI_PERFORM);

    while ($active && $mrc == CURLM_OK) {
        if (curl_multi_select($mh) != -1) {
            do {
                $mrc = curl_multi_exec($mh, $active);
            } while ($mrc == CURLM_CALL_MULTI_PERFORM);
        }
    }

    //close the handles
    curl_multi_remove_handle($mh, $ch);
    curl_multi_remove_handle($mh, $ch2);
    curl_multi_close($mh);

The first CURL (which I didnt post) works fine but this one doesnt work. I have tried changing the Auth to Bearer as well and nothing. I am not sure where to find the debug logs in salesforce since I am new to this, but the code seems like it should work?

  • Can you expound on your question a bit? What do you mean by "doesn't work"? At minimum, it'd be helpful to know what the http status code was that was returned (e.g. 301, 400, 500, etc), what the body of the response had, if any (you can redact sensitive information, if necessary), and if you got any logs on the salesforce.com side. Off the top of my head, I'd think either you had a malformed request (urlencode the email), or your profile doesn't have access to the class exposed by this resource... – sfdcfox Mar 11 '16 at 20:08
  • @sfdcfox Ya sorry I will try and get some more info. Would it matter if I have this in a POST? Sending this along with a web to lead curl from a form. – Packy Mar 11 '16 at 20:34
  • Salesforce RestResources generally specify which methods are allowed. If you're getting a 403 METHOD NOT ALLOWED error, then it means POST isn't allowed. Unless you're sending a body with your data, you probably meant to use a GET though. Also, POST requires a Content-Length, which I don't know if curl does automatically in the face of an empty body (I just haven't tried). – sfdcfox Mar 11 '16 at 20:47
  • @sfdcfox I am getting Session expired or invalid","errorCode":"INVALID_SESSION_ID – Packy Mar 11 '16 at 20:59
0

Here are some good working eamples of calling SFDC Rest service from PHP using curl.

http://developer.force.com/cookbook/recipe/interact-with-the-forcecom-rest-api-from-php

I see there are few differences in your and sample code. I would suggest you to try to make match with sample code.

If it still does not work then you can use workbench to call your service.

And see what is being posted. They try and match that request. https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/quickstart_using_workbench.htm

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.