RJ98 Posted April 17, 2022 Share Posted April 17, 2022 I am using the stock items endpoint using the updates product PUT method here is my request: url = "https://api.accounting.sage.com/v3.1/stock_items/{key}".format( key=product_id ) headers = { "Content-Type": "application/json", "Authorization": "Bearer " + access_token, } payload = {"stock_item": {"quantity_in_stock": new_quantity}} response = requests.request("PUT", url, headers=headers, data=payload) The new_quantity is a double/float data type. The JSON returned from the API was that a malformed API request was sent. Any ideas on what I am getting wrong? Thanks Link to comment Share on other sites More sharing options...
Steel, Mark Posted April 19, 2022 Share Posted April 19, 2022 Hi Norman, thank you for your question. quantity_in_stock can only be set on the creation of the record. If you then wish to adjust the stock level you must use the stock_movements API as in the below POST example. { "stock_movement":{ "stock_item_id":"c251189a7e614c89b5b48a0825908fe8", "date":"2022-04-19", "quantity":10, "cost_price":50, "details":"API Adjustment" } } Thanks Mark Link to comment Share on other sites More sharing options...
RJ98 Posted April 21, 2022 Author Share Posted April 21, 2022 (edited) Hi @Steel, Mark, I'm still getting the same error message. This is the body that I am passing: { 'stock_movement': { 'stock_item_id': 'exampleID', 'date': '2022-04-21', 'quantity': 1.0, 'cost_price': 0.01, 'details': 'Stock increase for online order' } } It keeps saying A malformed request body was sent to the API. Any ideas? Edited April 21, 2022 by RJ98 Link to comment Share on other sites More sharing options...
Steel, Mark Posted April 25, 2022 Share Posted April 25, 2022 The above looks to be invalid JSON, could you try replacing the single speech marks ' with doubles " please. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now