Api: Products: New Product: Add Images

Hi guys,



Trying to add product thru the API by posting to products.



I receive a product id from the API, the product is created. But the images are not pulled into Cscart and added to the products. The features are not added either but that's for another thread.



I tried to find the problem in Cscart source code, but to no avail. Too complex for me to follow.



Any ideas?

Thanks in advance guys.



Here's the array I'm sending:



[font=courier new,courier,monospace]Array[/font]

[font=courier new,courier,monospace]([/font]

[font=courier new,courier,monospace] [product] => sdfsdf[/font]

[font=courier new,courier,monospace] [main_category] => 193[/font]

[font=courier new,courier,monospace] [price] => 113.27[/font]

[font=courier new,courier,monospace] [list_price] => 113.27[/font]

[font=courier new,courier,monospace] [amount] => 100[/font]

[font=courier new,courier,monospace] [full_description] => [/font]

[font=courier new,courier,monospace] [company_id] => 1[/font]

[font=courier new,courier,monospace] [category_ids] => Array[/font]

[font=courier new,courier,monospace] ([/font]

[font=courier new,courier,monospace] [0] => 193[/font]

[font=courier new,courier,monospace] )[/font]



[font=courier new,courier,monospace] [features] => Array[/font]

[font=courier new,courier,monospace] ([/font]

[font=courier new,courier,monospace] [0] => Array[/font]

[font=courier new,courier,monospace] ([/font]

[font=courier new,courier,monospace] [company_id] => 1[/font]

[font=courier new,courier,monospace] [description] => Marka[/font]

[font=courier new,courier,monospace] [display_on_catalog] => Y[/font]

[font=courier new,courier,monospace] [display_on_product] => Y[/font]

[font=courier new,courier,monospace] [comparison] => Y[/font]

[font=courier new,courier,monospace] [value] => K&N[/font]

[font=courier new,courier,monospace] )[/font]



[font=courier new,courier,monospace] )[/font]



[font=courier new,courier,monospace] [main_pair] => Array[/font]

[font=courier new,courier,monospace] ([/font]

[font=courier new,courier,monospace] [http_image_path] => http://192.168.1.50/n/ecimex2/static/pimg/29/09/26/1506290926-33271900.jpg[/font]

[font=courier new,courier,monospace] [image_path] => http://192.168.1.50/n/ecimex2/static/pimg/29/09/26/1506290926-33271900.jpg[/font]

[font=courier new,courier,monospace] )[/font]

[font=courier new,courier,monospace])[/font]

hi,



we tried the image link into browser and it is not opened (possibly badly modified when posting this topic…) so please make sure that links are ok.



also please check this article and let us know if it helps



best regards,

WSA team

Just to be clear, you are sending a json representation of that array, correct?

[quote name='tbirnseth' timestamp='1435880280' post='221425']

Just to be clear, you are sending a json representation of that array, correct?

[/quote]



I'm using the Cscart API helper class @ GitHub - drahosistvan/cscartapi: This is an API wrapper class for CS-Cart v4.x API.

And yes, the library is sending JSON to Cscart.

Cscart receives and processes the request successfully, and creates the product. But does not add the images or the features. No error messages though. Also returns a new product ID.



Cscart API documentation is so vague, it is practically useless when you go 'deep' into some actual usage.

[quote name='Damir (WSA-team)' timestamp='1435859490' post='221408']

we tried the image link into browser and it is not opened (possibly badly modified when posting this topic…) so please make sure that links are ok.



also please check this article and let us know if it helps

[/quote]

Hello,

The link would not work for you because it's a link local to my network. I know the link works, tested it in the browser and from the machine itself. Cscart and the code that calls the API are both on 192.168.1.50.

Checked the article and did as it said (except used .html instead of .gif) and it works, so file_get_contents works as expected.



Which means there is some other problem, possible something wrong with the API.

Solved it!



Apparently, you need to use

[font=courier new,courier,monospace][detailed][image_path / http_image_path][/font]

for it to pull the images.



But the documentation does not mention that [font=courier new,courier,monospace]image_path[/font] needs to be below [font=courier new,courier,monospace]detailed[/font].



Thanks, you guys!



Now on to the feature insertion problem.

It is mentioned in the API docs:



