URGENT REQUEST: Add sortBy and sortOrder properties to API

KdeKokKdeKok Member Posts: 9
edited October 2018 in Development
Right now we have lots of large customers, with over thousands of orders a day, which we are almost unable to synchronize to a certain point back in time due to the low ratelimits and lack of possibility to reverse sortorer of e.g. the Get All invoices API call.
The only tooling we have is to increase the pagenumber, but while we wait for the rate-limit reset-period to expire and retrieve next pages, the contents of the first page have already changed. 
We can never retrieve the next page reliably, because while new orders flow in, the contents of the pages slide over time.
If we could however include the sortyBy=createdDate and sortOrder=ascending properties, we can reliably sync from a certain point in the history until up to date.

Please consider adding this must have feature!

Answers

  • gregaricangregarican Member Posts: 331 
    edited October 2018
    This is likely a bit deeper than a feature. The underlying nature of paginated API responses doesn't lend itself will to high transactional environments. Since each page response is pulled in real-time and indexing, ordering, pointers, etc. could change between page pulls.

    Here is a discussion of this topic that explains it pretty well from the API service provider's perspective --> https://mixmax.com/blog/api-paging-built-the-right-way

    Although for a workaround those query parameters would certainly make sense. And be a bit easier to implement from a back-end perspective.
    Post edited by gregarican on
  • Alex LugoAlex Lugo Administrator, Lightspeed Staff Posts: 152 moderator
    Hello @KdeKok,

    The API has an orderby and orderby_desc parameters that can be used with the createTime. You can read more about the available parameter in the link below.

    https://developers.lightspeedhq.com/retail/introduction/parameters/

    GET /API/Account/{accountID}/Sale.json?orderby=createTime&orderby_desc=1


    Alex Lugo
    API Support Specialist
    Lightspeed HQ
  • KdeKokKdeKok Member Posts: 9
    @Alex Lugo This is not working. You are refering to retail API, this is eCom/seoshop API
  • KdeKokKdeKok Member Posts: 9
    edited November 2018

    Exactly, a cursor or otherwise ascending sortorder is what's missing IMHO in the eCom API!


  • gregaricangregarican Member Posts: 331 
    edited November 2018
    KdeKok said:

    Exactly, a cursor or otherwise ascending sortorder is what's missing IMHO in the eCom API!


    It's also missing in the Retail API. For transactionally heavy customers this is a big deal. Although the fact that the vast majority of LS customers are smaller shops means that this likely won't get much attention. Unfortunately.

    So this doesn't work for you?

    edAt&orderby_desc=1 -u key:secret
    Post edited by gregarican on
  • gregaricangregarican Member Posts: 331 
    As a brief follow-up I have a e-com test account with API access. And the following API query example seemed to work in terms of sorting. The first example pulled all orders, while the second example pulled all products. The ordering in the responses was as expected.

    https://key:[email protected]/us/invoices.json?orderby=createTime&orderby_desc=1

    https://key:[email protected]/us/products.json?orderby=createdAt&orderby_desc=1
  • KdeKokKdeKok Member Posts: 9
    edited November 2018
    Not working for me. I have to connect to a different cluster i guess?
    I have to use API url https://api.webshopapp.com/nl/invoices.json
    none of the above examples work there. Invoices doesn't even have a 'createTime' field so i cannot imagine your example can work.

    btw, descending order is default. So what i really need is ascending orderering, oldest first.
  • gregaricangregarican Member Posts: 331 
    Sorry about that! You are correct, in that the orderby=createdAt should've been used in my invoices query. I guess that invalid orderby criteria is just ignored by the LS E-Com API endpoints. And you are correct, in that I am using a US cluster in my URL reference. Yours will obviously be different depending.

    I see what you mean though, in terms of the sorting not being honored. As a test I queried the products API endpoint, and specified the results to be ordered from oldest createdAt value to newest. Below are the results. It's still being sorted in descending order regardless. Definitely appears to be a bug somewhere. Or else the orderby and orderby_desc query parameters are being ignored altogether?

    cache-control: no-cache
    Postman-Token: 27de7970-3861-4f97-8625-3e46dc26ff87
    User-Agent: PostmanRuntime/7.1.1
    Accept: */*
    Host: api.shoplightspeed.com
    accept-encoding: gzip, deflate
    authorization: Basic xxxxxxxxxxxxxxxxxxxxx
    Connection: close


    HTTP/1.1 200 OK
    Server: nginx
    Date: Thu, 08 Nov 2018 13:10:56 GMT
    Content-Type: application/json; charset=utf-8
    Connection: close
    X-Api-User-Id: 16453
    X-RateLimit-Limit: 1000/12000/288000
    X-RateLimit-Remaining: 998/11992/287992
    X-RateLimit-Reset: 244/2944/38944
    X-Runtime: 0.074462
    X-Shop-Id: 622155
    X-Served-By: cml-use1prod-proxy-07416ddab462536b1.localdomain
    X-Request-Id: b21bd665ac01081baffd4891af2b5118
    Content-Length: 19579

    {
       "products":[
          {
             "id":15912486,
             "createdAt":"2018-09-07T16:31:09+00:00",
             "updatedAt":"2018-11-07T19:13:23+00:00",
             "isVisible":false,
             "visibility":"hidden",
             "hasMatrix":false,
             "data01":"",
             "data02":"",
             "data03":"",
             "url":"bridal-14k-white-gold-aa-diamond-engagement-ring-1",
             "title":"Bridal 14k White Gold AA Diamond engagement ring",
             "fulltitle":"Bridal 14k White Gold AA Diamond engagement ring",
             "description":"",
             "content":"",
             "set":false,
             "brand":{
                "resource":{
                   "id":872530,
                   "url":"brands\/872530",
                   "link":"https:\/\/api.shoplightspeed.com\/us\/brands\/872530.json"
                }
             },
             "categories":{
                "resource":{
                   "id":false,
                   "url":"categories\/products?product=15912486",
                   "link":"https:\/\/api.shoplightspeed.com\/us\/categories\/products.json?product=15912486"
                }
             },
             "deliverydate":false,
             "image":{
                "createdAt":"2018-11-07T19:13:19+00:00",
                "updatedAt":"2018-11-07T19:13:19+00:00",
                "extension":"jpg",
                "size":20962,
                "title":"X7806AA",
                "thumb":"https:\/\/cdn.shoplightspeed.com\/shops\/622155\/files\/10913689\/50x50x2\/x7806aa.jpg",
                "src":"https:\/\/cdn.shoplightspeed.com\/shops\/622155\/files\/10913689\/x7806aa.jpg"
             },
             "images":{
                "resource":{
                   "id":false,
                   "url":"products\/15912486\/images",
                   "link":"https:\/\/api.shoplightspeed.com\/us\/products\/15912486\/images.json"
                }
             },
             "relations":{
                "resource":{
                   "id":false,
                   "url":"products\/15912486\/relations",
                   "link":"https:\/\/api.shoplightspeed.com\/us\/products\/15912486\/relations.json"
                }
             },
             "metafields":{
                "resource":{
                   "id":false,
                   "url":"products\/15912486\/metafields",
                   "link":"https:\/\/api.shoplightspeed.com\/us\/products\/15912486\/metafields.json"
                }
             },
             "reviews":{
                "resource":{
                   "id":false,
                   "url":"reviews?product=15912486",
                   "link":"https:\/\/api.shoplightspeed.com\/us\/reviews.json?product=15912486"
                }
             },
             "type":false,
             "attributes":{
                "resource":{
                   "id":false,
                   "url":"products\/15912486\/attributes",
                   "link":"https:\/\/api.shoplightspeed.com\/us\/products\/15912486\/attributes.json"
                }
             },
             "supplier":false,
             "tags":{
                "resource":{
                   "id":false,
                   "url":"tags\/products?product=15912486",
                   "link":"https:\/\/api.shoplightspeed.com\/us\/tags\/products.json?product=15912486"
                }
             },
             "variants":{
                "resource":{
                   "id":false,
                   "url":"variants?product=15912486",
                   "link":"https:\/\/api.shoplightspeed.com\/us\/variants.json?product=15912486"
                }
             },
             "movements":{
                "resource":{
                   "id":false,
                   "url":"variants\/movements?product=15912486",
                   "link":"https:\/\/api.shoplightspeed.com\/us\/variants\/movements.json?product=15912486"
                }
             }
          },
          {
             "id":15912485,
             "createdAt":"2018-09-07T16:31:08+00:00",
             "updatedAt":"2018-09-07T16:31:08+00:00",
             "isVisible":false,
             "visibility":"hidden",
             "hasMatrix":false,
             "data01":"",
             "data02":"",
             "data03":"",
             "url":"bridal-14k-white-gold-aaa-diamond-engagement-ring-15912485",
             "title":"Bridal 14k White Gold AAA Diamond engagement ring",
             "fulltitle":"Bridal 14k White Gold AAA Diamond engagement ring",
             "description":"",
             "content":"",
             "set":false,
             "brand":{
                "resource":{
                   "id":872530,
                   "url":"brands\/872530",
                  ...
  • KdeKokKdeKok Member Posts: 9
    *BUMP*

    Would be really nice if a Lightspeed Admin can respond to this. It is becoming more and more of a problem now for large customers. We need this ascending order functionality really bad! 

    (Or remove those annoying rate limits all together :wink:)
  • gregaricangregarican Member Posts: 331 
    I'd guess that larger customers who heavily rely on the API are in the minority in terms of overall LS customers. So submitting the idea to the http://ideas.lightspeedretail.com page probably wouldn't garner a lot of votes. Unfortunately.

    But this is really more of a bug than a new feature/functionality request. An API query parameter that is assumedy valid isn't reflected in the response's result set. 

    We are in the same boat when it comes to LS Retail. Bigger customer with noted functional gaps, that likely won't garner any attention. :neutral:   
Sign In or Register to comment.