LightSpeed eCom API and webhook

robyrajurobyraju Member Posts: 8

Hi,

I'm trying to integrate LightSpeed eCom with GetResponse App and do automations. I have implemented site tracking using GetResponse JS code. But i couldn't track or synchronize the products, orders or customers in the store. As i have talked with the GetResponse support, i came to know that GetResponse don't have ecommerce integration with LightSpeed. So, i have decided to try the LightSpeed webhooks to fetch details of products, orders or customers and send to GetResponse.

I have checked the webhooks in LightSpeed API article (https://developers.lightspeedhq.com/ecom/tutorials/webhooks/) and i just want to know answers for some questions below:

1. Is webhook or API more suitable for this case?

2. Do we need any API key or secret key for creating and using webhooks?

3. How can we get the group ID (X-Group-Id) of the webhook we want to use?

4. If we set up a webhook that will call a URL when a new product is added in the store or a new order has been paced, do the response have the details of the product added or the new order?

5. Do validation is necessary for a webhook? How to set 'X-Signature' value?

Please let me know.

Thanks in advance

Answers

  • LeahLeah Moderator, Lightspeed Staff Posts: 176 moderator

    hi @robyraju let me try to answer your questions:

    1. Is webhook or API more suitable for this case?

    If you're trying to fetch newly created and/or updated products, customers and orders, webhooks are suitable for this. If you need to fetch pre-existing records, you will need to use the API to get these.

    2. Do we need any API key or secret key for creating and using webhooks?

    Yes, you need an API key and secret in order to access the eCom API, including creating and updating webhooks.

    3. How can we get the group ID (X-Group-Id) of the webhook we want to use?

    The webhook groups and actions are outlined here: https://developers.lightspeedhq.com/ecom/tutorials/webhooks/

    The X-Group-Id is associated with webhooks sent to apps and do not apply for single shop connections like the one you would be working with.

    4. If we set up a webhook that will call a URL when a new product is added in the store or a new order has been paced, do the response have the details of the product added or the new order?

    Yes, the webhook responses will contain the objects from the group/event they are associated with.

    5. Do validation is necessary for a webhook? How to set 'X-Signature' value?

    X-Signature is another header that is used exclusively for app webhooks and does not apply in this case

    API Support
    Lightspeed HQ
  • robyrajurobyraju Member Posts: 8

    Hi @Leah,

    Thanks for the reply.


    To confirm, which of these do i need in my case:


    X-Shop-Id

    X-Format

    X-Language

    X-Group-Id

    X-RateLimit-Limit

    X-RateLimit-Remaining

    X-RateLimit-Reset

    X-Cluster-Id

  • robyrajurobyraju Member Posts: 8

    Hi,

    I have one more question.

    I want to get only popular products from the eCom store. If i use the "/products.json" resource, which parameter i need to pass with that to sort the result based on popularity?

  • LeahLeah Moderator, Lightspeed Staff Posts: 176 moderator

    @robyraju those headers represent the headers that are sent with the webhook to the URL of your choosing. They will all be included in the webhook request. You can set up your webhooks on your shop and use a URL generated by the webhook tester at: https://webhook.site/ for the 'address' field. This URL will then allow you to see the full webhook request that eCom sends.

    As for the popular products, there is no API field for products that would allow you to sort based on popularity. The ability to sort on popularity is limited to the theme variables. See the documentation here: https://ecom-support.lightspeedhq.com/hc/en-us/articles/115000277594-3-b-Rain-variables#template-pageindexrain

    API Support
    Lightspeed HQ
  • robyrajurobyraju Member Posts: 8
    edited November 2019

    Hi @Leah,

    Thanks for the reply.

    Now, i'm trying to get all the products in the store using API.

    I'm using the below function of PHP Client for that:


    $shopInfo = $api->products->get(null,array('page'=>1,'limit'=>250));


    when i printed out the $shopInfo array, i only get 249 products. So, i have tried with another request with page=2 as below:


    $shopInfo = $api->products->get(null,array('page'=>1,'limit'=>250));

    This time also i got only 249 products.


    There is about 9970 products in the store. I have printed out the count of products using the below function:


     $api->products->count();


    I got the count of products as 2849.

    1) Could you please let me know why this is less than the count of products i have in the eCom store?

    2) Will this happen if the remaining products are set as hidden in the eCom store?


    3) If we created a webhook to trigger on order creation, using the below code, how can we get the details of the order created? What do i need to do for that?

    <?php
    $api->webhooks->create([
        'isActive'   => true,
        'itemGroup'  => 'orders',
        'itemAction' => 'created',
        'language'   => 'en',
        'format'     => 'json',
        'address'    => 'https://requestb.in/12345'
    ]);
    


    4) I have created a webhook for quotes in the webhook.site. I could see the webhook data in webhook.site. But i didn't get the customer details for the new quote created. Please refer the below screenshot. How can i get the customer details for quotes from the webhook data?

    5) I have tried to redirect the webhook data to a https url using the following settings:

    When i clicked "Redirect Now", i got an error message as follows:


    But, i couldn't figure out what causes the error and how to fix it.


    Please let me know.


    Thanks in advance.

    Post edited by robyraju on
  • robyrajurobyraju Member Posts: 8

    Hi @Leah ,

    Thanks for the reply.

    I have some questions regarding the webhook.site.

    1) I have created a webhook for trigger when a new quote is created.

    I got the webhook data in webhook.site. But i didn't get the customer details for the new quote created. Please refer the screenshot:

    How can we get the customer details of the quotes created ?


    2) I have tried to redirect the webhook data to a https url using the below settings

    But, when i clicked "Redirect Now" , the site is showing some error message as below:

    I couldn't figure out why this is happening and how to fix this.

    Please let me know


    Thanks in advance.

  • LeahLeah Moderator, Lightspeed Staff Posts: 176 moderator

    In order to add a customer to a quote, you need to include the customer ID in the "customer" field when creating (POST) or updating (PUT) the quote as outlined here: https://developers.lightspeedhq.com/ecom/endpoints/quote/#post-create-a-quote

    The webhook tester is a third party site, not affiliated with or supported by Lightspeed, which I provided as an example for testing purposes. You should be receiving your webhooks at your own URL rather than trying to redirect them from webhook.site.

    API Support
    Lightspeed HQ
  • robyrajurobyraju Member Posts: 8
    edited November 2019

    Hi @Leah ,


    Actually, the mentioned quote was created by a valid customer of the eCom store. I had just created a webhook to trigger when a new quote is created in the store.

    So, when a new quote is created in the store, the webhook is triggered and the data is pulled as json in the webhook tester url i have mentioned at the time of webhook creation.

    How can i include customer ID in that case? It needs to be included in the webhook data as below, right?


    I have also tried fetching all the quotes in the store using the below API method:

    $api->quotes->get();

    Then also, in some quotes there is no customer ID:


    Please let me know why this is happening and how to fix it.


    Thanks!

    Post edited by robyraju on
  • LeahLeah Moderator, Lightspeed Staff Posts: 176 moderator

    I'm going to do some testing of the behaviour around quote creation and webhooks and get back to you. In the meantime, could you DM me the shop ID and a few example quote IDs for quotes that have no customer attached when they should have one? Thanks.

    API Support
    Lightspeed HQ
  • robyrajurobyraju Member Posts: 8

    Hi @Leah ,


    I'm not sure which is the shop ID .

    This is the ID i got using the API : 611232

    This is the eCom backoffice url : https://macpherson-toy-house.shoplightspeed.com/

    Following are some of the quote IDs that have no customer details:

    23532184

    23503843

    23503782

    23404480

    23133495


    Please let me know.


    Thanks

  • LeahLeah Moderator, Lightspeed Staff Posts: 176 moderator

    Quotes are created very early on in the front-end checkout process (as soon as the quote object is created) so if you are getting the quotes/created webhook, you may often be receiving quotes that have no customer attached. It's possible to have a case where a quote is created (when the cart is made) and then the valid eCom customer subsequently signs in. The customer will, at this point, be attached to the quote, but their details will not have been sent with the quotes/created webhook. You might consider using the quotes/updated webhook, or better yet, the order/created webhook instead since this will ensure all required details are included.

    API Support
    Lightspeed HQ
Sign In or Register to comment.