get product list using soap api magento - magento

I am using Soap Api and want to get product list whose stock is not 0, meaning there is at least 1 inventory(Stock) of the product in magento.
I am using this type of code but it is not working.
$proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl');
$sessionId = $proxy->login((object)array('username' => 'apiUser', 'apiKey' => 'apiKey'));
$result = $proxy->catalogInventoryStockItemList((object)array('sessionId' => $sessionId->result, 'productIds' => array(1,2)));
var_dump($result->result);

Use the code below, it worked for me:
$proxy = new SoapClient('http://yourstore.com/api/v2_soap/?wsdl');
$sessionId = $proxy->login('apiUserName', 'apiKey');
$result = $proxy->catalogProductList($sessionId);
var_dump($result);
If this did not work for you try to replace the url with the following (add "index.php") http://yourstore.com/index.php/api/v2_soap/?wsdl
Hope this solves your problem!
Try adding the following lines before the code to enable error logging to see what the error is, seeing a blank screen might be because there is an error but you dont see it:
ini_set('display_errors', true);
error_reporting(E_ALL);
Can you also access this URL "yourstore.com/api/v2_soap/?wsdl" or this "yourstore.com/index.php/api/v2_soap/?wsdl" directly in your browser and let me know what you see? you should be able to see an XML document, if there is a setting issue, you will see something like "Invalid service adapter" or somekind of an error message.

use v1 api
$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$session = $client->login('apiUser', 'apiKey');
$proxy->call($session, 'catalog_product.info',array(1,2));//productIds

Related

YouTube DATA API V3 does not return refresh token

I have almost looked through all the answers to this question and have not been able to solve my problem. I tried different options but can't get refresh token. Here's an example of my code.
$googleClient = new \Google_Client();
$redirectUrl = url('***');
$googleClient->setClientId(config('services.google_api_key.client_id'));
$googleClient->setClientSecret(config('services.google_api_key.client_secret'));
$googleClient->setScopes(config('services.google_api_key.scopes'));
$redirect = filter_var($redirectUrl);
$googleClient->setRedirectUri($redirect);
$googleClient->setAccessType('offline');
$googleClient->setApprovalPrompt('force');
if ($request->has('code')) {
$googleClient->authenticate($request->get('code'));
$token = $googleClient->getAccessToken();
dd($token);
}
And it returned only these data
[
"access_token" => "***"
"expires_in" => 3599
"scope" => "https://www.googleapis.com/auth/youtube"
"token_type" => "Bearer"
"created" => 1613189613
]
I know that the refresh token is provided only on the first call, and so I tried to use this method $googleClient->revokeToken($token); to get it again, but it didn't help, and I already spent a whole day trying to solve this problem and could not. Please help me solve this problem. I understand that I am making a mistake somewhere, but I cannot understand where. Thanks in advance.
I finally found the problem and would like to explain in detail what was the reason, maybe someone else will come in handy. And so I created everything as it was described in the official documentation https://developers.google.com/youtube/v3/guides/auth/server-side-web-apps#obtainingaccesstokens.
I used this code and was unable to get the refresh token.
$googleClient = new \Google_Client();
$redirectUrl = url('***');
$googleClient->setClientId(config('services.google_api_key.client_id'));
$googleClient->setClientSecret(config('services.google_api_key.client_secret'));
$googleClient->setScopes(config('services.google_api_key.scopes'));
$redirect = filter_var($redirectUrl);
$googleClient->setRedirectUri($redirect);
$googleClient->setAccessType('offline');
$googleClient->setApprovalPrompt('force');
if ($request->has('code')) {
$googleClient->authenticate($request->get('code'));
$token = $googleClient->getAccessToken();
dd($token);
}
The official documentation says this:
$client = new Google_Client();
$client->setAuthConfig('client_secret.json');
$client->addScope(GOOGLE_SERVICE_YOUTUBE::YOUTUBE_FORCE_SSL);
$client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/oauth2callback.php');
// offline access will give you both an access and refresh token so that
// your app can refresh the access token without user interaction.
$client->setAccessType('offline');
// Using "consent" ensures that your application always receives a refresh token.
// If you are not using offline access, you can omit this.
$client->setApprovalPrompt("consent");
$client->setIncludeGrantedScopes(true); // incremental auth
Pay attention to this part:
// Using "consent" ensures that your application always receives a refresh token.
// If you are not using offline access, you can omit this.
$client->setApprovalPrompt("consent");
And this is what I managed to find out
$client->setApprovalPrompt('force'); // works
$client->setApprovalPrompt('consent'); // doesn't work
$client->setPrompt('consent'); // works
For 'consent' setApprovalPrompt() doesn't work, but I could not find about it in the official documentation. And found this error from here https://github.com/googleapis/google-api-php-client/issues/1795.
My final code looks like this which works fine and returns me a refresh token:
$redirectUrl = url('my_callback_url');
$client = new \Google_Client();
$client->setClientId(config('services.google_api_key.client_id'));
$client->setClientSecret(config('services.google_api_key.client_secret'));
$client->addScope(config('services.google_api_key.scopes'));
$client->setState(substr(md5(time()), 0, 15));
$client->setRedirectUri($redirectUrl);
$client->setAccessType('offline');
$client->setPrompt('consent');
$client->setIncludeGrantedScopes(true);
return $client->createAuthUrl();
Thank you stvar for your answer, after that I started to read the documentation all over again and look for the reason.
adding consent prompt fixed the issue. for js library it will look like this:
const authorizationUrl = oauth2Client.generateAuthUrl({
// 'offline' will get refresh_token
access_type: 'offline',
scope: scopes,
prompt: 'consent',
state: stateName,
});

