Jump to content

curl+webservice=add new product


Recommended Posts

Hi all.

 

Can any body help me with webservice.

 

I added new user and give all permissions. I can access to shop thru

curl 'http://[email protected]/api/'

 

I wan to add a lot of products with webservice, but I cannot understand how to do this.

As I can understand from tutorials

 

curl -X POST -T /tmp/xmlka 'http://[email protected]/api/'

 

In this file

<?xml version="1.0" encoding="UTF-8"?>

<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">

<product>

<name><language id="3" xlink:href="http://mototrend.org/api/languages/3"><![CDATA[test]]></language></name>

<id_category_default xlink:href="http://mototrend.org/api/categories/29"><![CDATA[29]]></id_category_default>

<link_rewrite><language id="3" xlink:href="http://mototrend.org/api/languages/3"><![CDATA[-thor-force]]></language></link_rewrite>

</product>

</prestashop>

 

 

But when I call curl -X POST -T /tmp/xmlka 'http://[email protected]/api/'

 

I get such answer

<?xml version="1.0" encoding="UTF-8"?>

<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">

<errors>

<error>

<message><![CDATA[internal error. To see this error please display the PHP errors.]]></message>

</error>

</errors>

</prestashop>

 

 

Where is my mistake?

  • Like 1
Link to comment
Share on other sites

  • 2 months later...
  • 3 months later...

Hi. May be any body need help.

Here is solution.

 

My function written on bash

 

function add_product()

{

local __name=$1

local __manufact=$2

local __price=$3

local __quantity=$4

local __supplier=$5

 

local tmp=`echo ${__name//_/ }`

__name=$tmp

echo "xml=<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > /tmp/xmlka

echo "<prestashop xmlns:xlink=\"http://www.w3.org/1999/xlink\">" >> /tmp/xmlka

echo "<product>" >> /tmp/xmlka

echo "<name><language id=\"3\"><![CDATA[$__name]]></language></name>" >> /tmp/xmlka

echo "<id_manufacturer>$__manufact</id_manufacturer>" >> /tmp/xmlka

echo "<id_supplier>$__supplier</id_supplier>" >> /tmp/xmlka

echo "<out_of_stock>2</out_of_stock>" >> /tmp/xmlka

echo "<price>$__price</price>" >> /tmp/xmlka

echo "<active>1</active>" >> /tmp/xmlka

echo "<quantity>$__quantity</quantity>" >> /tmp/xmlka

echo "<available_for_order>1</available_for_order>" >> /tmp/xmlka

echo "<show_price>1</show_price>" >> /tmp/xmlka

echo "<meta_description><language id=\"3\"><![CDATA[$__name]]></language></meta_description>" >> /tmp/xmlka

echo "<meta_keywords><language id=\"3\"><![CDATA[$__name]]></language></meta_keywords>" >> /tmp/xmlka

echo "<meta_title><language id=\"3\"><![CDATA[$__name]]></language></meta_title>" >> /tmp/xmlka

echo "<link_rewrite><language id=\"3\"><![CDATA[1]]></language></link_rewrite>" >> /tmp/xmlka

echo "<description><language id=\"3\"><![CDATA[$__name]]></language></description>" >> /tmp/xmlka

echo "<description_short><language id=\"3\"><![CDATA[$__name]]></language></description_short>" >> /tmp/xmlka

echo "</product>" >> /tmp/xmlka

echo "</prestashop>" >> /tmp/xmlka

 

curl -v -X POST -d @/tmp/xmlka 'http://[email protected]/api/products/' 1>/tmp/trace 2>/dev/null

}

 

 

You can try to fill file by hands and give as parameter to curl

Link to comment
Share on other sites

×
×
  • Create New...