Hello guys, due to my poor knowledge of javascript I have decided to implement my own API wrapper in python I have managed to post a listing and upload a photo but when I tried to set a status of a photo from ‘pending’ to ‘active’ using the above code
patch = {
'op': 'replace',
'path': '/photo/' + photo_listing['data']['id'] + '/status',
'value': 'active'
}
print("listing_id:" + listing['data']['id'])
print("photo_id:" + photo_listing['data']['id'])
try:
auth = 'GFAPI ' + GFAPI_KEY + ':' + pyotp.TOTP('secret_key').now()
pat = requests.patch(BASE_URL.production.value + '/' + 'listing/' + listing['data']['id'], data=patch, headers={"Authorization":auth, "Content-Type": "application/json-patch+json"})
print(requests.get(BASE_URL.production.value + '/' + 'listing/' + listing['data']['id'], headers={"Authorization":auth}).json())
pat.raise_for_status()
except HTTPError as http_err:
print(f'HTTP error occurred: {http_err}') # Python 3.6
except Exception as err:
print(f'Other error occurred: {err}') # Python 3.6
else:
print('Success!')
but I am taking the following error:
HTTP error occurred: 400 Client Error: Bad Request for url: https://production-gameflip.fingershock.com/api/v1/listing/listing_id
Any clues?
Did you paste that error message verbatim?
Why is the url
https://production-gameflip.fingershock.com/api/v1/listing/listing_id
instead of for example
https://production-gameflip.fingershock.com/api/v1/listing/63247af4-aa4a-47db-a8e3-c1d94577c22d
with an actual ID?
No I have replaced uuid string with <listing_id> for obvious reasons
The patch data has to be an array of patch objects.
Please read the sample code:
digital: true,
digital_region: 'none',
digital_deliverable: 'transfer',
shipping_predefined_package: 'None',
shipping_fee: 0,
shipping_paid_by: 'seller',
};
let listing = await gfapi.listing_post(query);
// Upload an image to show in the listing page
gfapi.upload_photo(listing.id, photo_url, 0).then(() => {
// Upload another image to show in the search results
return gfapi.upload_photo(listing.id, photo_url);
// If you want to add a second image in the listing page then uncomment the two lines below:
// }).then(() => {
// return gfapi.upload_photo(listing.id, second_photo_url, 1);
}).then(() => {
// List the listing for sale
return gfapi.listing_status(listing.id, GfApi.LISTING_STATUS.ONSALE);
}).catch(err => {
// Upload the image
let upload_req = await Request.put({
url: photo_obj.upload_url,
body: photo_blob,
headers: {
"Content-Type": image_type
}
});
// Update the listing with the new image
let patch = [{
op: CONST.LISTING_OPS.REPLACE,
path: '/photo/' + photo_obj.id + '/status',
value: CONST.LISTING_PHOTO_STATUS.ACTIVE
}];
let order_patch = display_order >= 0 ? {
op: CONST.LISTING_OPS.REPLACE,
path: '/photo/' + photo_obj.id + '/display_order',
value: display_order
} : {
op: CONST.LISTING_OPS.REPLACE,
upload_photo
patch array has two patch operations in it.
Yes! Right!
patch must be an array and the request must send the array as json.dumps(patch_array)
patch = [{
'op': 'replace',
'path': '/photo/' + photo_listing['data']['id'] + '/status',
'value': 'active'
}]
print("listing_id:" + listing['data']['id'])
print("photo_id:" + photo_listing['data']['id'])
try:
auth = 'GFAPI ' + GFAPI_KEY + ':' + pyotp.TOTP('secret_key').now()
pat = requests.patch(BASE_URL.production.value + '/' + 'listing/' + listing['data']['id'], data=json.dumps(patch), headers={"Authorization":auth, "Content-Type": "application/json-patch+json"})
print(requests.get(BASE_URL.production.value + '/' + 'listing/' + listing['data']['id'], headers={"Authorization":auth}).json())
pat.raise_for_status()
except HTTPError as http_err:
print(f'HTTP error occurred: {http_err}') # Python 3.6
except Exception as err:
print(f'Other error occurred: {err}') # Python 3.6
else:
print('Success!')