cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Unable to register products in sandbox environment

I'm using a translation site so I apologize if there are any grammatical errors.

 

I'm currently creating an application that uses Python to operate the eBay API.

I'm trying to register a test product in the SandBox environment to implement a function to delete products with a specified SKU, but it's not working.

 

Please let me know what I need to fix.

 

・Implementation with cURL
curl -X POST -i 'https://api.sandbox.ebay.com/sell/inventory/v1/inventory_item/TEST001' -H 'Accept: application/json' -H 'Accept-language: en-US' -H 'Content-type: application/json' -H 'Content-language: en-US' -H 'Authorization: Bearer v***' -d '{"availability": {"shipToLocationAvailability": {"quantity": 50}}, "condition": "NEW", "product": {"title": "GoPro Hero4 Helmet Cam", "description": "New GoPro Hero4 Helmet Cam. Unopened box.", "aspects": {"Brand": ["GoPro"], "Type": ["Helmet/Action"], "Storage Type": ["Removable"], "Recording Definition": ["High Definition"], "Media Format": ["Flash Drive (SSD)"], "Optical Zoom": ["10x"]}, "brand": "GoPro", "mpn": "CHDHX-401"}}'

 

・Implementation in Python
req_header = {

   "Accept": "application/json",
   "Accept-Language": "en-US",
   "Authorization": "Bearer " + aToken,
   "Content-Type": "application/json",
   "Content-Language": "en-US",
}

req_data = {
   "availability": {
      "shipToLocationAvailability": {
         "quantity": 50
      }
   },
   "condition": "NEW",
   "product": {
      "title": "GoPro Hero4 Helmet Cam",

      "description": "New GoPro Hero4 Helmet Cam. Unopened box.",

      "aspects": {

         "Brand": ["GoPro"],

         "Type": ["Helmet/Action"],

         "Storage Type": ["Removable"],

         "Recording Definition": ["High Definition"],

         "Media Format": ["Flash Drive (SSD)"],

         "Optical Zoom": ["10x"]

      },

      "brand": "GoPro",

      "mpn": "CHDHX-401"

   }

}

 

req = urllib.request.Request(inventory_url_sandbox + SKU, data=json.dumps(req_data).encode("utf-8"), headers=req_header)

 

response = None

 

try:
   response = urllib.request.urlopen(req).read()
except Exception as e:
   print(e)

 

・Error message
400 Bad Request
{"errors":[{"errorId":2004,"domain":"ACCESS","category":"REQUEST","message":"Invalid request","longMessage":"The request has errors. For help, see the documentation for this API."}]}

Message 1 of 2
latest reply
1 REPLY 1

Unable to register products in sandbox environment

I managed to solve the problem of creating items by using API Explorer, but when I tried to "reduce the number of products" using the command below, which is what I originally wanted to do, I got a 400 error.
 
It works fine in API Explorer, so where is the problem?
 
Is it a problem specific to the sandbox?
 
#cURL command
-H 'Accept: application/json' \
-H 'Content-language: en-US' \
-H 'Content-type: application/json' \
-H 'Authorization: Bearer *****' \
-d '{ "availability": { "shipToLocationAvailability": { "quantity": 1000 } } }'
 
#python code
def ReduceQuantityToZero(aToken, SKU, isSandBox):
 
#Variable declaration (common for eBay connection)
req_header = {
"Accept": "application/json",
"Authorization": "Bearer " + aToken,
"Content-Type": "application/json",
"Content-Language": "en-US",
}
 
req_data = json.dumps({
"availability": {
"shipToLocationAvailability": {
"quantity": 0
}
}
})
 
if isSandBox:
req = urllib.request.Request(inventory_url_sandbox + SKU, data=req_data.encode(), headers=req_header, method="POST")
else:
req = urllib.request.Request(inventory_url + SKU, data=req_data.encode(), headers=req_header, method="POST")
 
response = None
 
try:
with urllib.request.urlopen(req) as rq:
response = rq.getcode()
 
except Exception as e:
if e.code != None:
response = e.code
print(e)
 
Finally:
return response
Message 2 of 2
latest reply