[Skip to main content](#vessel-content)

#   API advice on creating digital product

##

- **[boxcarmib](/forum/user/39131-boxcarmib "View boxcarmib's Profile")**
- [![boxcarmib's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/39131-boxcarmib "View boxcarmib's Profile") Topic Author
- [ Offline](/forum/user/39131-boxcarmib)

Less More

- Posts: 13
- Thank you received: 0
-
-

9 years 11 months ago [\#256834](#256834) by [boxcarmib](/forum/user/39131-boxcarmib "View boxcarmib's Profile")  *[API advice on creating digital product](/forum/26-product-category-display/887780-api-advice-on-creating-digital-product#256834 "-- HikaShop version -- : 2.6.4 -- Joomla version -- : 3.6.4  So looking through the forum and reading the API docs, I think I understand how to create a new product with the API. Here's my code...  $price = new stdClass(); $price-&gt;price&#95;value = 99.99; $price-&gt;price&#95;currency&#95;id = 1; $price-&gt;price&#95;price&#95;min&#95;quantity = 0;  $product = new stdClass(); $product-&gt;product&#95;name ='fileA'; $product-&gt;product&#95;quantity = -1; $product-&gt;product&#95;published = 1; $product-&gt;product&#95;weight = 0; $product-&gt;product&#95;type = &quot;main&quot;; $product-&gt;product&#95;msrp = 4.99; $product-&gt;product&#95;access = &quot;all&quot;; $product-&gt;prices = &#91;$price&#93;; $product-&gt;categories = &#91;1&#93;;  $productClass = hikashop&#95;get('class.product'); $productId = $productClass-&gt;save($product);  $productClass-&gt;updateCategories($product,$productId);  So while a new product is created (I can see it in the database), it is not displayed in the back end hikashop products listing. Also I note that there is a table &quot;hikashop&#95;file&quot; that gets stuffed with some digital download info. Is there some API i should be calling to update that database table as well? Please tell me what I'm doing wrong.")* was created by *[boxcarmib](/forum/user/39131-boxcarmib "View boxcarmib's Profile")*

-- HikaShop version -- : 2.6.4
-- Joomla version -- : 3.6.4

So looking through the forum and reading the API docs, I think I understand how to create a new product with the API. Here's my code...

$price = new stdClass();
$price-&gt;price_value = 99.99;
$price-&gt;price_currency_id = 1;
$price-&gt;price_price_min_quantity = 0;

$product = new stdClass();
$product-&gt;product_name ='fileA';
$product-&gt;product_quantity = -1;
$product-&gt;product_published = 1;
$product-&gt;product_weight = 0;
$product-&gt;product_type = "main";
$product-&gt;product_msrp = 4.99;
$product-&gt;product_access = "all";
$product-&gt;prices = [$price];
$product-&gt;categories = [1];

$productClass = hikashop_get('class.product');
$productId = $productClass-&gt;save($product);

$productClass-&gt;updateCategories($product,$productId);

So while a new product is created (I can see it in the database), it is not displayed in the back end hikashop products listing. Also I note that there is a table "hikashop_file" that gets stuffed with some digital download info. Is there some API i should be calling to update that database table as well? Please tell me what I'm doing wrong.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84ODc3ODAtYXBpLWFkdmljZS1vbi1jcmVhdGluZy1kaWdpdGFsLXByb2R1Y3Q/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86564
- Thank you received: 14311
-
-

9 years 11 months ago [\#256843](#256843) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[API advice on creating digital product](/forum/26-product-category-display/887780-api-advice-on-creating-digital-product#256843 "-- HikaShop version -- : 2.6.4 -- Joomla version -- : 3.6.4  So looking through the forum and reading the API docs, I think I understand how to create a new product with the API. Here's my code...  $price = new stdClass(); $price-&gt;price&#95;value = 99.99; $price-&gt;price&#95;currency&#95;id = 1; $price-&gt;price&#95;price&#95;min&#95;quantity = 0;  $product = new stdClass(); $product-&gt;product&#95;name ='fileA'; $product-&gt;product&#95;quantity = -1; $product-&gt;product&#95;published = 1; $product-&gt;product&#95;weight = 0; $product-&gt;product&#95;type = &quot;main&quot;; $product-&gt;product&#95;msrp = 4.99; $product-&gt;product&#95;access = &quot;all&quot;; $product-&gt;prices = &#91;$price&#93;; $product-&gt;categories = &#91;1&#93;;  $productClass = hikashop&#95;get('class.product'); $productId = $productClass-&gt;save($product);  $productClass-&gt;updateCategories($product,$productId);  So while a new product is created (I can see it in the database), it is not displayed in the back end hikashop products listing. Also I note that there is a table &quot;hikashop&#95;file&quot; that gets stuffed with some digital download info. Is there some API i should be calling to update that database table as well? Please tell me what I'm doing wrong.")*

Hi,

The fact that you see the product in the database but not in the backend indicates that there is a problem with the link between the category and the product.
For example, if the product is not added to a category, or is added to a non existent one, it won't display in the backend.

In your case, I guess that the problem comes from the line: Code:

$product-&gt;categories = [1];

You use the category_id 1 which is the root category id. And when you arrive on the products listing in your backend, you're in the "product categories" category, so you're already under the root category and thus it's normal that you don't see the products directly under the root category.
You should use another id, like "2" which is the id of the "product categories" category, if you didn't modify your category tree structure too much.

For the files, you can do like that: Code:

// add file entry to the hikashop_file table $file = new stdClass(); $file-&gt;file_path = 'myfilename.jpg'; // make sure that your file is in the safe upload folder of HikaShop $file-&gt;file_type= 'file'; $fileClass = hikashop_get('class.file'); $file_id = $fileClass-&gt;save($file); $product-&gt;files= array($file_id); $productClass-&gt;updateFiles($product,$productId,'files');

It's roughly the same process for product images.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84ODc3ODAtYXBpLWFkdmljZS1vbi1jcmVhdGluZy1kaWdpdGFsLXByb2R1Y3Q/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[boxcarmib](/forum/user/39131-boxcarmib "View boxcarmib's Profile")**
- [![boxcarmib's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/39131-boxcarmib "View boxcarmib's Profile") Topic Author
- [ Offline](/forum/user/39131-boxcarmib)

Less More

- Posts: 13
- Thank you received: 0
-
-

9 years 11 months ago [\#256950](#256950) by [boxcarmib](/forum/user/39131-boxcarmib "View boxcarmib's Profile")  Replied by *[boxcarmib](/forum/user/39131-boxcarmib "View boxcarmib's Profile")* on topic *[API advice on creating digital product](/forum/26-product-category-display/887780-api-advice-on-creating-digital-product#256950 "-- HikaShop version -- : 2.6.4 -- Joomla version -- : 3.6.4  So looking through the forum and reading the API docs, I think I understand how to create a new product with the API. Here's my code...  $price = new stdClass(); $price-&gt;price&#95;value = 99.99; $price-&gt;price&#95;currency&#95;id = 1; $price-&gt;price&#95;price&#95;min&#95;quantity = 0;  $product = new stdClass(); $product-&gt;product&#95;name ='fileA'; $product-&gt;product&#95;quantity = -1; $product-&gt;product&#95;published = 1; $product-&gt;product&#95;weight = 0; $product-&gt;product&#95;type = &quot;main&quot;; $product-&gt;product&#95;msrp = 4.99; $product-&gt;product&#95;access = &quot;all&quot;; $product-&gt;prices = &#91;$price&#93;; $product-&gt;categories = &#91;1&#93;;  $productClass = hikashop&#95;get('class.product'); $productId = $productClass-&gt;save($product);  $productClass-&gt;updateCategories($product,$productId);  So while a new product is created (I can see it in the database), it is not displayed in the back end hikashop products listing. Also I note that there is a table &quot;hikashop&#95;file&quot; that gets stuffed with some digital download info. Is there some API i should be calling to update that database table as well? Please tell me what I'm doing wrong.")*

Thanks for the great support. I am now successfully adding products through the API. couple of wrinkles remain. Here's a screen shot of a product I have added.
[ ![hika1&#95;2016-12-05.png](/forum/attachment/35032) ](/forum/attachment/35032 "...2016-12-05.png")

I then use the following code to add the product to the customer's cart... but as the attached screen shot shows, the "product name" field is blank. Why is this happening? What am I doing wrong?
[ ![hika2&#95;2016-12-05.png](/forum/attachment/35033) ](/forum/attachment/35033 "...2016-12-05.png")

There's also an "#" column with a live link but when I click on that I get a couple of error messages and the error message... "You are not authorized to see this resource". This seems odd.
[ ![hika3&#95;2016-12-05.png](/forum/attachment/35034) ](/forum/attachment/35034 "...2016-12-05.png")

Would be grateful for your help.

- [ ![hika1&#95;2016-12-05.png](/forum/attachment/35032) ](/forum/attachment/35032 "...2016-12-05.png") [ ](/forum/attachment/35032?download=1 "...2016-12-05.png")
- [ ![hika2&#95;2016-12-05.png](/forum/attachment/35033) ](/forum/attachment/35033 "...2016-12-05.png") [ ](/forum/attachment/35033?download=1 "...2016-12-05.png")
- [ ![hika3&#95;2016-12-05.png](/forum/attachment/35034) ](/forum/attachment/35034 "...2016-12-05.png") [ ](/forum/attachment/35034?download=1 "...2016-12-05.png")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84ODc3ODAtYXBpLWFkdmljZS1vbi1jcmVhdGluZy1kaWdpdGFsLXByb2R1Y3Q/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86564
- Thank you received: 14311
-
-

9 years 11 months ago [\#256955](#256955) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[API advice on creating digital product](/forum/26-product-category-display/887780-api-advice-on-creating-digital-product#256955 "-- HikaShop version -- : 2.6.4 -- Joomla version -- : 3.6.4  So looking through the forum and reading the API docs, I think I understand how to create a new product with the API. Here's my code...  $price = new stdClass(); $price-&gt;price&#95;value = 99.99; $price-&gt;price&#95;currency&#95;id = 1; $price-&gt;price&#95;price&#95;min&#95;quantity = 0;  $product = new stdClass(); $product-&gt;product&#95;name ='fileA'; $product-&gt;product&#95;quantity = -1; $product-&gt;product&#95;published = 1; $product-&gt;product&#95;weight = 0; $product-&gt;product&#95;type = &quot;main&quot;; $product-&gt;product&#95;msrp = 4.99; $product-&gt;product&#95;access = &quot;all&quot;; $product-&gt;prices = &#91;$price&#93;; $product-&gt;categories = &#91;1&#93;;  $productClass = hikashop&#95;get('class.product'); $productId = $productClass-&gt;save($product);  $productClass-&gt;updateCategories($product,$productId);  So while a new product is created (I can see it in the database), it is not displayed in the back end hikashop products listing. Also I note that there is a table &quot;hikashop&#95;file&quot; that gets stuffed with some digital download info. Is there some API i should be calling to update that database table as well? Please tell me what I'm doing wrong.")*

Hi,

The empty name is normal as that's the name of your cart. You can see it in the cart_name column of the hikashop_cart table.
If you fill it in, you'll see it there.
You normally don't need a cart name for your carts since on 99% of websites, you only want one cart per user and thus you have the "multicart" setting turned off in the HikaShop configuration.

The cart page not displaying is probably a bug that we fixed last week. Download again the install package on our website and install it on yours and it should fix that.

The following user(s) said Thank You: [boxcarmib](/forum/user/39131-boxcarmib "View boxcarmib's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84ODc3ODAtYXBpLWFkdmljZS1vbi1jcmVhdGluZy1kaWdpdGFsLXByb2R1Y3Q/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[boxcarmib](/forum/user/39131-boxcarmib "View boxcarmib's Profile")**
- [![boxcarmib's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/39131-boxcarmib "View boxcarmib's Profile") Topic Author
- [ Offline](/forum/user/39131-boxcarmib)

Less More

- Posts: 13
- Thank you received: 0
-
-

9 years 11 months ago [\#256996](#256996) by [boxcarmib](/forum/user/39131-boxcarmib "View boxcarmib's Profile")  Replied by *[boxcarmib](/forum/user/39131-boxcarmib "View boxcarmib's Profile")* on topic *[API advice on creating digital product](/forum/26-product-category-display/887780-api-advice-on-creating-digital-product#256996 "-- HikaShop version -- : 2.6.4 -- Joomla version -- : 3.6.4  So looking through the forum and reading the API docs, I think I understand how to create a new product with the API. Here's my code...  $price = new stdClass(); $price-&gt;price&#95;value = 99.99; $price-&gt;price&#95;currency&#95;id = 1; $price-&gt;price&#95;price&#95;min&#95;quantity = 0;  $product = new stdClass(); $product-&gt;product&#95;name ='fileA'; $product-&gt;product&#95;quantity = -1; $product-&gt;product&#95;published = 1; $product-&gt;product&#95;weight = 0; $product-&gt;product&#95;type = &quot;main&quot;; $product-&gt;product&#95;msrp = 4.99; $product-&gt;product&#95;access = &quot;all&quot;; $product-&gt;prices = &#91;$price&#93;; $product-&gt;categories = &#91;1&#93;;  $productClass = hikashop&#95;get('class.product'); $productId = $productClass-&gt;save($product);  $productClass-&gt;updateCategories($product,$productId);  So while a new product is created (I can see it in the database), it is not displayed in the back end hikashop products listing. Also I note that there is a table &quot;hikashop&#95;file&quot; that gets stuffed with some digital download info. Is there some API i should be calling to update that database table as well? Please tell me what I'm doing wrong.")*

Great support! The latest version fixed the problem I was having.

ONE LAST THING!.... the hikashop website seems to be blocking my IP.... I can access the site from a coffee shop or a friends house, but no luck at all when I'm at my office... can you unblock me? or am i imagining things?

This message contains confidential information

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84ODc3ODAtYXBpLWFkdmljZS1vbi1jcmVhdGluZy1kaWdpdGFsLXByb2R1Y3Q/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Offline](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26401
- Thank you received: 4080
-
- [](http://obsi.dev)
-

9 years 11 months ago [\#257042](#257042) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[API advice on creating digital product](/forum/26-product-category-display/887780-api-advice-on-creating-digital-product#257042 "-- HikaShop version -- : 2.6.4 -- Joomla version -- : 3.6.4  So looking through the forum and reading the API docs, I think I understand how to create a new product with the API. Here's my code...  $price = new stdClass(); $price-&gt;price&#95;value = 99.99; $price-&gt;price&#95;currency&#95;id = 1; $price-&gt;price&#95;price&#95;min&#95;quantity = 0;  $product = new stdClass(); $product-&gt;product&#95;name ='fileA'; $product-&gt;product&#95;quantity = -1; $product-&gt;product&#95;published = 1; $product-&gt;product&#95;weight = 0; $product-&gt;product&#95;type = &quot;main&quot;; $product-&gt;product&#95;msrp = 4.99; $product-&gt;product&#95;access = &quot;all&quot;; $product-&gt;prices = &#91;$price&#93;; $product-&gt;categories = &#91;1&#93;;  $productClass = hikashop&#95;get('class.product'); $productId = $productClass-&gt;save($product);  $productClass-&gt;updateCategories($product,$productId);  So while a new product is created (I can see it in the database), it is not displayed in the back end hikashop products listing. Also I note that there is a table &quot;hikashop&#95;file&quot; that gets stuffed with some digital download info. Is there some API i should be calling to update that database table as well? Please tell me what I'm doing wrong.")*

Hi,

You IP has been unban.
It looks like we found a little bug in the "preview" feature of Kunena which generate wrong 404 links and trigger our security rules.

Sorry for the inconvenient.

Regards,

---

Jerome - Obsidev.com
HikaMarket &amp; HikaSerial developer / HikaShop core dev team.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84ODc3ODAtYXBpLWFkdmljZS1vbi1jcmVhdGluZy1kaWdpdGFsLXByb2R1Y3Q/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[boxcarmib](/forum/user/39131-boxcarmib "View boxcarmib's Profile")**
- [![boxcarmib's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/39131-boxcarmib "View boxcarmib's Profile") Topic Author
- [ Offline](/forum/user/39131-boxcarmib)

Less More

- Posts: 13
- Thank you received: 0
-
-

9 years 11 months ago [\#257081](#257081) by [boxcarmib](/forum/user/39131-boxcarmib "View boxcarmib's Profile")  Replied by *[boxcarmib](/forum/user/39131-boxcarmib "View boxcarmib's Profile")* on topic *[API advice on creating digital product](/forum/26-product-category-display/887780-api-advice-on-creating-digital-product#257081 "-- HikaShop version -- : 2.6.4 -- Joomla version -- : 3.6.4  So looking through the forum and reading the API docs, I think I understand how to create a new product with the API. Here's my code...  $price = new stdClass(); $price-&gt;price&#95;value = 99.99; $price-&gt;price&#95;currency&#95;id = 1; $price-&gt;price&#95;price&#95;min&#95;quantity = 0;  $product = new stdClass(); $product-&gt;product&#95;name ='fileA'; $product-&gt;product&#95;quantity = -1; $product-&gt;product&#95;published = 1; $product-&gt;product&#95;weight = 0; $product-&gt;product&#95;type = &quot;main&quot;; $product-&gt;product&#95;msrp = 4.99; $product-&gt;product&#95;access = &quot;all&quot;; $product-&gt;prices = &#91;$price&#93;; $product-&gt;categories = &#91;1&#93;;  $productClass = hikashop&#95;get('class.product'); $productId = $productClass-&gt;save($product);  $productClass-&gt;updateCategories($product,$productId);  So while a new product is created (I can see it in the database), it is not displayed in the back end hikashop products listing. Also I note that there is a table &quot;hikashop&#95;file&quot; that gets stuffed with some digital download info. Is there some API i should be calling to update that database table as well? Please tell me what I'm doing wrong.")*

Thanks for fixing it! ![:)](/media/kunena/emoticons/3.png ":)")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84ODc3ODAtYXBpLWFkdmljZS1vbi1jcmVhdGluZy1kaWdpdGFsLXByb2R1Y3Q/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.073 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
