Jump to content

Help needed, set up an API for a China supplier or import their CSV


Recommended Posts

Hi,

 

I'm interested in using a China supplier to add their product line to my PrestaShop,

They provide basic instructions about their API example to retrieve data from php.

I can download a csv file by selecting categories of products on their site, but don't know how import this correctly.

Here's the example of their API call, I don't know what to  do with it but want to learn a bit so i can do this with other suppliers.

 

<?php

$API_KEY = '[spam-filter]@_PUT_API_KEY_HERE_[spam-filter]@';

$url = "https://secure.site.com/api/getProductDetails.php";

$data = array(

'key' => $API_KEY,

'currency' => 'USD',

'model_code' => 'CVNZ-9470-Black-2GEN',

);

$content = json_encode($data);

 

echo "<blockquote>"; var_dump($content); echo "</blockquote>";

 

$curl = curl_init($url);

curl_setopt($curl, CURLOPT_HEADER, false);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json"));

curl_setopt($curl, CURLOPT_POST, true);

curl_setopt($curl, CURLOPT_POSTFIELDS, $content);

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$json_response = curl_exec($curl);

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

 

if ( $status != 200 ) {

die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));

}

 

curl_close($curl);

$response = json_decode($json_response, true);

 

echo "<blockquote>"; var_dump($response); echo "</blockquote>";

 

?>

Also, if you're using API's from different stores, would you need a new multistore for each api or can multiple API's be used in one Prestashop?

Thanks in advance.

Edited by sounds (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...