how can we create sales order (with line item and completed status) in minimum API calls?

madhupatelmadhupatel Member Posts: 12

I have made two API calls two to make 1 sales order, But my order is in In Progress status. how can I make it complete status?

Endpoints detail: https://api.lightspeedapp.com/API/Account/my_ac_num/Sale.json

https://api.lightspeedapp.com/API/Account/my_ac_num/Sale.json?load_relations=all

can you please guide me what's the best practice to create a sales order(with line item and completed status) with minimum API calls?


Tags:

19 comments

  • gregaricangregarican Member Posts: 683 
    edited January 13

    What happens when you include "completed": "true" and "completeTime": "yyyy-MM-ddThh:mm:ss+00:00" (of course set to whatever timestamp is valid) in the API request that creates the sale?

    Per the API documentation (https://developers.lightspeedhq.com/retail/endpoints/Sale/#post-create-a-sale) these appear to be fields that you can define. Although there's a chance the documentation could be off...

  • madhupatelmadhupatel Member Posts: 12
    edited January 14

    1) 

    In create sale endpoint when I'm passing completed and completeTime field I'm not able to add line item for the sales order beacuase we can't edit completed sale order.So In that case what I need to do?

    Endpoints Details

     /API/Account/{accountID}/Sale.json (for creating a sale)

     /API/Account/{accountID}/Sale/{saleID}/SaleLine.json (for creating a sales line items)

     

     2)Can we pass line item Details in create sales endpoint with completed and completeTime field?

     if it's possible please provide JSON formate how can we pass it.

  • gregaricangregarican Member Posts: 683 

    The API documentation doesn't provide an example of a one-shot API request for POST'ing a new sale with its accompanying line item(s). I'd suggest trying it to see what the outcome is.

    If that doesn't work, then you are essentially looking at a clumsy multiple step process --- creating the new sale record, assigning line items to the sale record, and then changing the sale status (if possible after the fact). 😣

  • madhupatelmadhupatel Member Posts: 12

    Hey Gregarican,

    Thanks for your suggestion. But I have already tried both solutions and it doesn't work.


    1 case) when I'm trying to create sales with line items it's only created the sale and not added my line items.


    2 case) Then I created a sales order and then I added my line item to sale after that I'm trying to change the status of the sale it's giving me the below error. Please let me know how can I solve this issue.

    {

      "httpCode": "400",

      "httpMessage": "Bad Request",

      "message": "Cannot complete an out of balance sale. Payments are insufficient.",

      "errorClass": "OutOfBalanceError",

      "saleID": "14",

      "balance": "10"

  • gregaricangregarican Member Posts: 683 

    Sorry you're still running into trouble with this. As for the insufficient payments response you're getting, do these transactions involve non-taxable items or discounts? There are a few threads on here involving quirks with those use cases. Also, can you post a sanitized version of your API requests that are failing with this error?

  • Salesforce_developerSalesforce_developer Member Posts: 22

    Having a related issue. Manually we can add a New Sales, assign Customer and then assign Items and 'Save as Quote'. However we want to do this via api when we synch our items from Salesforce but can't locate a way to 'Save as Quote'?

  • gregaricangregarican Member Posts: 683 

    If you are talking about creating a quote in Retail, here is that particular API endpoint --> developers.lightspeedhq.com/retail/endpoints/Quote/.

  • Salesforce_developerSalesforce_developer Member Posts: 22

    We first Created Quote then we creates Sales and at the same time we includes Sales line Items


    Please see below request for Sale and Saleline

    https://api.lightspeedapp.com/API/Account/139956/Sale/19606.json


    {

             

            "completed": "false",

            "voided": "false",        

            "customerID": "12596",     

            "employeeID": "10",

            "quoteID": "56",

            "registerID": "2",

             "shopID": "2",

             "SaleLines":{"SaleLine":[

             {

                   

                    "unitQuantity": "1",

                    "unitPrice": "310",

                    "normalUnitPrice": "310",

                    "discountAmount": "0",

                    "discountPercent": "1",

                    "avgCost": "72.22",

                    "fifoCost": "72.22",

                    "tax": "true",

                    "tax1Rate": "0.2",

                    "tax2Rate": "0",

                    "isLayaway": "false",

                    "isWorkorder": "false",

                    "isSpecialOrder": "false",

                    "displayableSubtotal": "0",

                    "displayableUnitPrice": "155",

                    "calcLineDiscount": "310",

                    "calcTransactionDiscount": "0",

                    "calcTotal": "0",

                    "calcSubtotal": "310",

                    "calcTax1": "0",

                    "calcTax2": "0",

                    "taxClassID": "1",

                    "customerID": "0",

                    "discountID": "4",

                    "employeeID": "10",

                    "itemID": "43454",

                    "noteID": "0",

                    "parentSaleLineID": "0",

                    "shopID": "2"

             }

             ]

             }

        }



    We are getting Success response, with status code = 200 but we can not see line items under sale.

  • Salesforce_developerSalesforce_developer Member Posts: 22

    Hi @gregarican should we be able to see the line items


    'We are getting Success response, with status code = 200 but we can not see line items under sale.'

  • gregaricangregarican Member Posts: 683 

    Do you see the lines in the Retail front-end web client?

  • Salesforce_developerSalesforce_developer Member Posts: 22

    Yes we do, but it's a 2 step process. Step 1m add client, step 2 search and add items, then you can 'Save as Quote.

  • Salesforce_developerSalesforce_developer Member Posts: 22

    So that is the challenge  @gregarican is there a way to query and add the lines whilst we are building the sale?

  • LeahLeah Moderator, Lightspeed Staff Posts: 219 moderator

    @Salesforce_developer For the sale you shared above, you need to load the relations in order to see the sale lines: https://api.lightspeedapp.com/API/Account/139956/Sale/19606.json?load_relations=["SaleLines"]

    More on loading relations here: https://developers.lightspeedhq.com/retail/introduction/relations/

    API Support
    Lightspeed HQ
  • Salesforce_developerSalesforce_developer Member Posts: 22

    thank you @Leah

    However, that method would bring back items already related. In the process of creating a 'Quote' the items exist, but are not yet related, it's the process of adding them that relates them. So what we need is the ability to add the 'Sale' then query the item with the SKU and relate it to that Sale.

  • Salesforce_developerSalesforce_developer Member Posts: 22

    Hi @Leah We want to push the SaleLines under the Sale record. The API you shared is for a GET request a POST request.

    We wish to send data to 'Sale' and 'Saleline' in POST request from Salesforce to Lightspeed

  • Salesforce_developerSalesforce_developer Member Posts: 22

    If I could find out whether this is possible at all, that would really help me @Leah

  • LeahLeah Moderator, Lightspeed Staff Posts: 219 moderator

    @Salesforce_developer I'm not sure I understand what the issue is, could you clarify? You can create a new sale using POST and then add salelines to it using POST. Is there some reason that process isn't working for you?

    API Support
    Lightspeed HQ
  • Salesforce_developerSalesforce_developer Member Posts: 22

    Creating the new Sales is fine.

    But our next step is to assign Items that already exist, so we are not creating new. We therefore need to locate them with a Query (using SKU number) and then add them to that new Sale.

  • rodeomasterrodeomaster Member Posts: 12

    Hi!

    We are also having an issue with creating a sale, in python we do:

    data = {

    "completed": "false",

    "voided": "false",

    "customerID": "6336",

    "employeeID": "5",

    "quoteID": "0",

    "registerID": "1",

    "shopID": "1",

    }

    path = "https://api.lightspeedapp.com/API/Account/{acount_id}/Sale.json"

    headers = {"Authorization": "Bearer {our_access_token}}

    response = requests.request("POST, path, headers=headers, data=data)

    But we receive:

    {'httpCode': '400', 'httpMessage': 'Bad Request', 'message': 'JSON Input was invalid. Error Message: Syntax error', 'errorClass': 'InvalidArgumentException'}

    We really can't figure our what is the issue... Hope you can help us! Thanks in advance

Sign In or Register to comment.