Magento 1 API: order.list not working - php

I am using SOAP to use Magento 1 API. It works when I try to use sales_order.info. But when I try to receive the list of the sales, "NULL" is returned. So far I only used example codes from Magento, that's why I am wondering why it is not working.
$mage_url = 'https://myhost/api/?wsdl';
$mage_user = '######';
$mage_api_key = '#######';
$client = new SoapClient( $mage_url );
$session = $client->login( $mage_user, $mage_api_key );
//WORKING:
$sale = $client->call($session, 'sales_order.info', '416203797');
$firstname = $sale['customer_firstname'];
echo $firstname;
//NOT WORKING:
$result = $client->call($session, 'sales_order.list');
var_dump ($result); <-- (result is 'NULL')
Does anybody has an idea why?

check below answer and change as per your requirement. I did this code for my API and it's working perfect. here I have code for "sales_order.list" and "sales_order.info". you can get code as per your requirement.
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$config=array();
$config["hostname"] = "www.yoursitename.com";
$config["login"] = "username";
$config["password"] = "password";
$proxy = new SoapClient('http://'.$config["hostname"].'/index.php/api/soap/?wsdl', array('trace'=>1));
$sessionId = $proxy->login($config["login"], $config["password"]);
$result = array();
$orderlist = ($proxy->call($sessionId, 'sales_order.list', array(array('customer_id'=>array('eq'=>$_REQUEST['customer_id'])))));
$order = ($proxy->call($sessionId, 'sales_order.info', array(array('order_info'=>array('eq'=>$_REQUEST['order'])))));
//echo '<pre>';
//print_r($orderlist);
//print_r($order);
//echo '</pre>';
//$result = json_encode($orderlist);
if($orderlist){
$result['success'] = true;
$result['available'] = $orderlist;
$result['available'] = $order;
}
else{
$result['failed'] = false;
$result['not-available'] = error message;
}
echo json_encode($result);
?>

Related

request does not return any result php

$gateway = new EpisodeGateway();
$db = $gateway ->acces_db();
$Ermittler = array();
$Ermittler = $gateway ->get_hauptkommissar($db);
$index = 0;
$counteur = 0;
for($x=0;$x < sizeof($Ermittler);$x++)
{
echo "<strong>".$Ermittler[$x][0]."</strong>";
echo "<br>";
$result = $gateway->get_episode_by_police($db,$Ermittler[$x][0]);
}
public function get_episode_by_police($db,$Ermittler)
{
$mysqli = new mysqli($db);
$request = 'select titel,Ertaussstrahlung,stadt from folge where Ermittler=$Ermittler[0]';
$result = mysqli_query($db,'select titel,Ertaussstrahlung,stadt from folge where Ermittler= %s',$Ermittler[0]);
$result = mysqli_fetch_assoc($result);
return $result;
}
I do not know why, it is not working. I don't have any result in the variable result in the for loop. Don't be mean with me please. I'm still a beginner

Session variables not setting correctly

