I try to logon Affili.net via SOAP by using the savon-gem.
client = Savon.client do
wsdl "https://api.affili.net/V2.0/Logon.svc?wsdl"
end
message = {
'Username' => '123123',
'Password' => '123123',
'ins2:WebServiceType' => 'Publisher' }
response = client.call(:logon, :message => message)
But I only get this exception:
(a:DeserializationFailed) The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://affilinet.framework.webservices/Svc:LogonRequestMsg. The InnerException message was 'Error in line 1 position 777. 'EndElement' 'LogonRequestMsg' from namespace 'http://affilinet.framework.webservices/Svc' is not expected. Expecting element 'Username | Password | WebServiceType'.'. Please see InnerException for more details.
https://developer-api.affili.net/V2.0/Logon.svc?wsdl
Whats wrong?
Update
Now i tried some tools like this:
http://www.soapclient.com/soapclient?template=%2Fclientform.html&fn=soapform&SoapTemplate=%2FSoapResult.html&SoapWSDL=https%3A%2F%2Fdeveloper-api.affili.net%2FV2.0%2FLogon.svc%3Fwsdl&_ArraySize=2
And it also tells me: it does not work. But my Account and that credentials are ok!
So I tried it on PHP
define ("WSDL_LOGON", "https://api.affili.net/V2.0/Logon.svc?wsdl");
define ("WSDL_STATS", "https://api.affili.net/V2.0/PublisherStatistics.svc?wsdl");
$Username = '123123'; // the publisher ID
$Password = '123123'; // the publisher web services password
$SOAP_LOGON = new SoapClient(WSDL_LOGON);
$Token = $SOAP_LOGON->Logon(array(
'Username' => $Username,
'Password' => $Password,
'WebServiceType' => 'Publisher'
));
echo $Token;
and it works!
Whats the difference between all online tools, all offline tools and Ruby on Rails and PHP?
Try to send message with symbolized keys, like this:
message = {
logon: {
username: '123123',
password: '123123',
web_service_type: 'Publisher'
}
}
I still do not know the difference between the savon (2.7.2) and the PHP implementation.
But there is a solution for affili.net by using savon 3 (but it is not stable yet!)
client = Savon.new("https://api.affili.net/V2.0/Logon.svc?wsdl")
logon_body = {
LogonRequestMsg: {
'Username' => '123123',
'Password' => '123123',
'WebServiceType' => 'Publisher'
}
}
operation = client.operation('Authentication', 'DefaultEndpointLogon', 'Logon')
operation.body = logon_body
response = operation.call
puts response.body[:credential_token]
Some Savon 3 Documentation: http://savonrb.com/version3/getting-started.html
And the github branch: https://github.com/savonrb/savon/tree/version3
Related
As with most people, Microsoft are turning off basic authentication. This means we need to use Modern Auth to retrieve emails from a mailbox.
However,when we retrie the access token fails with "
Client error: `POST https://login.microsoftonline.com/aea9a7d8-73fb-41af-987b-6fe14277421e/oauth2/v2.0/token` resulted in a `400 Bad Request` response:\n
{"error":"unauthorized_client","error_description":"AADSTS700016: Application with identifier '\"014438b9-82dc-4a4c-9584 (truncated...)
"
Here is the code we have for retrieving and connecting to IMAP. I am passing actual email and password in usename and password field
/* Get the access Token */
$Secret = '**REMOVED**';
$AppID = '**REMOVED**';
$TenantID = '**REMOVED**';
$AccessToken = '';
try {
$guzzle = new \GuzzleHttp\Client(['headers' => ['User-Agent' => 'App-Token-Request']]);
$url = 'https://login.microsoftonline.com/'.$TenantID.'/oauth2/v2.0/token';
$token = json_decode($guzzle->post($url, [
'form_params' => [
'grant_type' => 'password',
'client_id' => $AppID,
'client_secret' => $Secret,
'scope' => 'https://graph.microsoft.com/.default', //'https://outlook.office365.com/IMAP.AccessAsUser.All',// 'https://graph.microsoft.com/.default',
'username' => '**REMOVED**',
'password' => '**REMOVED**',
],
])->getBody()->getContents());
$this->info(var_dump($token));
$AccessToken = $token->access_token;
} catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
dd($e);
return redirect('/')->with('error', 'Error requesting access token')->with('errorDetail', json_encode($e->getResponseBody()));
}
***** RESPONSE: Net::HTTPOK -> {"status":"Success","primary_language":"notsure","PortalID":"1017","newContact":{"attributes":{"type":"Contact","url":"/services/data/v31.0/sobjects/Contact/003f000000goEpIAAU"},"Primary_Language_Master__c":"notsure","npe01__Preferred_Email__c":"Personal","Country_of_Birth_Master__c":"argentina","npe01__HomeEmail__c":"john.smith1228+689#gmail.com","RecordTypeId":"012i0000000Ng8uAAC","Portal_ID__c":1017,"FirstName":"John","Id":"003f000000goEpIAAU","LastName":"Smith", "High_School_Graduation_Year__c":"2007"},"message":"Create was created successfully.","lastname":"Smith","high_school_graduation_year":2007,"firstname":"John","email":"john.smith1228+689#gmail.com","country_of_residence":"argentina","ContactID":"003f000000goEpIAAU"}
The above is a response getting returned after I use the databasedotcom gem to interact with salesforce. I am trying to collect the contactid into my users table after a successfuly response.
Below is the method that I am pushing with
def salesforce_add_contact
client = Databasedotcom::Client.new("config/databasedotcom.yml")
client.authenticate(:username => "secret", :password => "secret" )
params = { :PortalID => current_user.id.to_s,
:firstname => current_user.first_name,
:lastname => current_user.last_name,
:email => current_user.email,
:country_of_residence => current_user.country_of_residence,
:primary_language => current_user.primary_language,
:high_school_graduation_year => current_user.high_school_graduation_year}
params = ActiveSupport::JSON.encode(params)
path = "/services/apexrest/v2/portalAccount"
result = client.http_post(path, params)
result = ActiveSupport::JSON.decode(result.body)
puts result.body #just added
if (response['status'] == "Success") #this didn't work
current_user.sfdc_contact_id = response['ContactId']
current_user.sfdc_contact_id.save
end
end
I am not totally understanding the syntax from the response and what kind of data structure is getting returned either....
I am trying to collect this "ContactID":"003f000000goEpIAAU"
Updated
I am getting NoMethodError (undefined methodbody' for #):`
when I do a puts result.body so I guess its not reading it correctly.
It looks you misnamed the variable that contains the decoded JSON response. You have:
result = ActiveSupport::JSON.decode(result.body)
Which should be:
response = ActiveSupport::JSON.decode(result.body)
I am using savon gem for accessing abc financial web services. I am getting error message user not authorize. I am using this code for accessing response
#wsdl="https://webservice.abcfinancial.com/wsdl/Prospect.wsdl"
#basic_auth=["user","pass"]
#headers={"Authorization" => "Basic"}
#client = Savon.client do |globals|
globals.wsdl #wsdl
globals.basic_auth #basic_auth
globals.headers #headers
end
#message = {
:clubNumber=> 'Club 0233',
:firstName=> 'abc',
:lastName=> 'def',
:gender=> "male"
}
response = #client.call(:insert_prospect, message: #message)
and I am getting an error message user not authorize. I searched it but didn't find any solution. Please help me.
They are using JAX-WS.
According to this article http://examples.javacodegeeks.com/enterprise-java/jws/application-authentication-with-jax-ws/ (and google) we should use login-password in http headers.
I don't have an account on the http://abcfinancial.com so I can't test the code.
Try it:
require 'savon'
user = 'myLogin'
password = 'myPassword'
client = Savon.client(
wsdl: 'https://webservice.abcfinancial.com/wsdl/Prospect.wsdl',
headers: {username: user,
password: password},
pretty_print_xml: true,
log: true
)
message = {
:arg0 => {
clubNumber: 'Club 0233',
:personal => {
:firstName => 'myName',
:lastName => 'myLastName',
:gender => 'male'
}
}
}
response = client.call(:insert_prospect, message: message)
Read this good article http://predic8.com/wsdl-reading.htm and turn on debugging (pretty_print_xml: true, log: true).
In regards to using SOAP to connect to Sugar CRM, the documentation for Sugar 6.1 Community Edition states:
"See /examples/SugarFullTest_Version2.php for more examples on usage."
source:
http://developers.sugarcrm.com/docs/OS/6.1/-docs-Developer_Guides-Sugar_Developer_Guide_6.1.0-Chapter%202%20Application%20Framework.html#9000244
This file is not in the examples folder. Where is it?
If this file does not exist, where can I find a working example of connecting to Sugar CRM with SOAP? None of the test scripts in the /examples/ folder work.
Couldn't find the file either, so made an example (PHP script connecting to sugarCRM v6 SOAP) for you.
<?php
require_once('include/nusoap/lib/nusoap.php');
$myWsdl = 'http://mysite.com/soap.php?wsdl';
$myAuth = array(
'user_name' => 'xxxx',
'password' => MD5('xxxx'),
'version' => '0.1'
);
$soapClient = new nusoap_client($myWsdl,true);
// Create lead
// (Can be made without login, i.e. sessionid)
$leadParams = array('user_name' => 'xxxx',
'password' => MD5('xxxx'),
'first_name' => 'Test',
'last_name' => '2',
'email_address' => '2#'
);
$leadResult = $soapClient->call('create_lead', $leadParams);
$leadId = $leadResult;
print_r($leadResult);
// Login
$loginParams = array('user_auth' => $myAuth, 'application_name' => 'WebForm');
$loginResult = $soapClient->call('login', $loginParams);
$sessionId = $loginResult['id'];
// Modules
// (Need login, so sessionID is used)
$modulesResult = $soapClient->call('get_available_modules', array('session' => $sessionId));
print_r($modulesResult);
// Get account list
$accountParams = array('session' => $sessionId,
'module_name' => 'Accounts',
'query' => "accounts.name = 'Amarelo'",
'order_by' => '',
'deleted' => 0
);
$accountResult = $soapClient->call('get_entry_list', $accountParams);
print_r($accountResult);
// Get entry
$leadParams = array('session' => $sessionId,
'module_name' => 'Leads',
'id' => "$leadId"
);
$leadResult = $soapClient->call('get_entry', $leadParams);
print_r($leadResult);
// Logout
$logoutResult = $soapClient->call('logout', array('session' => $sessionId));
?>
For debugging and testing SoapUI is very helpful.
I'm really having a difficult time trying to find a way to successfully authenticate a user and post a bookmark to their delicious account.
I downloaded Yahoo's YOS Social SDK then began modifying the oauth sampleapp.php. It basically handles the oAuth process by creating a login link that sends you to Yahoo to grant permission then sends you back to the callback URL you specify.
My thought was to modify the sampleapp.php file to make a request to delicious posts/add API to add a new bookmark once they oAuth process is over, but I'm running into some problems. I think I'm handling the POST request in the wrong manner.
Here is my code:
<?php
require dirname(__FILE__).'/lib/Yahoo.inc';
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', true);
YahooLogger::setDebug(true);
YahooLogger::setDebugDestination('LOG');
ini_set('session.save_handler', 'files');
session_save_path('/tmp/');
session_start();
define('OAUTH_CONSUMER_KEY', '<YOURS_GOES_HERE>');
define('OAUTH_CONSUMER_SECRET', '<YOURS_GOES_HERE>');
define('OAUTH_DOMAIN', '<YOURS_GOES_HERE>');
define('OAUTH_APP_ID', '<YOURS_GOES_HERE>');
if(array_key_exists("logout", $_GET)) {
YahooSession::clearSession();
header("Location: sampleapp.php");
}
$hasSession = YahooSession::hasSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID);
if($hasSession == FALSE) {
$callback = YahooUtil::current_url();
$auth_url = YahooSession::createAuthorizationUrl(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $callback);
}
else {
$session = YahooSession::requireSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID);
if($session) {
$consumer = new stdclass();
$consumer->key = OAUTH_CONSUMER_KEY;
$consumer->secret = OAUTH_CONSUMER_SECRET;
$nativeSession = new NativeSessionStore();
$token = $nativeSession->fetchAccessToken();
$client = new OAuthClient($consumer, $token, OAUTH_PARAMS_IN_HEADERS, OAUTH_SIGNATURE_HMAC_SHA1);
$request_url = 'http://api.del.icio.us/v2/posts/add';
$bookmark_url = 'http://www.tegdesign.com';
$parameters = array("url" => urlencode($bookmark_url), "description" => "test");
$response = $client->post($request_url,'TEXT',$parameters);
echo '<pre>';
print_r($response);
echo '</pre>';
}
}
if($hasSession == FALSE) {
echo sprintf("Login\n", $auth_url);
} else if($hasSession) {
echo "<p>Logout</p>";
}
?>
And here is the output of $response variable:
Array
(
[method] => POST
[url] => http://api.del.icio.us/v2/posts/add
[code] => 401
[requestHeaders] => Array
(
[0] => Accept: application/json
[1] => Authorization: OAuth realm="yahooapis.com",oauth_version="1.0",oauth_nonce="<MINE_SHOWS_HERE>",oauth_timestamp="1289407587",oauth_consumer_key="<MINE_SHOWS_HERE>",oauth_token="<MINE_SHOWS_HERE>",oauth_signature_method="HMAC-SHA1",oauth_signature="<MINE_SHOWS_HERE>"
[2] => Content-Type: TEXT
)
[requestBody] => Array
(
[url] => http%3A%2F%2Fwww.tegdesign.com
[description] => test
)
[responseHeaders] => Array
(
[Date] => Wed, 10 Nov 2010 16:46:32 GMT
[WWW-Authenticate] => OAuth oauth_problem="signature_invalid", realm="yahooapis.com"
[Content-Type] => application/json
[Cache-Control] => private
[Age] => 0
[Transfer-Encoding] => chunked
[Connection] => keep-alive
[Server] => YTS/1.17.21
)
[responseBody] => {"error":{"lang":"en-US","description":"Please provide valid credentials"}}
)
Does anybody have knowledge on using Delicious new API to successfully authenticate and post a bookmark on behalf a user? I'm having a terrible time.
Thanks,
Tegan
Set your content type to "application/x-www-form-urlencoded" instead of 'Text' on the below line.
$response = $client->post($request_url,'TEXT',$parameters);