Trouble updating a catalog object

Hey,

I’m just getting started with Square’s API.

I followed a guide and was able to create an API Catalog object.

Now I want to update it. It’s failing but returning the error None.

Here’s my code snippet (Python) for updating:

First I obtain the vars from the previously created object:

obj_id = result.body['catalog_object']['id']
slot_1_id = result.body['catalog_object']['item_data']['variations'][0]['id']

Then I just call upsert_catalog_object again

update = client.catalog.upsert_catalog_object(
    body={
        "idempotency_key": f"{UNIQUE_KEY}a",
        "object": {
            "type": "ITEM_VARIATION",
            "id": f"{slot_1_id}",
            "item_variation_data": {
                "item_id": f"{obj_id}",
                "pricing_type": "FIXED_PRICING",
                "price_money": {
                    "amount": 1000,
                    "currency": "USD"
                }
            }
        }
    }
)

Finally, I check the results with:

if update.is_success():
    print("\n\nUpdate Success!\n\n")
    print(update.body)
elif update.is_error():
    print("\n\nUpdate Error!\n\n")
    print(result.body)
    print(result.errors)

Additional question:

Does my idempotency_key have to be unique on updates? (I’m thinking yes so I append the letter ‘a’ to the same key I used to create the catalog object initially)

I think my problem was that I wasn’t including the version; and when I was including the version, I was turning it into a string.

Here’s my working code:

# Vars
obj_id = result.body['catalog_object']['id']
slot_1_id = result.body['catalog_object']['item_data']['variations'][0]['id']
slot_1_version = result.body['catalog_object']['item_data']['variations'][0]['version']

# Update
update = client.catalog.upsert_catalog_object(
    body={
        "idempotency_key": UNIQUE_KEY + "a",
        "object": {
            "type": "ITEM_VARIATION",
            "id": slot_1_id,
            "version": slot_1_version,
            "item_variation_data": {
                "item_id": obj_id,
                "name": "Variation 1",
                "pricing_type": "FIXED_PRICING",
                "price_money": {
                    "amount": 1000,
                    "currency": "USD"
                }
            }
        }
    }
)

I pretty much removed all quotes around everything, as well as included the version.

Glad to see you figured it out! Thanks for sharing your results. :slightly_smiling_face:

There was a second part to that email.

Is there support for generating a unique link to a specific product? (Through the api)

  • Austin

Do you want this link to be reusable or one time use? If you’re looking for reusable you’ll want to use Checkout links. They unfortunately can’t be made via API at this time.

If you’re looking for a one time use link you can use CreatePaymentLink. :slightly_smiling_face:

Bryan,

Oh, sorry. I got confused with this post and a support email I sent. (I replied to an email and was surprised to see it pop up here!)

I would like the link to be reusable until paid or expired. I managed to set an expiration date on an object through the API, so that’s done.

I’ll review the sources you sent before asking anything else. Thanks!

  • Austin