I am trying to set a session variable from page to another. It was working on my localhost but then I uploaded it to my server and now it fails. I have done some basic bug tests, and it will print at specific points, I have labeled them in the code. Here is the code the code I am using
//PAGE 1
session_start();
if(isset($_REQUEST['id'])){
$_SESSION['id'] = $_REQUEST['id'];
//prints here just fine then fails after
header('location: app.php');
}elseif($_POST){
if(isset($_SESSION['error'])){
unset($_SESSION['error']);
}
$questions = array();
for($i = 1; $i <= 11; $i++){
$questions['q'.$i] = $_POST['q'.$i];
}
$check = "";
foreach($questions as $key => $val){
$check .= $val;
}
$metreq = strcmp($check, "1111-1-1-1-11-1-1");
if(!$metreq){
$_SESSION['questionaire'] = $questions;
header("location: app.php");
}else{
header('location: nq.php');
}
}
///PAGE 2
<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
session_start();
require_once('inc/state_list_options.php');
if(isset($_SESSION['questionaire']) || isset($_SESSION['id'])){
$id = $first_name = $middle_name = $last_name = $suffix = $address = $city = $state = $zip = $phone_area = $phone_exch =
$phone_num = $phone2_area = $phone2_exch = $phone2_num = $email_address = $birth_month = $birth_day = $birth_year =
$job = $referred = "";
$selected = "selected";
$questions = array();
//here we will generate a session id that is the code passed from the link clicked by the user
$conn = mysql_connect('host', 'user', 'password');
mysql_select_db('db', $conn);
if($conn){
if(isset($_SESSION['id'])){
$id = $_SESSION['id'];
$q = "SELECT * FROM eagle.pre_application WHERE id = '$id'";
$r = mysql_query($q, $conn);
$row = mysql_fetch_assoc($r);
$first_name = $row['first_name'];
$middle_name = $row['middle_name'];
$last_name = $row['last_name'];
$suffix = $row['suffix'];
$address = $row['address'];
$city = $row['city'];
$state = $row['state'];
$zip = $row['zip'];
$phone_area = $row['phone_area'];
$phone_exch = $row['phone_exch'];
$phone_num = $row['phone_num'];
$phone2_area = $row['phone2_area'];
$phone2_exch = $row['phone2_exch'];
$phone2_num = $row['phone2_num'];
$email_address = $row['email_address'];
$birth_month = $row['birth_month'];
$birth_day = $row['birth_day'];
$birth_year = $row['birth_year'];
$questions['q1'] = $row['q1'];
$questions['q2'] = $row['q2'];
$questions['q3'] = $row['q3'];
$questions['q4'] = $row['q4'];
$questions['q5'] = $row['q5'];
$questions['q6'] = $row['q6'];
$questions['q7'] = $row['q7'];
$questions['q8'] = $row['q8'];
$questions['q9'] = $row['q9'];
$questions['q10'] = $row['q10'];
$questions['q11'] = $row['q11'];
$_SESSION['questionaire'] = $questions;
}
$q2 = "SELECT job_posting.id, job_posting.title, location.city, location.state
FROM eagle.job_posting
LEFT JOIN eagle.location
ON job_posting.location__Id = location.id";
$j = mysql_query($q2, $conn);
?>
<!-- job application goes ehre -->
<?
}else{
$_SESSION['error'] = "Please fill out the questionaire before completing the applicationn.";
header('location: index.php');
exit;
}
}else{
echo "There is an error";
}
?>
I'm not 100% sure where to go from this point forward. I was thinking that it was the headers causing and issue, but that has never appeared so at this poitn I am baffled. Please let me know what you think about this. If you need additional code or further examples please let me know and I can provide them for you. Thank you in advance to anyone who stops by to help!
EDITS/DEVELOPMENTS/UPDATES
9:07 AM: Using developer's tools on chrome it is now receiving a 500 server error when submitting to page 2
9:16 AM Removed errors found with the require_once(''); There was an error in the path. Now it just automatically goes to the redirect on page 2 even if a variable is manually passed in the header via the address bar. I'm stumped still. code updated to reflect changes

Google Adword API + PHP

