cancel
Showing results for 
Search instead for 
Did you mean: 

Curl usage help

SOLVED

Curl usage help

So if I need to encode this in Magento curl

http://<my system address>:85/?script=WebsiteSQL&tablename=ITEMMASTER&format=json&keyfield=ITEMCODE&condition=ITEMCODE=’313-6F7’&apikey=<key>

 

I would use the following? but how do I send it Options?

$adminUrl = '<my system address>';
$ch = curl_init();
$data = array("script" => "WebsiteSQL" , '"tablename" => "ITEMMASTER" , "format" => "json" , "keyfield" => "ITEMCODE" , "condition" => "ITEMCODE='313-6f7'" , "apikey" => "<key>");
$data_string = json_encode($data);
$ch = curl_init($adminUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PORT, 85);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded');
$response = curl_exec($ch);
curl_close($sh);
$response= json_decode($response);
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Curl usage help

Hello @kevin_marshall2 
I think you want to use POST and not GET here so it should be like this:

 

$adminUrl = 'http://<my system address>:85/';
$ch = curl_init();
$data = array("script" => "WebsiteSQL" , '"tablename" => "ITEMMASTER" , "format" => "json" , "keyfield" => "ITEMCODE" , "condition" => "ITEMCODE='313-6f7'" , "apikey" => "<key>");
$data_string = json_encode($data);
$ch = curl_init($adminUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PORT, 85);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded');
$response = curl_exec($ch);
curl_close($sh);
$response= json_decode($response);

If this helps you then please give us kudos and select as solution.

View solution in original post

1 REPLY 1

Re: Curl usage help

Hello @kevin_marshall2 
I think you want to use POST and not GET here so it should be like this:

 

$adminUrl = 'http://<my system address>:85/';
$ch = curl_init();
$data = array("script" => "WebsiteSQL" , '"tablename" => "ITEMMASTER" , "format" => "json" , "keyfield" => "ITEMCODE" , "condition" => "ITEMCODE='313-6f7'" , "apikey" => "<key>");
$data_string = json_encode($data);
$ch = curl_init($adminUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PORT, 85);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded');
$response = curl_exec($ch);
curl_close($sh);
$response= json_decode($response);

If this helps you then please give us kudos and select as solution.