<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>thread Re: Creating an item in the catalog via the API (PHP) in Archived Discussions (Read Only)</title>
    <link>https://community.squareup.com/t5/Archived-Discussions-Read-Only/Creating-an-item-in-the-catalog-via-the-API-PHP/m-p/93806#M40541</link>
    <description>&lt;P&gt;Hey &lt;a href="https://community.squareup.com/t5/user/viewprofilepage/user-id/131327"&gt;@Jonathon&lt;/a&gt;!&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;It looks like you're passing in&amp;nbsp;item_data on the variation object. When it should be item_variation_data.&amp;nbsp;Also you will need a separate id associated to the item_variation _id that is the same format as the item_id, but not identical.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;If you still need help please feel free to reach out to me.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Sep 2018 21:33:22 GMT</pubDate>
    <dc:creator>Chad</dc:creator>
    <dc:date>2018-09-19T21:33:22Z</dc:date>
    <item>
      <title>Creating an item in the catalog via the API (PHP)</title>
      <link>https://community.squareup.com/t5/Archived-Discussions-Read-Only/Creating-an-item-in-the-catalog-via-the-API-PHP/m-p/93516#M40540</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to create items thru the API using the provided PHP SDK, however I'm coming across an issue. When I follow along with the setup guide with its example (&lt;A href="https://docs.connect.squareup.com/products/catalog/setup" target="_blank"&gt;https://docs.connect.squareup.com/products/catalog/setup&lt;/A&gt;), I get the following error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Exception when calling CatalogApi-&amp;gt;batchUpsertCatalogObjects: [HTTP/1.1 400 Bad Request] {"errors":[{"category":"INVALID_REQUEST_ERROR","code":"VALUE_EMPTY","detail":"Field must not be blank","field":"batches[0].objects[0].item_data.variations[0].id"}]}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would be greatly appreciated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the object I am sending&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;pre&amp;gt;SquareConnect\Model\CatalogObjectBatch Object&lt;BR /&gt;(&lt;BR /&gt; [objects:protected] =&amp;gt; Array&lt;BR /&gt; (&lt;BR /&gt; [0] =&amp;gt; SquareConnect\Model\CatalogObject Object&lt;BR /&gt; (&lt;BR /&gt; [type:protected] =&amp;gt; ITEM&lt;BR /&gt; [id:protected] =&amp;gt; #itemID&lt;BR /&gt; [updated_at:protected] =&amp;gt; &lt;BR /&gt; [version:protected] =&amp;gt; &lt;BR /&gt; [is_deleted:protected] =&amp;gt; &lt;BR /&gt; [catalog_v1_ids:protected] =&amp;gt; &lt;BR /&gt; [present_at_all_locations:protected] =&amp;gt; &lt;BR /&gt; [present_at_location_ids:protected] =&amp;gt; &lt;BR /&gt; [absent_at_location_ids:protected] =&amp;gt; &lt;BR /&gt; [item_data:protected] =&amp;gt; SquareConnect\Model\CatalogItem Object&lt;BR /&gt; (&lt;BR /&gt; [name:protected] =&amp;gt; Nintendo Switch - Neon Blue and Red Joy-Con&lt;BR /&gt; [description:protected] =&amp;gt; 045496590093&lt;BR /&gt; [abbreviation:protected] =&amp;gt; &lt;BR /&gt; [label_color:protected] =&amp;gt; &lt;BR /&gt; [available_online:protected] =&amp;gt; &lt;BR /&gt; [available_for_pickup:protected] =&amp;gt; &lt;BR /&gt; [available_electronically:protected] =&amp;gt; &lt;BR /&gt; [category_id:protected] =&amp;gt; &lt;BR /&gt; [tax_ids:protected] =&amp;gt; &lt;BR /&gt; [modifier_list_info:protected] =&amp;gt; &lt;BR /&gt; [image_url:protected] =&amp;gt; &lt;BR /&gt; [variations:protected] =&amp;gt; Array&lt;BR /&gt; (&lt;BR /&gt; [0] =&amp;gt; SquareConnect\Model\CatalogObject Object&lt;BR /&gt; (&lt;BR /&gt; [type:protected] =&amp;gt; ITEM_VARIATION&lt;BR /&gt; [id:protected] =&amp;gt; #itemID&lt;BR /&gt; [updated_at:protected] =&amp;gt; &lt;BR /&gt; [version:protected] =&amp;gt; &lt;BR /&gt; [is_deleted:protected] =&amp;gt; &lt;BR /&gt; [catalog_v1_ids:protected] =&amp;gt; &lt;BR /&gt; [present_at_all_locations:protected] =&amp;gt; &lt;BR /&gt; [present_at_location_ids:protected] =&amp;gt; &lt;BR /&gt; [absent_at_location_ids:protected] =&amp;gt; &lt;BR /&gt; [item_data:protected] =&amp;gt; SquareConnect\Model\CatalogItemVariation Object&lt;BR /&gt; (&lt;BR /&gt; [item_id:protected] =&amp;gt; #itemID&lt;BR /&gt; [name:protected] =&amp;gt; Nintendo Switch - Neon Blue and Red Joy-Con&lt;BR /&gt; [sku:protected] =&amp;gt; &lt;BR /&gt; [upc:protected] =&amp;gt; &lt;BR /&gt; [ordinal:protected] =&amp;gt; &lt;BR /&gt; [pricing_type:protected] =&amp;gt; &lt;BR /&gt; [price_money:protected] =&amp;gt; SquareConnect\Model\Money Object&lt;BR /&gt; (&lt;BR /&gt; [amount:protected] =&amp;gt; 19435&lt;BR /&gt; [currency:protected] =&amp;gt; USD&lt;BR /&gt; )&lt;/P&gt;