Hai I am trying to integrate Google Adword API .. I am not having any devloper token for under MCC (My client center) account .
I am using this code ... But its not working
If you have any answer for this problem then please help me ... thanks in advance
<?php
require_once 'Google/Api/Ads/AdWords/Lib/AdWordsUser.php';
$username = "abc#mail.com";
$password = "abc";
$currencyCode = "USD";
$developerToken = "$username++$currencyCode";
$user = new AdWordsUser(null, $username, $password, $developerToken);
$user->SetDefaultServer("https://adwords-sandbox.google.com/");
$user->LogAll();
$user->SetClientId(null);
try {
$campaignService = $user->GetService("CampaignService", 'v201306');
$page = $campaignService->get(new Selector());
} catch (Exception $e) {
}
$managedCustomerService = $user->GetService('ManagedCustomerService', 'v201306');
$selector = new Selector();
$selector->fields = array('Login', 'CustomerId', 'Name');
$page = $managedCustomerService->get($selector);
$accounts = array();
foreach ($page->entries as $account) {
if ($account->customerId > 0) {
$accounts[] = $account;
}
}
foreach ($accounts as $account) {
print "Customer ID: {$account->customerId}\n";
}
$customerId = $accounts[0]->customerId;
$user->SetClientId($customerId);
$budgetService = $user->GetService('BudgetService', 'v201306');
$budget = new Budget();
$budget->name = 'Test Budget #' . time();
$budget->period = 'DAILY';
$budget->amount = new Money((float) 10000000);
$budget->deliveryMethod = 'STANDARD';
$operations = array();
$operation = new BudgetOperation();
$operation->operand = $budget;
$operation->operator = 'ADD';
$operations[] = $operation;
$result = $budgetService->mutate($operations);
$budget = $result->value[0];
$campaignService = $user->GetService("CampaignService", 'v201306');
$campaign = new Campaign();
$campaign->name = "Test Sandbox Account #" + time();
$campaign->status = "ACTIVE";
$campaign->biddingStrategy = new ManualCPC();
$campaign->budget = new Budget();
$campaign->budget->budgetId = $budget->budgetId;
$networkSetting = new NetworkSetting();
$networkSetting->targetGoogleSearch = TRUE;
$campaign->networkSetting = $networkSetting;
$campaign->settings = array(new KeywordMatchSetting(false));
$operation = new CampaignOperation();
$operation->operand = $campaign;
$operation->operator = 'ADD';
$operations = array($operation);
$result = $campaignService->mutate($operations);
print_r($result);
?>
I am getting this error ::
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://adwords-sandbox.google.com//api/adwords/mcm/v201306/ManagedCustomerService?wsdl' : failed to load external entity "https://adwords-sandbox.google.com//api/adwords/mcm/v201306/ManagedCustomerService?wsdl" in /home/profiles/public_html/testing/seoteam/q/src/Google/Api/Ads/Common/Lib/AdsSoapClient.php:169 Stack trace: #0 /home/profiles/public_html/testing/seoteam/q/src/Google/Api/Ads/Common/Lib/AdsSoapClient.php(169): SoapClient->SoapClient('https://adwords...', Array) #1 /home/profiles/public_html/testing/seoteam/q/src/Google/Api/Ads/AdWords/Lib/AdWordsSoapClient.php(53): AdsSoapClient->__construct('https://adwords...', Array, Object(AdWordsUser), 'ManagedCustomer...', 'https://adwords...') #2 /home/profiles/public_html/testing/seoteam/q/src/Google/Api/Ads/AdWords/v201306/ManagedCustomerService.php(3660): AdWordsSoapClient->__construct('https://adwords...', Array, Object(AdWordsUser), 'ManagedCustomer...', 'https://adwor in /home/profiles/public_html/testing/seoteam/q/src/Google/Api/Ads/Common/Lib/AdsSoapClient.php on line 169
The Adwords API sandbox functionality is deprecated. You can use a test account while you wait for your token to be approved: Test accounts documentation
If you still keep getting this error even with Test accounts, check my answer at https://stackoverflow.com/a/41622876/674965

Redeclare function in loop

