Hello - quick question about the Team API. I want to create a new category using a Catalog API endpoint… But as of now, I can’t find any Catalog API endpoint for creating a new category. Is this something that can be done? I’ve looked through the API and I don’t see this option - maybe I’m missing something?
Yes, you can create a new catalog category with the API. You’ll use the same endpoints you use to create items except you’ll be creating a category. For example:
{
"idempotency_key": "9d09f89b-da58-496c-bdb3-3a639277d15d",
"object": {
"type": "CATEGORY",
"category_data": {
"name": "My new category"
},
"id": "#newcatagory"
}
}
Hi Bryan,
Thanks for this info - I’m working in php and example of creating an item starts as:
$body_idempotencyKey = 'af3d1afc-7212-4300-b463-0bfc5314a5ae';
$body_object_type = Models\CatalogObjectType::ITEM;
$body_object_id = '#Cocoa';
$body_object = new Models\CatalogObject(
$body_object_type,
$body_object_id
);
$body_object->setItemData(new Models\CatalogItem());
$body_object->getItemData()->setName('Cocoa');
...
Can I assume that we change
Models\CatalogObjectType::ITEM
to
Models\CatalogObjectType::CATEGORY
and
new Models\CatalogItem())
to
new Models\CatalogCategory())
johnh…
Basically, yes. You’ll change the ObjectType
to CATEGORY
and add CategoryData
. Similar to this:
$category_data = new \Square\Models\CatalogCategory();
$category_data->setName('soda');
$object = new \Square\Models\CatalogObject('CATEGORY', '#soda');
$object->setCategoryData($category_data);
$body = new \Square\Models\UpsertCatalogObjectRequest('cacba125-ef80-4847-8907-50c31f414e4b', $object);
$api_response = $client->getCatalogApi()->upsertCatalogObject($body);
if ($api_response->isSuccess()) {
$result = $api_response->getResult();
} else {
$errors = $api_response->getErrors();
}