Fetch Order ID Pyhton Help!

Can some Python expert help with this? Trying to fetch the order ID from Placed Order Response but unable to fetch Order_Id from the Python Dictionary.

Code:
try:
# Place order
PlaceOrderId = api_instance.place_order(body, api_version)
print(PlaceOrderId)
PlaceOrderId = PlaceOrderId[‘data’]
print(PlaceOrderId)
PlaceOrderId = PlaceOrderId[‘order_id’]
print(PlaceOrderId)
except ApiException as e:
print(“Exception when calling OrderApi->place_order: %s\n” % e)

Error:
{‘data’: {‘order_id’: ‘230924000001245’}, ‘status’: ‘success’}
Traceback (most recent call last):
File “C:\Users\umava\PycharmProjects\KiteConnect\Upstox_Soum_V2_Testing.py”, line 71, in
PlaceOrderId = PlaceOrderId[‘data’]
~~~~~~~~~~~~^^^^^^^^
TypeError: ‘PlaceOrderResponse’ object is not subscriptable

Process finished with exit code 1

Use dot notations on the api_response: placeorderid.data.order_id

@Sheoran, Thanks for answering :+1:

@Rohit_K.A let us know if this works for you.

Thank you! This worked!

You can use below code to fetch order id details

def get_order_details():
url = ‘https://api-v2.upstox.com/order/history
headers = {
‘accept’: ‘application/json’,
‘Api-Version’: ‘2.0’,
‘Authorization’: f’Bearer {upstox_access_token}',
}
params = {
‘order_id’: ‘order_id’,
}
response = requests.get(url, params=params, headers=headers)

        response = requests.post(url, headers=headers, json=json_data)
        response = response.json()
        print(response)
        if response["status"] == "success":
            response_message = response['data']['order_id']