Inventory stock is not updating for a particular product using Soap Api

I am using Magento version 1.12.0.2.
I am not able to update stock quantity using soap API. It is working fine for other products except one. I tried to update manually from admin and it worked fine but when trying to update from soap API, its not updating.
Please find the script below:
$proxy = new SoapClient('https://sueryder.wcltest.com/index.php/api/v2_soap/?wsdl');
$sessionId = $proxy->login('demo', 'demotest');
$result = $proxy->catalogInventoryStockItemUpdate($sessionId, 3711, array(
'qty' => '31',
'is_in_stock' => 1
));
var_dump($result);
Use soap client- https://sueryder.wcltest.com/index.php/api/v2_soap/?wsdl=1 insteed of https://sueryder.wcltest.com/index.php/api/v2_soap/?wsdl.

Codeigniter Restserver basic autentication always valid

I've a problem with Codeigniter Restserver (https://github.com/chriskacerguis/codeigniter-restserver) because I've enabled basic autentication but it returns always results even if credentials are wrong.
See details below:
Into rest.php file I modified the value:
$config['rest_auth'] = '';
to
$config['rest_auth'] = 'basic';
then
$config['auth_source'] = 'ldap';
to
$config['auth_source'] = '';
Credentials are stored in $config['rest_valid_logins'] = ['admin' => '1234'];
But if I try to call my webservice, it answers with results even if credentials are wrong or missed.
Why?
Thanks.

Dynamic callback url laravel

I tried to make my callback url dynamic because I'm configuring socialite in a multi auth system. I tried to use the socialiteproviders/manager as below:
$clientId = env($provider."_client_id");
$clientSecret = env($provider."_client_secret");
$redirectUrl = "the url i want";
$config = new \SocialiteProviders\Manager\Config($clientId,$clientSecret,$redirectUrl);
return Socialite::with($provider)->setConfig($config)->redirect();
but it says:
Call to undefined method Laravel\Socialite\Two\FacebookProvider::setConfig()
when trying to login with facebook.
Can someone please help me? Thank you.
I could reproduce and found a solution. The code you provided was outdated, and I found other instances of it here: https://laravel.io/forum/07-28-2016-dynamic-callback-url-laravel-socialite
By default, Socialite will get the provider config in services.php by passing the $providerName = facebook
So your code now becomes:
// The services.php config will return null, fix it by using: strtoupper()
$clientId = env(strtoupper($provider . "_client_id"));
$clientSecret = env(strtoupper($provider . "_client_secret"));
$redirectUrl = "/the-url-i-want";
// ->redirect() acts as a closure, without it, you'll get an error like:
// "Serialization of 'Closure' is not allowed"
$user = Socialite::with($provider)->redirect();
return redirect()->to($redirectUrl)->with(['user', $user]);
More info on redirecting with session data:
https://laravel.com/docs/6.x/redirects#redirecting-with-flashed-session-data

Connecting to Magento API with SOAP

