def main() -> None: parser = argparse.ArgumentParser(description=""" # Clear drone required actions via the Ware GraphQL API # To use this tool you must define 2 environment variables (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY). # You can get these values from your Ware service representative. # """) parser.add_argument('--required-action-id', help='The required action id to clear', required=True) parser.add_argument("--endpoint", type=str, help="Optional endpoint value to override the default", default=DEFAULT_HOST) args = parser.parse_args() api = WareAPI(host=args.endpoint) result = api.reset_required_action(args.required_action_id) if result['status'] != SUCCESS_STATUS: return result print(f'Required action {args.required_action_id} cleared')
def main() -> None: parser = argparse.ArgumentParser(description=""" # Interact with the Ware GraphQL API # To use this tool you must define 2 environment variables (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY). # You can get these values from your Ware service representative. # """) parser.add_argument("--endpoint", type=str, help="Optional endpoint value to override the default", default=DEFAULT_HOST) args = parser.parse_args() api = WareAPI(host=args.endpoint) # Use JSON format string for the query. It does not need reformatting. my_info_result = api.my_info() if my_info_result["status"] != "success": print( f"Error calling myInfo: {my_info_result['message']}.\n" "Ensure proper AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are set and " "configured properly in the Ware portal") return # Print the output to the console. print(json.dumps(my_info_result["data"], indent=3))
def main() -> None: parser = argparse.ArgumentParser(description=""" # Interact with the Ware GraphQL API # To use this tool you must define 2 environment variables (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY). # You can get these values from your Ware service representative. # """) parser.add_argument("--endpoint", type=str, help="Optional endpoint value to override the default", default=DEFAULT_HOST) parser.add_argument("id", help="LocationScanOrder UUID") args = parser.parse_args() try: lso_id = uuid.UUID(f'urn:uuid:{args.id}') except TypeError: print(f'Invalid id: {args.id}') exit(1) api = WareAPI(host=args.endpoint) response = api.get_location_scan_order(str(lso_id)) print(json.dumps(response, indent=2))
def main() -> None: parser = argparse.ArgumentParser(description=""" # Interact with the Ware GraphQL API # To use this tool you must define 2 environment variables (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY). # You can get these values from your Ware service representative. # """) parser.add_argument("--endpoint", type=str, help="Optional endpoint value to override the default", default=DEFAULT_HOST) parser.add_argument("--zone_id", type=str, help="Zone ID that the query pertains to") args = parser.parse_args() api = WareAPI(host=args.endpoint) # Use JSON format string for the query. It does not need reformatting. try: # zone_id should be a valid UUID4 zone_uuid = uuid.UUID(f"urn:uuid:{args.zone_id}") page = 0 more_data = True cursor = None while more_data: zone_locations_result = api.zone_locations_page( zone_id=str(zone_uuid), page=page, cursor=cursor) if zone_locations_result["status"] != "success": print( f"Error calling zoneLocationsPage: {zone_locations_result['message']}." ) break zone_locations_data = zone_locations_result["data"] for record in zone_locations_data["records"]: bin_lpns = [] for lpn in record["record"]["inventory"]: bin_lpns.append(lpn["lpn"]) print(f"Bin: {record['record']['binName']} - LPNs: {bin_lpns}") if zone_locations_data["pageInfo"]["hasNextPage"]: # Ware API uses cursors for paging. To advance the page, pass the "endCursor" to subsequent calls # as the starting cursor. cursor = zone_locations_data["pageInfo"]["endCursor"] page += 1 else: more_data = False except TypeError as e: print("Invalid zone_id returned")
def main() -> None: global api parser = argparse.ArgumentParser( description=""" # Upload a WMS data file to the Ware GraphQL API # To use this tool you must define 2 environment variables (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY). # You can get these values from your Ware service representative. # """ ) parser.add_argument( "--endpoint", type=str, help="Optional endpoint value to override the default", default=DEFAULT_HOST ) parser.add_argument("--zone_id", type=str, help="Zone ID that the upload pertains to") parser.add_argument("--file", type=str, help="Source file name") parser.add_argument("--status_check", type=str, default="subscribe") args = parser.parse_args() try: # zone_id should be a valid UUID4 zone_uuid = uuid.UUID(f"urn:uuid:{args.zone_id}") except TypeError as e: print("Invalid zone_id specified") api = WareAPI(host=args.endpoint) # Prepare a file upload request file_format = "CSV" if args.file.lower().endswith("xlsx"): file_format = "XLSX" create_wms_upload_result = api.create_wms_location_history_upload(zone_id=args.zone_id, file_format=file_format) print(create_wms_upload_result) if create_wms_upload_result["status"] != "success": print(f"Error calling createWMSLocationHistoryUpload: {create_wms_upload_result['message']}.") return with open(args.file, "rb") as f: files = {"file": (args.file, f)} fields_dict = json.loads(create_wms_upload_result["data"]["uploadFields"]) http_response = requests.post(create_wms_upload_result["data"]["uploadUrl"], data=fields_dict, files=files) # If successful, returns HTTP status code 204 print(f"File upload HTTP status code: {http_response.status_code}") if args.status_check == "poll": # Now we can poll for status using the wmsLocationHistoryUploadRecord endpoint result = api.wms_location_history_upload_record(create_wms_upload_result["data"]["id"]) print(result) while result["status"] == "success" and result["data"]["status"] not in ["SUCCESS", "FAILURE"]: sleep(1) result = api.wms_location_history_upload_record(create_wms_upload_result["data"]["id"]) print(result) elif args.status_check == "subscribe": # Use the GraphQL subscribe mechanism to wait for updates # The following call will block and wait on the websocket used for the subscription. # Any data received will be handled by the handler function that is passed in api.subscribe_wms_location_history_upload_status_change( create_wms_upload_result["data"]["id"], data_handler=wms_upload_subscription_data_handler )
def main() -> None: global api parser = argparse.ArgumentParser( description=""" # Upload a WMS data chunk to the Ware GraphQL API. The data chunk in this example will be read from a file. # To use this tool you must define 2 environment variables (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY). # You can get these values from your Ware service representative. # """ ) parser.add_argument( "--endpoint", type=str, help="Optional endpoint value to override the default", default=DEFAULT_HOST ) parser.add_argument("--zone_id", type=str, help="Zone ID that the upload pertains to") parser.add_argument("--file", type=str, help="Source file name with JSON payload") args = parser.parse_args() try: # zone_id should be a valid UUID4 zone_uuid = uuid.UUID(f"urn:uuid:{args.zone_id}") except TypeError as e: print("Invalid zone_id specified") api = WareAPI(host=args.endpoint) # Load properly formatted JSON with WMS data from the input file with open(args.file, "rb") as f: json_from_file = json.load(f) create_wms_upload_result = api.create_wms_location_history_records(zone_id=args.zone_id, data=json_from_file) print(create_wms_upload_result) if create_wms_upload_result["status"] != "success": print(f"Error calling createWMSLocationHistoryRecords: {create_wms_upload_result['message']}.") return # Now we can poll for status using the wmsLocationHistoryUploadRecord endpoint result = api.wms_location_history_upload_record(create_wms_upload_result["data"]["id"]) print(result) while result["status"] == "success" and result["data"]["status"] not in ["SUCCESS", "FAILURE"]: sleep(1) result = api.wms_location_history_upload_record(create_wms_upload_result["data"]["id"]) print(result)
def main() -> None: parser = argparse.ArgumentParser( description=""" # Interact with the Ware GraphQL API # To use this tool you must define 2 environment variables (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY). # You can get these values from your Ware service representative. # """ ) parser.add_argument( "--endpoint", type=str, help="Optional endpoint value to override the default", default=DEFAULT_HOST ) parser.add_argument("--zone-id", help="Zone ID for the query", required=True, type=uuid.UUID) parser.add_argument("--user-tracking-token", help="Optional user tracking token", default=None) parser.add_argument("--status", help="Optional filter for location scan order status", choices=["ERROR", "SUCCEEDED", "QUEUED", "IN_PROGRESS"], default=None) args = parser.parse_args() api = WareAPI(host=args.endpoint) response = api.get_location_scan_orders(str(args.zone_id), args.user_tracking_token, args.status) print(json.dumps(response, indent=2))
def main() -> None: parser = argparse.ArgumentParser( description=""" # Interact with the Ware GraphQL API # To use this tool you must define 2 environment variables (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY). # You can get these values from your Ware service representative. # """ ) parser.add_argument( "--endpoint", type=str, help="Optional endpoint value to override the default", default=DEFAULT_HOST ) parser.add_argument("--zone-id", help="Zone ID for the query", required=True) parser.add_argument("--user-tracking-token", help="Optional user tracking token", default=None) parser.add_argument("--bins", nargs="+", help="List of bin names to scan") args = parser.parse_args() api = WareAPI(host=args.endpoint) response = api.create_location_scan_order(args.zone_id, args.bins, args.user_tracking_token) print(json.dumps(response, indent=2))