I'm stumped as to how I would get this working. I'm using the twitteroauth.php library and I am grabbing the users token and token secret from a db query. Here is the code:
while($row = mysql_fetch_array($m))
{
$connection = new TwitterOAuth($consumerKey, $consumerSecret, $oauthToken, $oauthTokenSecret);
$consumerKey = "#####";
$consumerSecret = "#####";
$oauthToken = $row['oauth_token'];
$oauthTokenSecret = $row['oauth_token_secret'];
$userName = $row['username'];
$query = mysql_query("select url from retweets order by rand() limit 1");
$row = mysql_fetch_assoc($query);
$retweet = basename($row['url']);
$method = 'statuses/retweet/'.$retweet.'';
twitterOAuth($method, $connection->post($method), $connection->http_code, $userName);
}
If there are multiple results from mysql, it loops through and says:
Fatal error: Cannot redeclare random_from() (previously declared in /usr/share/nginx/www/twitteroauth/twitteroauth.php:199) in /usr/share/nginx/www/twitteroauth/twitteroauth.php on line 199
Since the $connection variable relies on $oauthToken and $oauthTokenSecret from the mysql query, I can't move it outside of the loop, so how would I make it so I can use it in each loop without redeclaring?
Thank you in advance!
Update: This is twitterOAuth
function twitterOAuth($method, $response, $http_code, $userName, $parameters = '') {
if($http_code == 200){
echo "retweeted successfully #".$userName."<br />";
}else{
echo "an error has occurred while retweeting #".$userName."";
echo "<br />";
print_r($response);
}
}
It needs to look like this...
while($row = mysql_fetch_array($m))
{
$consumerKey = "#####";
$consumerSecret = "#####";
$oauthToken = $row['oauth_token'];
$oauthTokenSecret = $row['oauth_token_secret'];
$userName = $row['username'];
$connection = new TwitterOAuth($consumerKey, $consumerSecret, $oauthToken, $oauthTokenSecret);
$query = mysql_query("select url from retweets order by rand() limit 1");
$row = mysql_fetch_assoc($query);
$retweet = basename($row['url']);
$method = 'statuses/retweet/'.$retweet.'';
twitterOAuth($method, $connection->post($method), $connection->http_code, $userName);
}
You were declaring it before declaring the variables that you wanted to pass into it...

update mysql and add value to existing value

I am trying to edit this code so that instead of just inserting the info - it checks to see if the file already exists in the database, if it does it inserts as it does now. If it does exist... it should just update the info, adding the "value" amount to the value amount already in there instead of replacing it. But this is very new to me and I am lost so any help with really be appreciated!
<?php
define('JPATH_BASE',$_SERVER['DOCUMENT_ROOT']);
require_once($_SERVER['DOCUMENT_ROOT']."/b2/configuration.php");
require_once($_SERVER['DOCUMENT_ROOT']."/b2/libraries/joomla/factory.php");
require_once($_SERVER['DOCUMENT_ROOT']."/b2/libraries/joomla/base/object.php");
require_once($_SERVER['DOCUMENT_ROOT']."/b2/libraries/joomla/database/database.php");
require_once($_SERVER['DOCUMENT_ROOT']."/b2/libraries/joomla/database/database/mysql.php");
$config = new JConfig;
$options = array();
$options['host'] = $config->host;
$options['user'] = $config->user;
$options['password'] = $config->password;
$options['database'] = $config->db;
$options['prefix'] = $config->dbprefix;
$options['select'] = true;
$db = new JDatabaseMySQL($options);
//$user = JFactory::getUser();
$userId = 0;
//($user->id > 0) ? $user->id : 0;
$numbervote = $_REQUEST['w'];
$folder = $_REQUEST['w2'];
$name = $_REQUEST['w1'];
$date = date('Y-m-d H-i-s');
$sql = "INSERT INTO jos_image_ratetting (id,userid,datecreated,value,filename,folder,md5name) VALUES(NULL,'".$userId."','".$date."','".$numbervote."','".$name."','".$folder."',MD5('".$name."'))";
$db->setQuery($sql);
if($db->query()){
$msg = "Thanks for rate!";
}else{
$msg = mysql_error();
}
echo $msg;
//echo 'Hello';
?>
Take a look at the ON DUPLICATE KEY UPDATE syntax for MySQL

Categories