Walmart API Search Products - php

I am trying to get search products for a keyword
My code:
$searchquery = "ipod";
$api_endpoint = "http://api.walmartlabs.com/v1/search";
$postfields = "apiKey=". $appid ."&query=" . $searchquery;
//$postfields = array('apiKey' => $appid, 'query' => $searchquery);
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, $api_endpoint);
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
//curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);
curl_setopt($connection, CURLOPT_POST, true);
curl_setopt($connection, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($connection, CURLOPT_HEADER, true);
//curl_setopt($connection, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($connection);
curl_close($connection);
print_r($api_endpoint);
print_r($response);
When i go in browser and visit api.walmartlabs.com/v1/search?apiKey={appid}&query=ipod , it shows results, but when i try to do with curl , it shows
"Action Not Found"
Here is the Screenshot
Any help would be appreciated.

looking on the doc (https://developer.walmartlabs.com/io-docs) it appears that the server expects a GET request.
Just replace your POST request with a GET request and all should be fine
$searchquery = "ipod";
$api_endpoint = "http://api.walmartlabs.com/v1/search";
$urlParams = "apiKey=". $appid ."&query=" . $searchquery;
$fullUrl = $api_endpoint . '?' . $urlParams;
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, $fullUrl);
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($connection, CURLOPT_HEADER, true);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($connection);
curl_close($connection);
print_r($api_endpoint);
print_r($response);

<?php
ini_set('display_errors', 1);
//API URL : https://affiliates.walmart.com/#!/api
$api_key="**********"; //https://developer.walmartlabs.com/apps/mykeys
$keywords="men%20watches"; // Search text - whitespace separated sequence of keywords to search for
$format="json"; // data we want in response
$responseGroup="base"; // Specifies the item fields returned in the response, allowed response groups are [base, full]. Default value is base.
$sort='price'; //Sorting criteria, allowed sort types are [relevance, price, title, bestseller, customerRating, new]. Default sort is by relevance.
$order="asc"; //Sort ordering criteria, allowed values are [asc, desc]. This parameter is needed only for the sort types [price, title, customerRating].
//http://api.walmartlabs.com/v1/search?apiKey={apiKey}&lsPublisherId={Your LinkShare Publisher Id}&query=ipod
$request_url="http://api.walmartlabs.com/v1/search?apiKey=".$api_key."&query=".$keywords."&format=".$format."&responseGroup=".$responseGroup."&sort=".$sort."&order=".$order;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$request_url);
curl_setopt($ch, CURLOPT_FAILONERROR,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$retValue = curl_exec($ch);
// Check for errors and display the error message
if($errno = curl_errno($ch)) {
$error_message = curl_strerror($errno);
echo "cURL error ({$errno}):\n {$error_message}";
}
curl_close($ch);
$arr = json_decode($retValue,true);
echo "<pre>";
print_r($arr);
// echo "<pre>";
// var_dump($retValue);
?>

Related

Pipedrive - Updating a Lead Returns 404 not found

I am trying to update a LEAD using this URL
$lead_url = ‘https://’.$company_domain.’.pipedrive.com/api/v1/leads/’ . $leadID . ‘?api_token=’ . $PD_API_KEY;
But it returns 404 Not Found. When I check this URL in the browser it returns the complete information of that lead.
Here is my Curl Code:
function pipedrive_update_curl($arr , $endpoint)
{
$response = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($arr));
//***//
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
//**//
$response_result = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curl_errors = curl_error($ch);
curl_close($ch);
$response['error'] = $curl_errors;
$response['status'] = $status_code;
$response['response'] = $response_result;
return $response;
}
Can somebody please explain where I am going wrong?
PUT method for updating leads is not supported.
see docs and pipedrive community posts:
https://developers.pipedrive.com/docs/api/v1/Leads#updateLead
https://devcommunity.pipedrive.com/t/put-not-working-when-updating-a-lead/3629

how to view final url before submission curl php

I want to know final url just before executing curl to check all parameters passing as desired. how to view that.
<?PHP
function openurl($url) {
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postvars);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_TIMEOUT, '3');
$content = trim(curl_exec($ch));
curl_close($ch);
echo $content;
}
$postvars = array('user' => "user123",'password' => "user#user!123",'Text' => "Test");
$sms_url ="http://remoteserver/plain";
openurl($sms_url);
?>
desired output to check all params and its values passing correct..
http://remoteserver/plain?user=user123&password=user#user!123&Text=TESThere
You forgot to add the $postvars as parameter to your function.
function openurl($url, $postvars) {
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postvars);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_TIMEOUT, '3');
$content = trim(curl_exec($ch));
curl_close($ch);
echo $content;
}
$postvars = array('user' => "user123",'password' => "user#user!123",'Text' => "Test");
$sms_url ="http://remoteserver/plain";
// create a test var which we can display on screen / log
$test_url = sms_url . http_build_query($postvars);
// either send it to the browser
echo $test_url;
// or send it to your log (make sure loggin is enabled!)
error_log("CURL URL: $test_url", 0);
openurl($sms_url, $postvars);

