Sale -> SaleLines

jtellierjtellier Member Posts: 38

I don't see in the documentation how to add SaleLines to a Sale in the create POST.

Would it just be like? - This creates the order but no SaleLines are on the order.

{

    "completed": true,

    "archived": false,

    "voided": false,

    "employeeID": 1,

    "shopID": "1",

    "registerID": "1",

    "enablePromotions": true,

    "isTaxInclusive": false,

    "completeTime": "2020-07-14T10:48:50+00:00",

    "referenceNumber": "RunFreeProjectNumber",

    "receiptPreference": "printed",

    "customerID": "15467",

    "SaleLines": [{

        "itemId": "583",

        "unitQuantity": 1,

        "unitPrice": "2.99",

        "shopID":"1"

    }],

    "SalePayments": [{

        "paymentTypeID": 3,

        "amount": "3.17"

    }]

}

8 comments

  • gregaricangregarican Member Posts: 469 

    What I would recommend it trying an API GET request for a specific sale that exists, with its associated line items. Such as:


    GET https://api.merchantos.com/API/Account/{AccountId}/Sale.json?archived=false&voided=false&completed=true&load_relations=["SaleLines","SaleLines.Discount","SaleLines.Note","SaleLines.Item","SalePayments","SalePayments.PaymentType","SalePayments.SaleAccounts","Customer","Customer.Contact","Discount"]&offset=0&limit=100


    If you inspect the API response you will see the format that the sales lines need to be in. Of course certain fields should be considered read-only, such as the saleLineID, createTime, timeStamp, etc.

  • jtellierjtellier Member Posts: 38

    Ok so I did that, and now I get this:

    {

        "httpCode": "400",

        "httpMessage": "Bad Request",

        "message": "No payment charge attached to this sale payment",

        "errorClass": "SaleError",

        "saleID": "1955"

    }

    when posting like it showed:


    {

        "completed": true,

        "archived": false,

        "voided": false,

        "employeeID": 1,

        "shopID": "1",

        "registerID": "1",

        "enablePromotions": true,

        "isTaxInclusive": false,

        "completeTime": "2020-07-14T10:48:50+00:00",

        "referenceNumber": "RunFree TEST",

        "receiptPreference": "printed",

        "customerID": "15467",

        "taxTotal": 0.18,

        "SaleLines": {

            "SaleLine": [{

                "itemID": 583,

                "unitQuantity": 1,

                "unitPrice": 2.99,

                "calcTax": 0.18,

                "taxClassID": 0,

                "shopID":"1"

            }]

        },

        "SalePayments": {

            "SalePayment": [{

                "paymentTypeID": 3,

                "amount": 3.17,

                "remoteReference": "RFTEST"

            }]

        }

    }

    And if I take out the hard defined sub object type SalePayment: [] I get an error that the SalePayments dont add up to $3.17

  • gregaricangregarican Member Posts: 469 

    When I perform a GET of an existing sale, with all the relations loaded (e.g. - SalePayments) I don't see braces around the SalePayment specifics. Remember a gotcha, in that a lot of times if a property can be an array, it only requires or emits braces if it actually has multiple items. If it only has one item there aren't any braces involved. Here's a snippet below from my GET response.


    "SalePayments": {

                    "SalePayment": {

                        "salePaymentID": "2495",

                        "amount": "188.13",

                        "createTime": "2019-01-19T15:30:47+00:00",

                        "archived": "false",

                        "remoteReference": "e8107a65-29bb-49fd-b939-ca3751501298",

                        "paymentID": "",

                        "saleID": "4396",

                        "paymentTypeID": "18",

                        "ccChargeID": "0",

                        "refPaymentID": "0",

                        "registerID": "1",

                        "employeeID": "24",

                        "creditAccountID": "0",

                        "PaymentType": {

                            "paymentTypeID": "18",

                            "code": "",

                            "name": "PayPal",

                            "requireCustomer": "true",

                            "archived": "false",

                            "internalReserved": "false",

                            "type": "user defined",

                            "channel": "instore",

                            "refundAsPaymentTypeID": "0"

                        }

                    }

                }

  • jtellierjtellier Member Posts: 38

    That didnt help, same error:


    {

        "httpCode": "400",

        "httpMessage": "Bad Request",

        "message": "No payment charge attached to this sale payment",

        "errorClass": "SaleError",

        "saleID": "1970"

    }

  • jtellierjtellier Member Posts: 38
    edited July 16

    Is there a way to see what is wrong with that post?... or get an example of one that would work including:

    Sale

    LineItems

    Payments

  • jtellierjtellier Member Posts: 38

    I figured out that I needed to set it as type 7 instead of 3 for payment types since it was an ecommerce purchase I was just thinking that was going to be from eCom product as opposed to a third party platform like ours.

    But not the order shows in Retail as "In Progress" what needs to be set to complete it, I have it set as "completed": true, is there something else?

  • LeahLeah Moderator, Lightspeed Staff Posts: 187 moderator

    Hi @jtellier, I did some tests, and I suspect the issue is the remote reference you're using for the payment not being unique. Can you PM me the request URL (including account ID) and post the full payload you're sending and it's corresponding error message? I'll try to get to the bottom of it.

    API Support
    Lightspeed HQ
  • jtellierjtellier Member Posts: 38

    @Leah - I think I send you a DM, did you get it, I don't see private messages in here?

Sign In or Register to comment.