&lt;P&gt;[location_overrides:protected] =&amp;gt; &lt;BR /&gt; [track_inventory:protected] =&amp;gt; &lt;BR /&gt; [inventory_alert_type:protected] =&amp;gt; &lt;BR /&gt; [inventory_alert_threshold:protected] =&amp;gt; &lt;BR /&gt; [user_data:protected] =&amp;gt; &lt;BR /&gt; [service_duration:protected] =&amp;gt; &lt;BR /&gt; )&lt;/P&gt;
&lt;P&gt;[category_data:protected] =&amp;gt; &lt;BR /&gt; [item_variation_data:protected] =&amp;gt; &lt;BR /&gt; [tax_data:protected] =&amp;gt; &lt;BR /&gt; [discount_data:protected] =&amp;gt; &lt;BR /&gt; [modifier_list_data:protected] =&amp;gt; &lt;BR /&gt; [modifier_data:protected] =&amp;gt; &lt;BR /&gt; )&lt;/P&gt;
&lt;P&gt;)&lt;/P&gt;
&lt;P&gt;[product_type:protected] =&amp;gt; &lt;BR /&gt; [skip_modifier_screen:protected] =&amp;gt; &lt;BR /&gt; )&lt;/P&gt;
&lt;P&gt;[category_data:protected] =&amp;gt; &lt;BR /&gt; [item_variation_data:protected] =&amp;gt; &lt;BR /&gt; [tax_data:protected] =&amp;gt; &lt;BR /&gt; [discount_data:protected] =&amp;gt; &lt;BR /&gt; [modifier_list_data:protected] =&amp;gt; &lt;BR /&gt; [modifier_data:protected] =&amp;gt; &lt;BR /&gt; )&lt;/P&gt;
&lt;P&gt;)&lt;/P&gt;
&lt;P&gt;)&lt;BR /&gt;&amp;lt;/pre&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And here is the code I'm using&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;$defaultApiConfig = new \SquareConnect\Configuration();&lt;BR /&gt; $defaultApiConfig-&amp;gt;setAccessToken($this-&amp;gt;accessToken);&lt;/P&gt;
&lt;P&gt;$defaultApiClient = new \SquareConnect\ApiClient($defaultApiConfig);&lt;BR /&gt; $catalogApi = new SquareConnect\Api\CatalogApi($defaultApiClient);&lt;BR /&gt; &lt;BR /&gt; $price = new \SquareConnect\Model\Money;&lt;BR /&gt; $price-&amp;gt;setAmount($data["price"] * 100);&lt;BR /&gt; $price-&amp;gt;setCurrency('USD');&lt;BR /&gt; &lt;BR /&gt; $itemData = new \SquareConnect\Model\CatalogItem;&lt;BR /&gt; $itemData-&amp;gt;setName($data["name"]);&lt;BR /&gt; $itemData-&amp;gt;setDescription($data["upc"]);&lt;BR /&gt; &lt;BR /&gt; $item = new \SquareConnect\Model\CatalogObject;&lt;BR /&gt; $item-&amp;gt;setType("ITEM");&lt;BR /&gt; $item-&amp;gt;setId("#itemID");&lt;BR /&gt; &lt;BR /&gt; $varData = new \SquareConnect\Model\CatalogItemVariation;&lt;BR /&gt; $varData-&amp;gt;setName($data["name"]);&lt;BR /&gt; $varData-&amp;gt;setItemId("#itemID");&lt;BR /&gt; $varData-&amp;gt;setPriceMoney($price);&lt;BR /&gt; $varData-&amp;gt;setUpc($data["upc"]);&lt;BR /&gt; $varData-&amp;gt;setSku($data["sku"]);&lt;BR /&gt; &lt;BR /&gt; $var = new \SquareConnect\Model\CatalogObject;&lt;BR /&gt; $var-&amp;gt;setType("ITEM_VARIATION");&lt;BR /&gt; $var-&amp;gt;setItemData($varData);&lt;BR /&gt; &lt;BR /&gt; $itemData-&amp;gt;setVariations(array($var));&lt;BR /&gt; $item-&amp;gt;setItemData($itemData);&lt;BR /&gt; &lt;BR /&gt; $batch = new \SquareConnect\Model\CatalogObjectBatch;&lt;BR /&gt; $batch-&amp;gt;setObjects(array($item));&lt;BR /&gt; &lt;BR /&gt; $body = new \SquareConnect\Model\BatchUpsertCatalogObjectsRequest();&lt;BR /&gt; $body-&amp;gt;setIdempotencyKey(uniqid()); // uniqid() generates a random string.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt; $batches = array($batch);&lt;BR /&gt; $body-&amp;gt;setBatches($batches);&lt;BR /&gt; &lt;BR /&gt; try {&lt;BR /&gt; &lt;BR /&gt; $result = $catalogApi-&amp;gt;batchUpsertCatalogObjects($body);&lt;BR /&gt; echo 'Success!';&lt;BR /&gt; print_r($result);&lt;/P&gt;
&lt;P&gt;} catch (Exception $e) {&lt;BR /&gt; &lt;BR /&gt; echo 'Exception when calling CatalogApi-&amp;gt;batchUpsertCatalogObjects: ', $e-&amp;gt;getMessage(), PHP_EOL;&lt;BR /&gt; &lt;BR /&gt; }&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 21:10:59 GMT</pubDate>
      <guid>https://community.squareup.com/t5/Archived-Discussions-Read-Only/Creating-an-item-in-the-catalog-via-the-API-PHP/m-p/93516#M40540</guid>
      <dc:creator>Jonathon</dc:creator>
      <dc:date>2018-09-17T21:10:59Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an item in the catalog via the API (PHP)</title>
      <link>https://community.squareup.com/t5/Archived-Discussions-Read-Only/Creating-an-item-in-the-catalog-via-the-API-PHP/m-p/93806#M40541</link>
      <description>&lt;P&gt;Hey &lt;a href="https://community.squareup.com/t5/user/viewprofilepage/user-id/131327"&gt;@Jonathon&lt;/a&gt;!&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;It looks like you're passing in&amp;nbsp;item_data on the variation object. When it should be item_variation_data.&amp;nbsp;Also you will need a separate id associated to the item_variation _id that is the same format as the item_id, but not identical.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;If you still need help please feel free to reach out to me.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Sep 2018 21:33:22 GMT</pubDate>
      <guid>https://community.squareup.com/t5/Archived-Discussions-Read-Only/Creating-an-item-in-the-catalog-via-the-API-PHP/m-p/93806#M40541</guid>
      <dc:creator>Chad</dc:creator>
      <dc:date>2018-09-19T21:33:22Z</dc:date>
    </item>
  </channel>
</rss>

