srilakshu012456 commited on
Commit
e73c9c1
·
verified ·
1 Parent(s): 7203369

Create public_api_location.py

Browse files
Files changed (1) hide show
  1. public_api/public_api_location.py +45 -0
public_api/public_api_location.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from public_api.public_api_auth import login
3
+
4
+ def get_location_status(session_data, warehouse_id, stoloc):
5
+ url = "http://euwdsw202em01:4660/api/inventory/v1/locationStatus"
6
+ session = session_data["wms_auth"]
7
+
8
+ # Pass everything from kwargs directly to the API
9
+ params = {
10
+ "stoloc":stoloc
11
+ }
12
+
13
+ headers = {
14
+ "accept": "application/json",
15
+ "Content-Type": "application/json"
16
+ }
17
+
18
+ try:
19
+ response = session.get(url, params=params, headers=headers, verify=False)
20
+
21
+ # Standardized 401 Session Recovery
22
+ if response.status_code == 401:
23
+ print("Session expired. Re-logging in...")
24
+ new_session, new_wh, success = login()
25
+ if success:
26
+ session_data["wms_auth"] = new_session
27
+ session_data["user_warehouse_id"] = new_wh
28
+ response = new_session.get(url, params=params, headers=headers, verify=False)
29
+
30
+ # SUCCESS: Return data and the status code for main.py to inspect
31
+ if response.status_code == 200:
32
+ try:
33
+ res_json = response.json()
34
+ all_data = res_json.get("data", [])
35
+
36
+ return {"data": all_data, "error": None, "status_code": 200}
37
+ except ValueError:
38
+ return {"data": [], "error": "Invalid JSON format", "status_code": 200}
39
+
40
+ print(f"Location API response code: {response.status_code}\n{response.text}")
41
+ return {"data": [], "error": f"Location API Error: {response.text}"}
42
+
43
+ except Exception as e:
44
+ print(f"Location API exception: {e}")
45
+ return {"data": [], "error": f"Location API Connection failed: {str(e)}"}