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

#   How to add the products through API

##

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

Less More

- Posts: 7
- Thank you received: 0
-
-

15 years 10 months ago [\#3958](#3958) by [chola](/forum/user/538-chola "View chola's Profile")  *[How to add the products through API](/forum/4-how-to/3958-how-to-add-the-products-through-api#3958 "Hi, I have a requirement to call your api and insert the products and their details from the custom page.Can you please point me in the right direction.  Regards Chola")* was created by *[chola](/forum/user/538-chola "View chola's Profile")*

Hi,
I have a requirement to call your api and insert the products and their details from the custom page.Can you please point me in the right direction.

Regards
Chola

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzM5NTgtaG93LXRvLWFkZC10aGUtcHJvZHVjdHMtdGhyb3VnaC1hcGk/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)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86290
- Thank you received: 14268
-
-

15 years 10 months ago [\#3959](#3959) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: How to add the products through API](/forum/4-how-to/3958-how-to-add-the-products-through-api#3959 "Hi, I have a requirement to call your api and insert the products and their details from the custom page.Can you please point me in the right direction.  Regards Chola")*

We added a code sample for that in our developer's documentation: [ www.hikashop.com/support/documentation/6...umentation.html#code](http://www.hikashop.com/support/documentation/62-hikashop-developer-documentation.html#code)

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

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

Less More

- Posts: 7
- Thank you received: 0
-
-

15 years 10 months ago [\#3969](#3969) by [chola](/forum/user/538-chola "View chola's Profile")  Replied by *[chola](/forum/user/538-chola "View chola's Profile")* on topic *[Re: How to add the products through API](/forum/4-how-to/3958-how-to-add-the-products-through-api#3969 "Hi, I have a requirement to call your api and insert the products and their details from the custom page.Can you please point me in the right direction.  Regards Chola")*

Thanks for the code snippet.But I would be more interested in adding the product itself.

Idea is to allow the user to sell products and I would need an API to define the product itself from the front end.

Regards
Chola

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzM5NTgtaG93LXRvLWFkZC10aGUtcHJvZHVjdHMtdGhyb3VnaC1hcGk/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)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86290
- Thank you received: 14268
-
-

15 years 10 months ago [\#3970](#3970) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: How to add the products through API](/forum/4-how-to/3958-how-to-add-the-products-through-api#3970 "Hi, I have a requirement to call your api and insert the products and their details from the custom page.Can you please point me in the right direction.  Regards Chola")*

To insert a product you can use something like this (after including the hikashop helper file as mentionned in my previous link):
Code:

$price=null; $price-&gt;price_value = 10; $price-&gt;price_currency_id = 1; $price-&gt;price_price_min_quantity = 0; $product = null; $product-&gt;product_name = 'my product'; $product-&gt;prices = array($price); $product-&gt;categories = array(1, 2); //where 1and 2 are the ids of two categories $productClass = hikashop::get('class.product'); $productClass-&gt;save($product);

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

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

Less More

- Posts: 7
- Thank you received: 0
-
-

15 years 10 months ago [\#3973](#3973) by [chola](/forum/user/538-chola "View chola's Profile")  Replied by *[chola](/forum/user/538-chola "View chola's Profile")* on topic *[Re: How to add the products through API](/forum/4-how-to/3958-how-to-add-the-products-through-api#3973 "Hi, I have a requirement to call your api and insert the products and their details from the custom page.Can you please point me in the right direction.  Regards Chola")*

Awesome Thanks..Can you please give and example for the prices array?

Example: I have something like below.

4 Hrs -- $4.99
24 Hrs -- $10.99
5 Days -- $24.99

Regards
Chola

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzM5NTgtaG93LXRvLWFkZC10aGUtcHJvZHVjdHMtdGhyb3VnaC1hcGk/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)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86290
- Thank you received: 14268
-
-

15 years 10 months ago [\#3974](#3974) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: How to add the products through API](/forum/4-how-to/3958-how-to-add-the-products-through-api#3974 "Hi, I have a requirement to call your api and insert the products and their details from the custom page.Can you please point me in the right direction.  Regards Chola")*

You can't just add days to prices...
What do you want to do ?

I suppose that you want to have a product with a "delivery" characteristic and several variants, each with a price. That's way more that a few lines of code as you need to handle 5 tables data. Not something that we can provide in a forum. I invite you to read the code in administrator/components/com_hikashop/classes/product.php to look at our code and see our code handling the save of the product information.
You need:
either to create the characteristic (with the values 4hrs, 24hrs, 5days) or not based on your needs.
Then, add that characteristic to the product with the characteristics array.
Then, get the automatically generated variants product_id based on the product_id from the product you just saved.
Also, get the characteristic linked to the each variants via the variant table in order to know which one correspond to which value of your characteristic
Finally, add the corresponding price for each variant directly in the price table.

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

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

Less More

- Posts: 7
- Thank you received: 0
-
-

15 years 10 months ago [\#3975](#3975) by [chola](/forum/user/538-chola "View chola's Profile")  Replied by *[chola](/forum/user/538-chola "View chola's Profile")* on topic *[Re: How to add the products through API](/forum/4-how-to/3958-how-to-add-the-products-through-api#3975 "Hi, I have a requirement to call your api and insert the products and their details from the custom page.Can you please point me in the right direction.  Regards Chola")*

Yeah Got it..I will look into the file and find out how the save happens with characteristics.

Thanks for helping me out..It is awesome support

Regards
Chola

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzM5NTgtaG93LXRvLWFkZC10aGUtcHJvZHVjdHMtdGhyb3VnaC1hcGk/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.344 seconds

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

[](#top)
