Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

CS-Cart API and PHP cURL Rate Topic   * * * * * 1 votes

 
  • GauNodac
  • Newbie
  • Members
  • Join Date: 25-Oct 13
  • 3 posts

Posted 25 October 2013 - 09:06 PM #1

I am trying to communicate via the API for CS-Cart and having some troubles. I am able to fetch data successfully, but not putting data. I have tried the helper class in this forum as well as regular PHP cURL requests.

I get this error: "Method Not Allowed: O" Status: 405.

It would help if anyone had any working examples of PHP cURL using "PUT". I do not use mod_rewrite for this. So my calls are towards example:
"api.php?_d=orders&order_id=1"

My code (Real passwords, usernames and url is omitted in example):
--------------------------------------------------------------------
$order_data = json_encode(array('timestamp' => 1382548160) );
$order_id = "13752";
$query_string = "?_d=orders&order_id=$order_id";

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_URL, 'http://example.com/api.php'.$query_string);
curl_setopt($ch, CURLOPT_USERPWD, $usr . ":" . $pass);
curl_setopt($ch, CURLOPT_POSTFIELDS,$order_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($order_data))
);

$result = curl_exec($ch);

echo $result;
curl_close($ch);

--------------------------------------------------------------------

Hope any one can help. :)

 
  • GauNodac
  • Newbie
  • Members
  • Join Date: 25-Oct 13
  • 3 posts

Posted 25 October 2013 - 10:18 PM #2

I found the answer at last. It was in the URL. It should be:
"?_d=orders/$order_id"

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11263 posts

Posted 26 October 2013 - 04:16 AM #3

thanks for posting the update. Small syntactical issues like this can drive one crazy but now, I'll be able to search for the answer.

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • rolex
  • Newbie
  • Members
  • Join Date: 23-Apr 14
  • 11 posts

Posted 23 April 2014 - 11:14 PM #4

I found the answer at last. It was in the URL. It should be:
"?_d=orders/$order_id"

I would like to do the same , but can not find api.php ? any idea ? .thanks...

 
  • gorka
  • Newbie
  • Members
  • Join Date: 28-Apr 14
  • 3 posts

Posted 28 April 2014 - 04:57 PM #5

I would like to do the same , but can not find api.php ? any idea ? .thanks...


The api.php is in your server: {project_path}/shop/api.php

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11263 posts

Posted 28 April 2014 - 09:58 PM #6

I believe that if they are using the free version that api.php does not exist.

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • rolex
  • Newbie
  • Members
  • Join Date: 23-Apr 14
  • 11 posts

Posted 29 April 2014 - 09:37 PM #7

The api.php is in your server: {project_path}/shop/api.php

thanks for the the info

 

Posted 17 May 2014 - 07:48 PM #8

Hello Everyone,

I have implemented the code from "GauNodac" post and I updated my test order status to "Complete":
$order_data = json_encode(array('status' => 'C') );

It works fine, but the only problem is CS-Cart doesn't send an order status update notification emails to the customer. Does anybody know how to fix that please?

Thank you in advance!