Shoppy.gg product updating returns true but does not change

12 Views Asked by At

I am trying to update my items stock using the shoppy.gg api but when i try to add a new stocked item it says that its been updated but my new item is not in the stock. Here is my code:

class StoreAPI:
    API_KEY = "apikeyhere"
    headers = {"Authorization": API_KEY, "Content-type": "application/json", "Connection": "keep-alive"}

    product_table = {
        "test": "product_id_here"
    }

    def __init__(self):
        self.session = requests.session()
    
    def update_stock(self, product, stock_item):
        product_prefix = self.product_table.get(product, None)
        if not product_prefix:
            return False
        
        listing_info = self.session.get(f"https://shoppy.gg/api/v1/products/{product_prefix}", headers=self.headers).json()
        new_stock_payload = {"id": listing_info["id"], "model": "Product", "title": listing_info["title"], "description": listing_info["description"], "unlisted": False, "type": "account", "gateways": listing_info["gateways"], "price": int(listing_info["price"]), "confirmations": int(listing_info["confirmations"]), "email": listing_info["email"], "custom_fields": listing_info["custom_fields"],"webhook_urls": listing_info["webhook_urls"],"accounts": [account['account'] for account in listing_info['accounts']] + [stock_item], "quantity": listing_info["quantity"], "stock_warning": listing_info["stock_warning"], "attachment_id": listing_info["attachment_id"], "image": listing_info["image"], "currency": listing_info["currency"], "dynamic_url": listing_info["dynamic_url"],"position": listing_info["position"], "created_at": listing_info["created_at"], "updated_at": str(datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M:%S.000000Z')), "seller": listing_info["seller"],"stock": int(listing_info["stock"])}
        
        new_stock_info = self.session.post(f"https://shoppy.gg/api/v1/products/{product_prefix}", headers=self.headers, data=new_stock_payload).json()
        if new_stock_info.get("status", False):
            return True
        
        return False

the shoppy payload is like this:

{"id":"product_id_here","model":"Product","title":"test","description":"descc","unlisted":false,"type":"account","gateways":["Litecoin","Stripe"],"price":1,"confirmations":3,"email":{"enabled":false},"custom_fields":[],"webhook_urls":[],"accounts":["looooooooool\r","test3a\r","test2"],"quantity":{"min":1,"max":1000000},"stock_warning":0,"attachment_id":null,"image":null,"currency":"EUR","dynamic_url":"","position":null,"created_at":"2024-03-24T15:11:47.000000Z","updated_at":"2024-03-24T15:47:06.000000Z","seller":"sellername","stock":"3"}

my payload looks like this:

{'id': 'product_id_here', 'model': 'Product', 'title': 'test', 'description': 'descc', 'unlisted': False, 'type': 'account', 'gateways': ['Litecoin', 'Stripe'], 'price': 1, 'confirmations': 3, 'email': {'enabled': False}, 'custom_fields': [], 'webhook_urls': [], 'accounts': ['test2', 'test3a', 'looooooooool', 'newly_added_stock'], 'quantity': {'min': 1, 'max': 1000000}, 'stock_warning': 0, 'attachment_id': None, 'image': None, 'currency': 'EUR', 'dynamic_url': '', 'position': None, 'created_at': '2024-03-24T15:11:47.000000Z', 'updated_at': '2024-03-24T16:03:37.000000Z', 'seller': 'sellername', 'stock': 3}

could anyone help me out what im doing wrong because i dont see any difference in the payloads

I tried changing the updated_at but that looks fine and i could not come up to anything else

0

There are 0 best solutions below