how to integrate atom payment gateway in PHP

I am using ATOM payment gateway and YII framework. I am using following code & i am not getting response here $returnData = curl_exec($ch); its returning empty.
Please tell how can i come over it. is ther any tutorials for this integration.
$url = ‘http://203.114.240.77/paynetz/epi/fts';// test bed URL
$port = 80;
$atom_prod_id = “NSE”;
// code to generate token
$param = "&login=".$userid."&pass=".$password."&ttype=NBFundTransfer&prodid=".$atom_prod_id."&amt=".$amount."&txncurr=INR&txnscamt=0&clientcode=".$clientcode."&txnid=".$invoiceid."&date=".$today."&custacc=12345";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_PORT , $port);
curl_setopt($ch, CURLOPT_SSLVERSION,3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
$returnData = curl_exec($ch);
// Check if any error occured
if(curl_errno($ch))
{
echo ‘Curl error: ‘ . curl_error($ch);
}
curl_close($ch);
$xmlObj = new SimpleXMLElement($returnData);
$final_url = $xmlObj->MERCHANT->RESPONSE->url;
// eof code to generate token
// code to generate form action
$param = “”;
$param .= “&ttype=NBFundTransfer”;
$param .= “&tempTxnId=”.$xmlObj->MERCHANT->RESPONSE->param[1];
$param .= “&token=”.$xmlObj->MERCHANT->RESPONSE->param[2];
$param .= “&txnStage=1″;
$url = $url.”?”.$param;
// eof code to generate form action
Please check for the http response code. Are you expecting any data to be returned? You're posting data, maybe the response-body should be empty?
Please add the code below to check for the http status code.
$info = curl_getinfo($ch);
echo $info["http_code"];

"type Invalid 16-bit integer. invalid Input.format.short " error while HTTP POST request using CURL

I am newbie with Social Minor I am trying to create a new Feed in Social Miner using "Social-Miner Create Feed API".
Problem:
When I click on "Create Feed" button on my interface I receive following error: " type Invalid 16-bit integer. invalid Input.format.short "
Code:
<?php
error_reporting(o);
$URL = "http://192.168.200.163:8080/ccp-webapp/ccp/feed";
//Create Feed form values
$type = $_POST['type'];
$feed_name = $_POST['feed_name'];
$description = $_POST['description'];
$ur = $_POST['ur'];
$polling_interval = $_POST['polling_interval'];
$minimum_age = $_POST['minimum_age'];
$reply_template = $_POST['reply_template'];
$tags = $_POST['tags'];
//Storing above values in a string
$myFeedString='<?xml version="1.0" encoding="utf-8"?>
<Feed>
<type>$type</type>
<name>$feed_name</name>
<description>$description</description>
<ur>$ur</ur>
<polling_interval>$polling_interval</polling_interval>
<minimum_age>$minimum_age</minimum_age>
<tags>
<tag>$tags</tag>
</tags>
</Feed>
';
//setting the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_USERPWD, "hashmatkhan" . ":" . "Army2life");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $myFeedString);
if (curl_errno($ch))
{
//moving to display page to display curl errors
echo curl_errno($ch) ;
echo curl_error($ch);
}
else
{
//getting response from server
$response = curl_exec($ch);
print_r($response);
curl_close($ch);
}
?>
Need Help?

getting JSON object from a GET cURL in php

Here is my code:
$ch = curl_init('');
$request = 'where={"place":"'.$place.'"}&count=1&limit=0';
$url = "https://api.parse.com/1/classes/className" . "?" . $request;
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-Parse-Application-Id: ...',
'X-Parse-REST-API-Key: ...
));
//curl_setopt($ch, CURLOPT_POST, true);
// Execute
$result = curl_exec($ch);
// Close connection
curl_close($ch);
Here is the output:
{"results":[],"count":0}
I want to get only he number in count.
I tried this:
$json_res = json_decode($result, true);
echo 'Number : '.$json_res['count'];
but the output becomes:
Number :
If i do json_encode the result is just a True value.
I tried added this:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
but didn't change anything.
What am I missing?
EDIT: doing a var_dump on $json_res gives me that: int(1).
Why is that?
Curl does not return the output if you don't set the CURLOPT_RETURNTRANSFER option
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

Categories