Failed to update draft order. Status code: 400

I get some draft orders with incomplete addresses and I am trying o update them but everything I tried failed to work. Now I am passing the exact same draft order json and yet it continues to give me the same error,

Response: {"errors":{"draft_order":"Required parameter missing or invalid"}}

All access scopes have been allowed. I use this same code for my partner test store, and it works, but I need some help here.


Hi @safwanadnan

There is an issue with the parameters. Please send your request parameters for processing.

This is my code, works fine for my test store but the actual store it returns an error

import requests
import json

Define the API endpoints and access credentials

store_url = “”
access_token = “”
draft_orders_endpoint = “/admin/api/2024-07/draft_orders.json?limit=1”
update_endpoint_template = “/admin/api/2024-07/draft_orders/{draft_order_id}.json”

Set up the headers with the access token

headers = {
“X-Shopify-Access-Token”: access_token,
“Content-Type”: “application/json”
}

Function to fetch draft orders

def fetch_draft_orders():
url = f"{store_url}{draft_orders_endpoint}"
response = requests.get(url, headers=headers)
if response.status_code == 200:
return response.json()
else:
print(f"Failed to fetch draft orders. Status code: {response.status_code}")
print(“Response:”, response.text)
return None

Function to update draft order note attributes

def update_draft_order(draft_order):
draft_order_id = draft_order.get(‘id’)
update_url = f"{store_url}{update_endpoint_template.format(draft_order_id=draft_order_id)}"
data = {
“draft_order”: draft_order
}
response = requests.put(update_url, headers=headers, json=data)
if response.status_code == 200:
print(f"Draft order {draft_order_id} updated successfully.“)
return response.json()
else:
print(f"Failed to update draft order {draft_order_id}. Status code: {response.status_code}”)
print(“Response:”, response.text)
return None

Fetch the draft orders

draft_orders_data = fetch_draft_orders()

if draft_orders_data:
draft_orders = draft_orders_data.get(‘draft_orders’, )
if draft_orders:
first_draft_order = draft_orders[0]

Update the draft order with the same note attributes

updated_draft_order = update_draft_order(first_draft_order)
if updated_draft_order:
print(“Updated Draft Order:”, updated_draft_order)
else:
print(“No draft orders found.”)
else:
print(“Failed to retrieve draft orders.”)

Hi @safwanadnan

I need to request parameters, such as the following code:

{
"draft_order":{
"id":"123198237",
"line_items":[{"variant_id":447654529,"quantity":1}]
}
}

That’s what I’m saying, I fetched the entire order and first replaced the address in the order with itself just for testing purposes so that nothing is actually changed, it threw the same error, so I passed the entire order json as parameter to see if something is missing maybe that works but no same error persists. Funny thing is that both versions of codes worked perfectly fine with ny test store but the actual store e throws an error.

As you can see in the code I fetched a draft order, parsed it’s contents and then passed that exact same json which contained the contents but it says error.