[color=#444444]detailed[/color]

[color=#444444]Full image data[/color]

[color=#444444]array (content explained below)[/color]

[color=#444444]…[/color]

[color=#444444]http_image_path[/color]

[color=#444444]HTTP path to the image[/color]

[color=#444444]Valid HTTP URL pointing to the image[/color]

[color=#444444]…[/color]

[quote name='eComLabs' timestamp='1435917787' post='221487']

[color=#444444]array (content explained below)[/color]

[/quote]

This part is confusing because there is no 'below', no indentation.



I have managed to have the main image created, but not the secondary images.



Here is the current data I'm sending:

Array

(

[product] => test - xxx

[main_category] => 221

[price] => 22.22

[list_price] => 22.22

[amount] => 500

[full_description] => adsa

[company_id] => 1

[category_ids] => Array

(

[0] => 221

)

[lang_code] => tr

[product_features] => Array

(

[18] => Array

(

[feature_id] => 18

[feature_code] =>

[company_id] => 1

[feature_type] => E

[parent_id] => 0

[display_on_product] => N

[display_on_catalog] => N

[display_on_header] => Y

[description] => Marka

[lang_code] => tr

[prefix] =>

[suffix] =>

[categories_path] =>

[full_description] =>

[status] => A

[comparison] => N

[position] => 0

[variant_id] => 146

)



)



[main_pair] => Array

(

[detailed] => Array

(

[http_image_path] => http://192.168.1.50/n/ecimex2/static/pimg/26/11/18/1506261118-77822800.jpg

[image_path] => http://192.168.1.50/n/ecimex2/static/pimg/26/11/18/1506261118-77822800.jpg

)



)



[image_pairs] => Array

(

[0] => Array

(

[detailed] => Array

(

[http_image_path] => http://192.168.1.50/n/ecimex2/static/pimg/29/09/39/1506290939-15438300.jpg

[image_path] => http://192.168.1.50/n/ecimex2/static/pimg/29/09/39/1506290939-15438300.jpg

)



)



)



)



The image is there, made sure of it; main pair is downloaded into Cscart, everything is updated; but the image_pairs are not processed. It says image pair ID must be the key, but does not mention what must be done when the image pair is new. The representation above says key 0 but in actuality there are no keys there. I tried to read the code but too complex for me.

[quote name='necmettin' timestamp='1436183839' post='221754']

This part is confusing because there is no 'below', no indentation.



I have managed to have the main image created, but not the secondary images.



Here is the current data I'm sending:

Array

(

[product] => test - xxx

[main_category] => 221

[price] => 22.22

[list_price] => 22.22

[amount] => 500

[full_description] => adsa

[company_id] => 1

[category_ids] => Array

(

[0] => 221

)

[lang_code] => tr

[product_features] => Array

(

[18] => Array

(

[feature_id] => 18

[feature_code] =>

[company_id] => 1

[feature_type] => E

[parent_id] => 0

[display_on_product] => N

[display_on_catalog] => N

[display_on_header] => Y

[description] => Marka

[lang_code] => tr

[prefix] =>

[suffix] =>

[categories_path] =>

[full_description] =>

[status] => A

[comparison] => N

[position] => 0

[variant_id] => 146

)



)



[main_pair] => Array

(

[detailed] => Array

(

[http_image_path] => [url=“http://192.168.1.50/n/ecimex2/static/pimg/26/11/18/1506261118-77822800.jpg”]http://192.168.1.50/...18-77822800.jpg[/url]

[image_path] => [url=“http://192.168.1.50/n/ecimex2/static/pimg/26/11/18/1506261118-77822800.jpg”]http://192.168.1.50/...18-77822800.jpg[/url]

)



)



[image_pairs] => Array

(

[0] => Array

(

[detailed] => Array

(

[http_image_path] => [url=“http://192.168.1.50/n/ecimex2/static/pimg/29/09/39/1506290939-15438300.jpg”]http://192.168.1.50/...39-15438300.jpg[/url]

[image_path] => [url=“http://192.168.1.50/n/ecimex2/static/pimg/29/09/39/1506290939-15438300.jpg”]http://192.168.1.50/...39-15438300.jpg[/url]

)



)



)



)



The image is there, made sure of it; main pair is downloaded into Cscart, everything is updated; but the image_pairs are not processed. It says image pair ID must be the key, but does not mention what must be done when the image pair is new. The representation above says key 0 but in actuality there are no keys there. I tried to read the code but too complex for me.

[/quote]



yes, i have a same problem, can u give a example how to add image with chrome extensions

Advanced Rest Client Application

Please update the issue here:



http://forum.cs-cart.com/tracker/issue-5927-api-product-create-or-update-image-pairs-are-not-processed-correctly/