Struggling to update Item - Sales Price

So as will probably become apparent I am quite new to the REST API and am trying to use PUT to update a record.

Everything is updating fine EXCEPT for the sales price (my app doesn't make use of the wholesale or trade prices at the moment).

I am probably overlooking something really simpe and have altered my code to try various different things and have officially given up in the hope of help.

We are due to get our shop online next week and require this to automatically update the pricing on thousands of lines.

IF anyone could give me a heads up on where I'm going wrong it would be appreciated.

The code I'm using is below : -


$data = array(
                    'stock_item' => array(
                                                            'displayed_as' => "Same as description",
                                                            'item_code' => "Item Code",
                                                            'description' => "The description of the item",
                                                            'notes' => "These are the updated notes for the item.",
                                                            'cost_price' => "50.00",
                                                           

                                                             'sales_prices' => array(
                                                                                array(
                                                                                'price' => "100.00"
                                                                                ),
                                                            
                                                            ),

                                                            'purchase_description' => "Purchase description",
                                                            'supplier_part_number' => "Supplier Part Number"
                                                            )
                );


This works fine on everything except for the sales_prices field, but if I include this I get one of the following errors.

array(1) { [0]=> object(stdClass)#1 (4) { ["$severity"]=> string(5) "error" ["$dataCode"]=> string(13) "RecordInvalid" ["$message"]=> string(36) "The service_rate_type_id is invalid." ["$source"]=> string(17) "service_rate_type" } }

OR

array(1) { [0]=> object(stdClass)#1 (4) { ["$severity"]=> string(5) "error" ["$dataCode"]=> string(10) "Validation" ["$message"]=> string(35) "stock_item[sales_prices] is invalid" ["$source"]=> string(24) "stock_item[sales_prices]" } }

Depending on how I structure my code.

I am fairly sure it is down to how I am structuring my nested arrays, but would be most grateful for any help.

While I am here, I have also noticed that I am unable to update the displayed_as field. This just takes on the value of whatever is PUT in the description field; not sure if that is done by design or not, but something I spotted the other day.

Look forward to hearing from someone soon.

Parents
  • Dear Krasta,

    first of all, the `displayed_as` field is readonly——by design. It is composed of or aliases other attributes, depending on the endpoint.

    Secondly, the `sales_prices` attribute is an Array of Strings (dont ask me why numbers are being required as Strings, but at least the docs are clear about it: https://developer.sage.com/api/accounting/api/products-services/#operation/postStockItems if you are using version 3.1 and developer.columbus.sage.com/docs if you are on version 3). So, your payload should look like this:

    'sales_prices' => array('100.00')

    Let me know if you need further help on this.

    Best regards,

    Martin Eismann

    Sage

  • Hi Martin,

    Many thanks for the fast response.

    It is noted about the 'displayed_as' field, I figured it may have been done by design, and you've cleared it up.

    On the other issue I updated the code with your suggestion, and it now returns the following error : -

    array(1) { [0]=> object(stdClass)#1 (4) { ["$severity"]=> string(5) "error" ["$dataCode"]=> string(15) "UnexpectedError" ["$message"]=> string(29) "An unexpected error occurred." ["$source"]=> string(0) "" } }

    This was actually how I had it, and started delving in to other options when it wouldn't work. Any further suggestions you might be able to mak would be gratefully received.

  • Hi Krasta,

    sorry for this unhelpful error message. I digged into the issue and tried to fire your request myself and was successfull with the below JSON payload. As you can see, I had to add the following attributes to your payload:

    • `sales_ledger_account_id` — choose an ID from your sales ledger accounts from the response of /ledger_accounts
    • `purchase_ledger_account_id` — choose an ID from your purchase ledger accounts from the response of /ledger_accounts
    • `sales_prices[][product_sales_price_type_id]` — choose an ID from the response of /product_sales_price_types endpoint.

    Here is the JSON that worked for me. You do have to replace the three IDs mentioned above with IDs from responses you get at the respective endpoints!

    {
      "stock_item":{
        "sales_prices":[
          {
            "product_sales_price_type_id":"d491850628e0403b80c1d715d9d40812",
            "price":"100.00"
          }
        ],
        "purchase_ledger_account_id":"634b6f8dcfdb11e9998a0242ac1a0005",
        "sales_ledger_account_id":"634c9522cfdb11e9998a0242ac1a0005",
        "purchase_description":"Purchase description",
        "cost_price":"50.00",
        "description":"The description of the item",
        "item_code":"Item Code2",
        "notes":"These are the updated notes for the item.",
        "supplier_part_number":"Supplier Part Number"
      }
    }
    You may notice that the "sales_prices" attribute is not the Array of Strings I have pointed you to. What is worse, our docs are wrong in both versions, 3 and 3.1. I beg your pardon for this and will make sure this docs issue gets addressed.
    Best regards,
    Martin Eismann
    Sage
Reply
  • Hi Krasta,

    sorry for this unhelpful error message. I digged into the issue and tried to fire your request myself and was successfull with the below JSON payload. As you can see, I had to add the following attributes to your payload:

    • `sales_ledger_account_id` — choose an ID from your sales ledger accounts from the response of /ledger_accounts
    • `purchase_ledger_account_id` — choose an ID from your purchase ledger accounts from the response of /ledger_accounts
    • `sales_prices[][product_sales_price_type_id]` — choose an ID from the response of /product_sales_price_types endpoint.

    Here is the JSON that worked for me. You do have to replace the three IDs mentioned above with IDs from responses you get at the respective endpoints!

    {
      "stock_item":{
        "sales_prices":[
          {
            "product_sales_price_type_id":"d491850628e0403b80c1d715d9d40812",
            "price":"100.00"
          }
        ],
        "purchase_ledger_account_id":"634b6f8dcfdb11e9998a0242ac1a0005",
        "sales_ledger_account_id":"634c9522cfdb11e9998a0242ac1a0005",
        "purchase_description":"Purchase description",
        "cost_price":"50.00",
        "description":"The description of the item",
        "item_code":"Item Code2",
        "notes":"These are the updated notes for the item.",
        "supplier_part_number":"Supplier Part Number"
      }
    }
    You may notice that the "sales_prices" attribute is not the Array of Strings I have pointed you to. What is worse, our docs are wrong in both versions, 3 and 3.1. I beg your pardon for this and will make sure this docs issue gets addressed.
    Best regards,
    Martin Eismann
    Sage
Children