Jump to content

Malformed API request for stock items endpoint


 Share

Recommended Posts

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

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

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 by RJ98
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...