I am working on a project that requires access to Brandbank API, however their documentation seems pretty limited as to how to access their information.
I have been given access keys and the documentation seems to direct you to extract data via SOAP siting this link https://api.brandbank.com/svc/feed/extractdata.asmx?WSDL
Can anyone provide an example of how to access the product feed of this API?
At a minimum you will need code that looks like this:
$wsdl = "https://api.brandbank.com/svc/feed/extractdata.asmx?WSDL";
try {
$soapclient = new SoapClient($wsdl, array(
'soap_version' => SOAP_1_1,
'trace' => 1,
'exceptions' => true,
)
);
$parameters = new stdClass();
$response = $soapclient->GetUnsentProductData($parameters);
} catch (Exception $e) {
var_dump($e ->getMessage());
}
The call won't work until you finish it with your access credentials, but it provides an example of how most SOAP calls look in PHP.
Related
I am trying to figure out how to programmatically create a "HelpDesk" ticket in vTiger using its Web Services api. I am currently using the official vtwsclib v1.5 php library. The log in, appears to succeed and I can also successfully perform a doDescribe on the module, however doCreate returns 'false' no matter what I do. Sample below. Am I missing anything?
$url = 'http://vtiger.mydomain.com/';
$client = new Vtiger_WSClient($url);
$login = $client -> doLogin('systemuser', 'O8nFgnotrealkey');
if (!$login)
echo 'Login Failed';
else {
$module = "HelpDesk";
$record = $client -> doCreate($module, Array(
'assigned_user_id' => "21",
'parent_id' => "91",
'ticket_title' => "test",
'ticketstatus' => "Open"
));
if ($record) {
$recordid = $client -> getRecordId($record['id']);
}
}
Retruns:
$record: bool(false)
Found it:
Looks like if you leave 'assigned_user_id' blank, it will populate it with the correct 'assigned_user_id' for yourself. The 'assigned_user_id' can also be retrieved for your own account from the login response and it appears like this {module_id}x{user_id}. ie: "3x16".
All id's ('parent_id', 'assigned_user_id', 'related_to' etc etc etc) appear to be in a 'NxN' format.
struggling to understand the oauth2 token and refresh token processes
ive got this code
$url = 'https://www.googleapis.com/oauth2/v3/token';
$data = array('client_id' => 'clientid', 'client_secret' => 'secret','refresh_token' => 'token','grant_type' => 'refresh_token');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded",
'method' => 'POST',
'approval_prompt'=>'force',
'access_type'=>'offline',
'content' => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
that code above gives me an access token , and i followed this link suggested by one fellow stackoverflower, pinoyyid, BUT , im confunsed on how to correctly use the resulting access token to access drive and copy a file...
all the process ive seen usually involves $client = new Google_Client() and im not sure on how to use the whole POST http://..... thing, so basically i need to figure out if i use the access token i got with the code above in a new instance of google client, or i simply do a post to a url with necesary info ( which im not clear on also ) any help/clarification is appreciated guys really
EDIT #1
what i want to achieve is to allow the end user to access my drive via my webpage, to let them copy a spreadsheet in my drive , and access it via my website, to store data on the spreadsheet,the spreadsheet will always be on my drive, never on the end user
EDIT #2
code as per your posts is as follows, using the service account,,,,the files are inside that gmail account which i created on the api console a service account
<?php
require 'Google/autoload.php';
$client = new Google_Client();
// Replace this with your application name.
$client->setApplicationName("TEST");
// Replace this with the service you are using.
$service = new Google_Service_Drive($client);
// This file location should point to the private key file.
$key = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/number-privatekey.p12');
$user_to_impersonate = 'admin#testpr.com';
$cred = new Google_Auth_AssertionCredentials(
'number#developer.gserviceaccount.com',
array('https://www.googleapis.com/auth/drive'), ****//this here has to be drive not drive.file
$key,
'notasecret',
'http://oauth.net/grant_type/jwt/1.0/bearer',
$user_to_impersonate
);
$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion();
}
$originFileId = "longnumber";
$copyTitle = 'copied';
$newfile = copyFile($service, $originFileId, $copyTitle);
print_r($newfile);
function copyFile($service, $originFileId, $copyTitle)
{
$copiedFile = new Google_Service_Drive_DriveFile();
$copiedFile->setTitle($copyTitle);
try {
return $service->files->copy($originFileId, $copiedFile);
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
}
return NULL;
}
?>
so got it working just now, ty all for your time guys really and edited my post to reflect the dang thing
If you want to give the end user access to your drive, you have to give your application authority to make API calls on behalf of a user (in this case you) in your domain. For this you have to set up a service account and generate a p12 key in the Google Developers Console. You have to enter the https://www.googleapis.com/auth/drive API scope in your Admin Console as well.
Full explanation and examples can be found here: https://developers.google.com/api-client-library/php/auth/service-accounts.
To achieve this you also need the Google API's client library: https://github.com/google/google-api-php-client (also mentioned in the Google manual).
Code example to let users make API calls on behalf of one of your accounts: https://developers.google.com/api-client-library/php/guide/aaa_oauth2_service
I have a WCF Service written in .Net 4.0 that accepts two parameters. One is a complex type consisting of User, MerchantName, and Password, the second variable is an int. The service returns a third complex type.
It's structure looks like the following:
//*C# Code *
public sub AccountData Log(Login LoginData, int AccountID)
{
//do stuff here
}
Using SoapClient and removing the int AccountID from the C# service, I can pass the complex data in and parse through the complex data output succesfully. Adding the AccountID parameter, breaks the soap call. I can't seem to compound the variables into one array in a fashion that WCF will accept.
The question is how to form the array to pass in the call?
I have tried the following:
//****Attempt one *******
$login = array('MerchantName' => 'merchantA',
'User' => 'userA',
'password' => 'passwordA');
$account = '68115'; //(also tried $account = 68115; and $account = (int)68115;)
$params = array('LoginData' => $login, 'AccountID' => $account);
$send = (object)$params; //Have tried sending as an object and not.
$client = new SoapClient($wsdl);
$client->soap_defencoding = 'UTF-8';
$result = $client->__soapCall('Log', array($send);
var_dump($send);
echo("<pre>");
var_dump($result);
The latest attempt was to class the variables but I got stuck when tring to form into the $client call.
class LogVar
{
public $MerchantName;
public $User;
public $Password;
}
class AccountID
{
public $AccountID;
}
$classLogin = new LogVar();
$classLogin->MerchantName = 'merchantA';
$classLogin->User = 'userA';
$classLogin->Password = 'passwordA';
$classAccount = new AccountID();
$classAccount->AccountID = '68115';
//How to get to $client->__soapCall('Log', ???????);
P.S. I'm a .Net coder, please be kind with the PHP explanations... Also NuSoap didn't seem much better, however it may have undiscovered ways of dealing with complex types.
This worked for me with standard SoapClient:
$client = new SoapClient($wsdl, array('trace' => true));
$data = $client->Log(array('AccountID' => 23, 'LoginData' => array('User' => '123', 'Password' => '123', 'MerchantName' => '123')));
// echo $client->__getLastRequest();
var_dump($data);
You can display the last request XML and compare it with what a WCF client is generating. This is how I figured it out: I generated a WCF client, inspected the XML message generated by it and compared to $client->__getLastRequest.
Note: You can call the method by its name on a SoapClient rather than use $client->__soapCall('operationName')
I've got the basic idea covered (I think), but can't seem to successfully post anything using Facbook's provided PHP class. Given this example, can anyone see anything that might be the problem?
// Initialize Facebook API
$fb = new Facebook(array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_SECRET,
'cookie' => true
));
if($fb->getSession()) {
$res = $fb->api('/me/feed/', 'post', array(
'message' => 'test message',
'description' => 'testing'
));
}
var_dump($res);
When I output the contents of $res I get a face-palming NULL. Any ideas? If the above looks correct, can anyone suggest some things I might try to debug this?
In your app, when you check to see if the user is logged into Facebook, make sure you are confirming that your app requested the 'special privilege' of posting to the user's wall. You can do this by modifying your code as follows:
$url = $this->facebook->getLoginUrl(array('canvas' => 1, 'fbconnect' => 0, 'req_perms' => 'user_status,publish_stream'));
Note the req_perms key being set to a list of values including 'publish_stream'. If you don't have this privilege the feed call will fail.
Also whether this is really the problem or not, you can wrap your Facebook requests with a try-catch block to catch FacebookApiException type exceptions to get more information when you have errors. For example:
try {
$uid = $this->facebook->getUser();
$me = $this->facebook->api('/me');
} catch (FacebookApiException $e) {
print_r($e);
}
I need to connect to a web service that requires authentication credentials in the form of a plain text user name and password.
I have a basic understanding of SOAP and have managed to connect to other open web services that do not require a username or password using NuSOAP.
The following was sent to me:
<?php
// Set up security options
$security_options = array("useUsernameToken" => TRUE);
$policy = new WSPolicy(array("security" => $security_options));
$security_token = new WSSecurityToken(array(
"user" => "xxx",
"password" => "xxx",
"passwordType" => "basic"));
// Create client with options
$client = new WSClient(array("wsdl" => "https://xxx.asmx?wsdl",
"action" => "http://xxx",
"to" => "https://xxx",
"useWSA" => 'submission',
"CACert" => "cert.pem",
"useSOAP" => 1.1,
"policy" => $policy,
"securityToken" => $security_token));
// Send request and capture response
$proxy = $client->getProxy();
$input_array = array("From" => "2010-01-01 00:00:00",
"To" => "2010-01-31 00:00:00");
$resMessage = $proxy->xxx($input_array);
?>
After some research I understand that the above implementation uses wso2. I need to be able to do this without using wso2.
I have tried my best to look for resources (Google, forums, etc) about the above but haven't been able to find anything. I have read some tutorials on SOAP and have been able to set up a SOAP client using PHP but cannot get my head around all the authentication and "policies".
An explanation of how to achieve this and maybe some links to further reading about this would be very much appreciated as I am tearing my hair out! Ideally I would like some links to resources for an absolute beginner to the SOAP authentication.
Thanks. P.S some of the links/credentials in the above could have been xxx'd for privacy.
If you have the SOAP extension enabled in php (php version >= 5.0.1), you can use the SoapClient class to process your request. To authenticate, you can pass the username and password to the class with the target URL:
$soapURL = "https://www.example.com/soapapi.asmx?wsdl" ;
$soapParameters = Array('login' => "myusername", 'password' => "mypassword") ;
$soapFunction = "someFunction" ;
$soapFunctionParameters = Array('param1' => 42, 'param2' => "Search") ;
$soapClient = new SoapClient($soapURL, $soapParameters);
$soapResult = $soapClient->__soapCall($soapFunction, $soapFunctionParameters) ;
if(is_array($soapResult) && isset($soapResult['someFunctionResult'])) {
// Process result.
} else {
// Unexpected result
if(function_exists("debug_message")) {
debug_message("Unexpected soapResult for {$soapFunction}: ".print_r($soapResult, TRUE)) ;
}
}
If you're not sure about the functions you can call, you can view the target URL (e.g. ending in ".asmx?wsdl") in your browser. You should get an XML response that tells you the available SOAP functions you can call, and the expected parameters of those functions.
Check out the soap_wsse library