HELP! Get current lead's ID w/PHP (not Tracking ID)

Comments

4 comments

  • Official comment
    Avatar
    Scott Silver

    Hi Chris, 

    Thank you very much for this question! 


    There are a couple of methods that I believe should work for you to return the SharpSpring leadID. 

    The first option would be to use our Dynamic Web Content code to return the lead object record on any tracked lead. Information on this process can be found in the following article:

    https://help.sharpspring.com/hc/en-us/articles/115001036207-For-Developers-Adding-Dynamic-Web-Content-to-Tracking-Codes 

    You can then use the object response to pull or map any fields dynamically. Here is an example of the response that this code will provide:

    Email: "scottshsp+74579873423@gmail.com"
    First Name: "John"
    Has an Opportunity: 1
    Last Name: "Smith"
    Lead Score: 6
    Lead Status: "customer"
    SharpSpring ID: 638987231234
    trackingID: "201809|5ba2b0d9dedb9a06be5ccb2e"
    type: "page"

    The second option would be to use our getLeads API method and use the emailAddress within the where parameter. Here is an example of the JSON call to make this post:

    {"method":"getLeads",
     "params":{
     "where":{
      "emailAddress":"scottshsp@gmail.com"
     },
     "limit":500,
     "offset":0
    },
    "id":123
    }

    This post will return the full lead record, including the leadID. Here is an example of what that php would look like:

     

    <?php

    $method = 'getLeads';
    $params = array(

    'where' => array(
    // 'id' => '488139403266'
    // 'emailAddress' => 'unique500@gmail.com'
    ),

    'limit' => '500',
    'offset' => '0'

    /* 'fields' => array(
    'firstName',
    'lastName',
    'title'
    ) */

    );
    $requestID = session_id();
    $accountID = 'ECCBC87E4B5CE2FE28308FD9F2A7BAF3';
    $secretKey = '58177D3CDCF0D69B52081F633A337132';
    $data = array(
    'method' => $method,
    'params' => $params,
    'id' => $requestID,
    'header' => array(
    'accountID' => $accountID,
    'secretKey' => $secretKey,
    )
    );

    $queryString = http_build_query(array('accountID' => $accountID, 'secretKey' => $secretKey));
    $url = "http://api.sharpspring.com/pubapi/v1/?$queryString";

    $data = json_encode($data);
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data),
    'Expect: '
    ));

    $result = curl_exec($ch);
    curl_close($ch);

    echo $result;

    // Sample Response
    /*
    {"result":{"lead":[{"id":"88038560770","accountID":"2023607298","ownerID":"313370204","companyName":"Company One","title":"VPOP", "street":"555 SW 5th St","city":"Gainesville","country":"United States","state":"FL","zipcode":"32601", "website":"www.leadone.com","phoneNumber":"5555555555","officePhoneNumber":"0987654321","phoneNumberExtension":"55","mobilePhoneNumber":"3333333333","faxNumber":"8888888888","description":"This is Lead One description text","campaignID":"357630978","leadScore":"20","industry":"Finance","active":"1","isUnsubscribed":"0","updateTimestamp":"2016-11-09 17:18:22","leadScoreWeighted":"20","leadStatus":"qualified","api_big_text_area_57f6638adc5b8":""}]},"error":null,"id":""}
    */

    ?>

     

    Hope this helps! 

    Please let me know if you have any questions or concerns regarding this information and I am happy to assist! 


    Comment actions Permalink
  • Avatar
    Chris Martin

    Thanks, but this still doesn't completely solve my problem without other workarounds to pass data from the browser to the server.

    The Dynamic Content guidance relies on JS to capture the lead data... I'd like to be able to do it all on the server side.  I can use it and use the data on the front end, but what if I want to do all of this on the server side?

    The getLeads method is useful if I have the email address, but again, that isn't available on the server side unless I know the SharpSpring ID, in which case I'd just use the getLead method.

    Basically what you seem to be suggesting is I acquire lead data on the front end (at least, the email address) and pass it to the server, which I'd rather not do if possible. 

    It seems like an oversight that the API doesn't provide a way to fully communicate with SharpSpring from the server side without intervention from the front end code.  I keep asking myself if there is something stupid I'm missing, but can't seem to figure it out.

    3
    Comment actions Permalink
  • Avatar
    Louis

    Chris Martin Have you found a successful workaround for this? It seems like a major drawback if we have to rely on client-side scripts to get the lead ID.

     

    Thanks

    0
    Comment actions Permalink
  • Avatar
    Nick Ciske

    Unfortunately by the time the tracking ID is known, the server is done with the request so PHP would not have access.

    The tracking ID would have be retrieved via JS and passed to the server via ajax/fetch or as a query parameter via a redirect...then stored in a session or cookie to be available to PHP (and again, only on the 2nd request, not the first).

    The alternate approach is to fetch it via getLead if you knew the ID or email (e.g. they were logged in).

     

    0
    Comment actions Permalink

Please sign in to leave a comment.