I'm trying to follow a tutorail on connecting to magento API with Soap, but am stuck already ? SOAP seems to be installed on my sever as i can browse to the ?wsld and it displays an xml file.
I've setup the user and role in magento admin webservices.
i'm confused by 2 things in the tutorial
choosing a soap client, In this tutorial we will assume the usage of the PHP SoapClient. what is this where do i find it ?
Logging with the SOAP client
"So let's create a simple PHP-script that allows us to login into Magento through SOAP. The logic is here that we first need to initialize a new SoapClient object with as argument the Magento SOAP URL."
// Magento login information
$mage_url = 'http://MAGENTO/api/?wsdl';
$mage_user = 'soap_user';
$mage_api_key = '********';
// Initialize the SOAP client
$soap = new SoapClient( $mage_url );
// Login to Magento
$session_id = $soap->login( $mage_user, $mage_api_key );
Where do you create this script - is it a simple php file ? and how do you actualy make the call - do you just browse to it ?
http://blog.opensourcenetwork.eu/tutorials/guru/connecting-through-soap-with-magento-1
Many thanks in advance
You put this into a new blank file. Save this as name.php und run this is on your server:
<?php
$host = "127.0.0.1/magento/index.php"; //our online shop url
$client = new SoapClient("http://".$host."/api/soap/?wsdl"); //soap handle
$apiuser= "user"; //webservice user login
$apikey = "key"; //webservice user pass
$action = "sales_order.list"; //an action to call later (loading Sales Order List)
try {
$sess_id= $client->login($apiuser, $apikey); //we do login
print_r($client->call($sess_id, $action));
}
catch (Exception $e) { //while an error has occured
echo "==> Error: ".$e->getMessage(); //we print this
exit();
}
?>
Regards boti
Yes, the Soap Client the documents refer to is the built in PHP SoapClient object. There are a plethora of soap client's written in a plethora of different languages. SOAP, as a protocol, is language/platform independent. (although individual languages/platforms tend to have their own quirks). Magento provides a Soap Server, which can interacted with via a client. This is client/server architecture.
You call this script however you want. You can load it in an individual web page, you can run it from the command line $ php script.php, you can put it in an include files, you can place it in another framework's class files, etc.
this helped alot thanks
answered Nov 16 '11 at 7:26 boti
You put this into a new blank file. Save this as name.php und run this is on your server:
<?php
$host = "127.0.0.1/magento/index.php"; //our online shop url
$client = new SoapClient("http://".$host."/api/soap/?wsdl"); //soap handle
$apiuser= "user"; //webservice user login
$apikey = "key"; //webservice user pass
$action = "sales_order.list"; //an action to call later (loading Sales Order List)
try {
$sess_id= $client->login($apiuser, $apikey); //we do login
print_r($client->call($sess_id, $action));
}
catch (Exception $e) { //while an error has occured
echo "==> Error: ".$e->getMessage(); //we print this
exit();
}
?>
HI All,
The solution is :
from Magento Admin Panel...
System -> Configuration -> Web -> Url Options -> Add Store Code to Urls = NO
AND !!!!
Auto-redirect to Base URL = NO
Then Add user from
System -> Web Services-> Users
Make a user to use with the soapclient
Then make a role from
System -> Web Services -> Roles
Attach all resources if you want do it this way.
This is important ! add this role to the user you’ve just created
Also Make sure that PHP.ini from
;extension=php_soap.dll
to
extension=php_soap.dll
Then you can connect with this user I use this code
$proxy = new SoapClient(’http://localhost/api/soap/?wsdl’,array(
$apiuser = "user",
$apikey = "key"));
download soapui from forgesource
http://sourceforge.net/projects/soapui/?source=directory
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Magento">
<soapenv:Header/>
<soapenv:Body>
<urn:login soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<username xsi:type="xsd:string">username</username>
<apiKey xsi:type="xsd:string">password</apiKey>
</urn:login>
</soapenv:Body>
</soapenv:Envelope>
Get the link of our server with link below and save as magentoV2.wsdl
http://localhost/index.php/api/v2_soap?wsdl
I hope this will help others because I a lost half a day to understand this simple things because there were no enough detail information on one place.
HR
They are referring to the standard SOAP client functionality of PHP(provided, i can't read the link you posted, but I'm assuming it is). Have a look here for more: http://php.net/manual/en/class.soapclient.php
As per your question i will tel you simple steps, follow those steps then you wii get result as we require.
1. Login to Magento admin panel then navigate to system-->webservices-->SOAP RPC Roles create SOAP RPC roles
2. Navigate to system-->webservices-->SOAP RPC users create SOAP RPC user map this user with roles.
3. Create one PHP file name it as magentoapi.php inside xampp-->htdocs-->folder(project name).
4. Here I am giving you one example, how to get customer Info.
5. Open magentoapi.php file create one function name it as customerInfo
Below is the code:
function customerInfo($api_url, $api_user, $api_pwd) {
$websites = '' . $api_url . "/index.php/api/soap/?wsdl";
try {
$client = new SoapClient($websites);
$session = $client->login($api_user, $api_pwd);
$result = $client->call($session, 'customer.info', '1');
print_r($result);
} catch (\SoapFault $e) {
echo $e->getMessage();
}
}
Here,
$api_url is your store url,$api_user= api user name, $api_pwd = api password
pass this value to the customerInfo function. We will get complete information about a particular customer
Do same thing for all functions
Here is the API reference URL http://devdocs.magento.com/guides/m1x/api/soap/customer/customer.list.html
Finally run the below URL in browser you will get results
http://localhost/yourprojectname/magentoapi.php?functionName=customerLogout&store_url=http://127.0.0.1/magento19&api_username=magento&api_key=123456

Resources