Trying to load sales of a specific item on a specific date.

rsirotarsirota Member Posts: 93

I am trying to load all sales on a specific date which contact an item "FREE DELIVERY". I am having no luck using the key Sales.Sale.SalesLines.SaleLine.Item.description and setting it to FREE DELIVERY. Other parts of the query work. But when I add that line the count seems like all sales on that date not just the ones with "FREE DELIVERY"

Tags:

Answers

  • LucienVersendaalLucienVersendaal Moderator, Lightspeed Staff Posts: 856 moderator
    edited December 2020

    Hi @rsirota,

    Thank you for contacting us.

    You can use:

    /SaleLine?load_relations=["Item"]&Item.description=FREE DELIVERY

    If you want to add a date, so every sale after X date:

    /SaleLine?load_relations=["Item"]&Item.description=FREE DELIVERY&timeStamp=>,2020-12-01

  • rsirotarsirota Member Posts: 93

    That works but I am needing the whole sale ticket which includes the FREE DELIVERY.

    I have tried:

    https://api.lightspeedapp.com/API/Account/{{accountID}}/Sale?load_relations=all&timeStamp=>,2020-12-01T00:00:00-800&Item.description=FREE DELIVERY

    Which returns tons of entries, not just the 2 which have the FREE DELIVERY

    and

    https://api.lightspeedapp.com/API/Account/{{accountID}}/SaleLine?load_relations=all&Item.description=FREE DELIVERY&timeStamp=>,2020-12-01


    Which returns only those 2 line items not the whole orders attached to the line

  • LucienVersendaalLucienVersendaal Moderator, Lightspeed Staff Posts: 856 moderator

    Hi @rsirota,

    I guess you're trying to find the whole sales where FREE DELIVERY is included. With the query I gave you, you're looking for only the sales where FREE DELIVERY is in the SaleLine and not the other items. Which makes sense because you're looking for that specific Item.Description.

    I'm afraid you can't get the full sale when doing this call.

  • rsirotarsirota Member Posts: 93

    Is there a way to get all sales for a day with "FREE DELIVERY"? Any way you could suggest would be great... I have also tried :

    https://api.lightspeedapp.com/API/Account/{{accountID}}/SaleLine?load_relations=all&Item.description=FREE DELIVERY&timeStamp=>,2020-12-01

  • LucienVersendaalLucienVersendaal Moderator, Lightspeed Staff Posts: 856 moderator

    Hi @gregarican,

    I know you have a lot of experience with Retail API, maybe you have a suggestion for @rsirota?

  • gregaricangregarican Member Posts: 683 

    I would suggest a series of two API calls, the first one for pulling the matching sales lines, and then the second one based on those referenced sales header ID's to pull the entire sales records. Not the most elegant solution, but practical! 😀

  • rsirotarsirota Member Posts: 93

    Thanks... I was trying to keep the call limit down.

  • rsirotarsirota Member Posts: 93

    So things work in Postman, however, when I do a php page for the web site I am not getting any data.

    Here is my code for the call:

    $tokenURL = "https://api.lightspeedapp.com/API/Account/{$accountID}/SaleLine?load_relations=all&timeStamp=>,2020-12-12&Item.description=FREE DELIVERY";

    $curl = curl_init();

    curl_setopt_array($curl, array(

    CURLOPT_URL => $tokenURL,

    CURLOPT_RETURNTRANSFER => true,

    CURLOPT_ENCODING => "",

    CURLOPT_MAXREDIRS => 10,

    CURLOPT_TIMEOUT => 30,

    CURLOPT_CUSTOMREQUEST => "GET",

    CURLOPT_HTTPHEADER => array(

    "Authorization: Bearer {$access_token}",

      )

    ));

    $response = curl_exec($curl);

    $responseObj = json_decode($response);

    $jsonString = json_encode($responseObj, JSON_PRETTY_PRINT);

    $err = curl_error($curl);


    curl_close($curl);


    if ($err) {

    echo "cURL Error #:" . $err;

    } else {

    // echo $tokenURL; 

    echo "We should have data";

    }

    echo "<pre>$responseObj</pre>";


    I do know my access-token is working and everything else is also working (ie secret)


    Any help? If you need to see my full files let me know.

  • gregaricangregarican Member Posts: 683 

    What does the API response look like? Between the HTTP error code, the response body, etc. there should be some indicators. Maybe run Fiddler or inspect the elements using your PHP code to see...

  • rsirotarsirota Member Posts: 93

    if I echo the following:

    echo $response;

    I get

    Bad Request

    Your browser sent a request that this server could not understand.


    I have included a link to the script:

    http://sirota-consulting.com/PPLG/getData.php

  • gregaricangregarican Member Posts: 683 

    I think I see now. Try modifying how you are specifying the timeStamp query parameter. I believe your greater-than-or-equal-to is reversed. And I believe you need to include a time and timezone. Example below, for me in the US Eastern Timezone.

    timeStamp>=,2020-12-12T00:00:01-5:00

  • rsirotarsirota Member Posts: 93

    Still no luck...

Sign In or Register to comment.