12-11-2024 10:51 PM
This code is resulting in the error below on both SANDBOX and PROD.
2024-12-12 06:36:33,020 - celery_app - INFO - Location data prepared for user 105987699652522530866: {'location': {'address': {'postalCode': '90210', 'country': 'US'}}, 'name': 'W105987699652522530866_1733985393', 'merchantLocationStatus': 'ENABLED', 'locationTypes': ['WAREHOUSE']}
2024-12-12 06:32:45,531 - werkzeug - INFO - 73.222.195.7 - - [12/Dec/2024 06:32:45] "GET /auth/ebay/login HTTP/1.1" 302 -
2024-12-12 06:36:33,219 - celery_app - ERROR - Error creating inventory location: Failed to create inventory location: {"errors":[{"errorId":2004,"domain":"ACCESS","category":"REQUEST","message":"Invalid request","longMessage":"The request has errors. For help, see the documentation for this API."}]}
CODE:
def create_inventory_location(client, user_id, location_data):
try:
# Generate a unique location key
timestamp = int(time.time())
location_key = f"W{user_id}_{timestamp}"[:50]
# Prepare the location data
location_request = {
"location": {
"address": {
"postalCode": location_data.get('postalCode'),
"country": "US"
}
},
"name": location_key,
"merchantLocationStatus": "ENABLED",
"locationTypes": [
"WAREHOUSE"
]
}
current_app.logger.info(f"Location data prepared for user {user_id}: {location_request}")
# Make the API request to create the location
response = client.put(
get_api_endpoint(f'sell/inventory/v1/location/{location_key}'),
json=location_request,
headers={
'Content-Language': 'en-US',
'Content-Type': 'application/json'
}
)
current_app.logger.info(f"Response from eBay API at {get_api_endpoint(f'sell/inventory/v1/location/{location_key}')}: {response.text}")
if response.status_code not in [200, 201, 204]:
current_app.logger.error(f"Failed to create inventory location for user {user_id}: {response.text}")
raise Exception(f"Failed to create inventory location: {response.text}")
return location_key
except Exception as e:
current_app.logger.error(f"Error creating inventory location: {str(e)}")
raise