So i have the following web service that is found on
http://screencast.com/t/y8qM8hRDu
These are my trials and results:
Try 1:
$api_target = "http://www.xyz.co/service1.svc?wsdl"
$soap_options["location"] = $api_target;
$soap_options['trace'] = TRUE;
$soap_options['cache_wsdl'] = WSDL_CACHE_NONE;
$soap_options['style'] = SOAP_RPC;
$soap_options['use'] = SOAP_ENCODED;
$soap_options['soap_version'] = SOAP_1_2;
$client = new SoapClient($api_target,$soap_options);
$result = $client->Login(array("parameters" => $user));
Response 1:
The SOAP action specified on the message, '', does not match the HTTP SOAP Action, 'http://tempuri.org/IService1/Login'.
Try 2: added SOAPaction header
$actionHeader = new SoapHeader($api_target,'SOAPAction','http://tempuri.org/IService1/Login');
$client->__setSoapHeaders($actionHeader);
$client = new SoapClient($api_target,$soap_options);
$result = $client->Login(array("parameters" => $user));
Response 2::
Bad Request
What am i doing wrong here?
By some unexplained miracle i got it working, if it helps anyone here is the revises code
$api_target = "http://www.xyz.co/service1.svc";
$api_url = $api_target."?wsdl";
$action = "http://tempuri.org/IService1/Login";
$soap_options["location"] = $api_target;
$soap_options["uri"] = $api_url;
$soap_options['trace'] = TRUE;
$soap_options['cache_wsdl'] = WSDL_CACHE_NONE;
$soap_options['style'] = SOAP_DOCUMENT;
$soap_options['use'] = SOAP_LITERAL;
$soap_options['soap_version'] = SOAP_1_2;
$actionHeader[] = new SoapHeader('http://www.w3.org/2005/08/addressing','Action',$action , true);
$actionHeader[] = new SoapHeader('http://www.w3.org/2005/08/addressing','To',$api_target ,true);
$client = new SoapClient($api_url,$soap_options);
$client->__setSoapHeaders($actionHeader);
$result = $client->__soapCall('Login',array($user));;
Related
I'll try to forward a mail with php-ews, but can't get it to work.
I have read the documentation for XML EWS
https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-respond-to-email-messages-by-using-ews-in-exchange
but I'll guess I've missed something.
$request = new CreateItemType();
$request->MessageDisposition = MessageDispositionType::SEND_AND_SAVE_COPY;
$request->Items = new NonEmptyArrayOfAllItemsType();
$request->Items->ForwardedItem = new ForwardItemType();
$request->Items->ForwardedItem->ToRecipients = new MessageType();
$request->Items->ForwardedItem->ToRecipients->Mailbox = new EmailAddressType();
$request->Items->ForwardedItem->ToRecipients->Mailbox->MailboxName = 'Foo Bar';
$request->Items->ForwardedItem->ToRecipients->Mailbox->MailboxAddress = 'Foo#Bar.com';
$request->Items->ForwardedItem->ReferenceItemId = new ItemIdType();
$request->Items->ForwardedItem->ReferenceItemId->Id = 'AAMk.....AAA=';
$request->Items->ForwardedItem->ReferenceItemId->ChangeKey = 'CQAA.....GOP';
$request->Items->ForwardedItem->NewBodyContent = new BodyContentType();
$request->Items->ForwardedItem->NewBodyContent->Value = 'Test';
$request->Items->ForwardedItem->NewBodyContent->BodyType = BodyTypeType::HTML;
The error message I'll get is:
Fatal error: Uncaught SoapFault exception: [a:ErrorInvalidRequest] Id
must be non-empty.
This doesn't look right
$request->Items->ForwardedItem->ToRecipients = new MessageType();
$request->Items->ForwardedItem->ToRecipients->Mailbox = new EmailAddressType();
$request->Items->ForwardedItem->ToRecipients->Mailbox->MailboxName = 'Foo Bar';
$request->Items->ForwardedItem->ToRecipients->Mailbox->MailboxAddress = 'Foo#Bar.com';
ToRecipients should be an array of recipient types so i think it should be
$request->Items->ForwardedItem->ToRecipients = new ArrayOfRecipientsType();
$recipient = new EmailAddressType();
$recipient->Name = 'Homer Simpson';
$recipient->EmailAddress = 'hsimpson#example.com';
$request->Items->ForwardedItem->ToRecipients->Mailbox[] = $recipient;
I'm using this composer package https://github.com/basvandorst/StravaPHP
The OAUTH is working fine and its generating me the JSON with the access token and user id, etc..
But whenever I try to use other function it returns me 404 not found.
Output is this :
{"token_type":"Bearer","access_token":"077058e0c800881c72a4b10a04a520d5898d4e3e","athlete":{"id":35670467,"username":"amir_do","resource_state":2,"firstname":"Amir","lastname":"Do","city":null,"state":null,"country":null,"sex":"M","premium":false,"summit":false,"created_at":"2018-10-13T13:55:41Z","updated_at":"2018-10-13T13:56:25Z","badge_type_id":0,"profile_medium":"https://lh5.googleusercontent.com/-ku6v9lKNgYY/AAAAAAAAAAI/AAAAAAAAAAA/ABtNlbASj8KhClhwnVYVqRrEG2oiYzWPbA/mo/photo.jpg","profile":"https://lh5.googleusercontent.com/-ku6v9lKNgYY/AAAAAAAAAAI/AAAAAAAAAAA/ABtNlbASj8KhClhwnVYVqRrEG2oiYzWPbA/mo/photo.jpg","friend":null,"follower":null,"email":"goncalomaia97#gmail.com"}}
35670467
Client error: `GET https://www.strava.com/api/athletes/35670467/stats?access_token=077058e0c800881c72a4b10a04a520d5898d4e3e` resulted in a `404 Not Found` response: {"message":"Record Not Found","errors":[{"resource":"resource","field":"path","code":"invalid"}]}
And this is my current callback.php page code:
<?php
include 'vendor/autoload.php';
use Strava\API\Client;
use Strava\API\Exception;
use Strava\API\Service\REST;
session_start();
$client = new GuzzleHttp\Client();
global $connect;
require_once("configs/database.php");
$connect = new mysqli($config['database']['host'],$config['database']['user'],$config['database']['pass'],$config['database']['db']);
$code = $_GET['code'];
$state = $_GET['state'];
$scope = $_GET['scope'];
$user = $_SESSION['username'];
$check = $connect->query("SELECT * FROM users WHERE email = '$user'");
$fetch = $check->fetch_array(MYSQLI_ASSOC);
$apix = $fetch['api'];
$api_secretx = $fetch['api_secret'];
$client = new GuzzleHttp\Client();
$data = [
"client_id" => $apix,
"client_secret" => $api_secretx,
"code" => $code
];
$result = $client->post('https://www.strava.com/oauth/token', ['json' => $data]);
print "<pre>";
print_r( $result->getBody()->getContents() );
print "</pre>";
$bodyb = $result->getBody();
$varx = json_decode((string) $bodyb, true);
$token = $varx['access_token'];
$id = $varx['athlete']['id'];
$_SESSION['token'] = $token;
printf($id);
try {
// REST adapter (We use `Guzzle` in this project)
$adapter = new \GuzzleHttp\Client(['base_uri' => 'https://www.strava.com/api/v3']);
// Service to use (Service\Stub is also available for test purposes)
$service = new \Strava\API\Service\REST($token, $adapter);
// Receive the athlete!
$client = new Client($service);
$athlete = $client->getAthleteStats($id);
print_r($athlete);
} catch(Exception $e) {
print $e->getMessage();
}
$adapter = new \GuzzleHttp\Client(['base_uri' => 'https://www.strava.com/api/v3']);
Change that to this (It should be trailing) :
$adapter = new \GuzzleHttp\Client(['base_uri' => 'https://www.strava.com/api/v3/']);
I want to communicate with an installation of Moodle 2.9.
The following sample client is a slight modification of:
https://github.com/moodlehq/sample-ws-clients/blob/master/PHP-REST/client.php
to use Unirest instead of Curl and JSON instead of XML:
$token = 'd1c74d6466daaaaad59b5d99906bfc84';
$domainname = 'http://moodle.example.com';
$functionname = 'core_user_create_users';
// REST RETURNED VALUES FORMAT
$restformat = 'json';
$user1 = new \stdClass();
$user1->username = 'testusername1';
$user1->password = 'testpassword1';
$user1->firstname = 'testfirstname1';
$user1->lastname = 'testlastname1';
$user1->email = 'testemail1#moodle.com';
$user1->auth = 'manual';
$user1->idnumber = 'testidnumber1';
$user1->lang = 'en';
$user1->theme = 'standard';
$user1->timezone = '-12.5';
$user1->mailformat = 0;
$user1->description = 'Hello World!';
$user1->city = 'testcity1';
$user1->country = 'au';
$preferencename1 = 'preference1';
$preferencename2 = 'preference2';
$user1->preferences = array(
array('type' => $preferencename1, 'value' => 'preferencevalue1'),
array('type' => $preferencename2, 'value' => 'preferencevalue2'));
$user2 = new \stdClass();
$user2->username = 'testusername2';
$user2->password = 'testpassword2';
$user2->firstname = 'testfirstname2';
$user2->lastname = 'testlastname2';
$user2->email = 'testemail2#moodle.com';
$user2->timezone = 'Pacific/Port_Moresby';
$users = array($user1, $user2);
$params = array('users' => $users);
/// REST CALL
$serverurl = $domainname . '/webservice/rest/server.php' . '?wstoken=' . $token . '&wsfunction=' . $functionname;
//if rest format == 'xml', then we do not add the param for backward compatibility with Moodle < 2.2
$restformat = ($restformat == 'json') ? '&moodlewsrestformat=' . $restformat : '';
$headers = array('Accept' => 'application/json');
$response = UnirestRequest::post($serverurl . $restformat, $headers, json_encode($params));
On execution I got an error:
"Notice: Array to string conversion"
, allegedly because of the parameters going in the body. So, I figured I had to serialize the body before sending it, but when I tried:
$response = UnirestRequest::post($serverurl . $restformat, $headers, json_encode($params));
I got back from Moodle:
{"exception":"invalid_parameter_exception","errorcode":"invalidparameter","message":"Detectado
valor de par\u00e1metro no v\u00e1lido","debuginfo":"Missing required
key in single structure: users"} ◀"
There must be something I'm not understanding about how exactly the POST request must look like. Any suggestion?
Moodle expects the body of the post to be URL encoded, so your body must be built
using http_build_query($params) (or any other method to encode your data) such as:
$convertedpostdata = implode('&', $params);//where $params is an array
As far as why, I dont really recall, I remember struggling with an implementation a while ago, you can view
[your_moodle_installation.com]/admin/webservice/documentation.php for more documentation, additionally you here's an example of what I did:
https://gist.github.com/Scott972/5d9e9495c1397a2ad728b66288ce1d42
I'm building bigcommerce APP. But I cannot get "AuthToken". Please help. See full code below. Also attached image with NULL response.
require_once($_SERVER['DOCUMENT_ROOT'].'/config.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php');
use Bigcommerce\Api\Client as Bigcommerce;
$object = new \stdClass();
$object->client_id = BC_CLIENT_ID;
$object->client_secret = BC_CLIENT_SECRET;
$object->redirect_uri = 'https://yourwebsiteurl.com/oauth.php';
$object->code = $_GET['code'];
$object->context = $_GET['context'];
$object->scope = $_GET['scope'];
$authTokenResponse = Bigcommerce::getAuthToken($object);
I have problem with Osuuspankki Webservice. I managed to get Certificate but when i need to get data from Bank there is few problems.
function getArgumentsToDownload($customerid=null,$private_key=null, $public_key=null,$status="NEW",$action=null,$start_date=null,$end_date=null) {
$xml = $this->createDocument();
$ApplicactionRequest = $xml->createElement("ApplicationRequest");
$ApplicactionRequest->setAttribute("xmlns", "http://bxd.fi/xmldata/");
$CustomerId = $xml->createElement("CustomerId",$customerid);
$ApplicactionRequest->appendChild($CustomerId);
$Timestamp = $xml->createElement("Timestamp",date("c"));
$ApplicactionRequest->appendChild($Timestamp);
$Status = $xml->createElement("Status",$status);
$ApplicactionRequest->appendChild($Status);
$Environment = $xml->createElement("Environment",$this->Environment);
$ApplicactionRequest->appendChild($Environment);
$SoftwareId = $xml->createElement("SoftwareId",$this->SoftwareId);
$ApplicactionRequest->appendChild($SoftwareId);
$xml->appendChild($ApplicactionRequest);
$objDSig = new XMLSecurityDSig();
$objDSig->setCanonicalMethod(XMLSecurityDSig::EXC_C14N_COMMENTS);
$objDSig->addReference($xml, XMLSecurityDSig::SHA1, array('http://www.w3.org/2000/09/xmldsig#enveloped-signature'));
$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, array('type'=>'private'));
//$objKey->loadKey($private_key,true);
$objKey->loadKey($private_key,true);
$objDSig->sign($objKey);
$objDSig->add509Cert(file_get_contents($public_key),false);
$objDSig->appendSignature($xml->documentElement);
$signed_XML = $xml->saveXML();}
`
I Can sign Env body but it needed to sign again to Env-header.
https://www.op.fi/media/liitteet?cid=151240134&srcpl=4 (page 22/44).
public function getFileList($username=null, $private_key=null, $public_key=null,$status='NEW',$start_date=null, $end_date=null) {
// Alustetaan muuttujat joita käytetään SOAP Clientissä datan lataamisessa Webservicestä.
$arguments = $this->CI->getArgumentsToDownload($username,$private_key,$public_key);
$client = new SoapClient($this->wsdl_test, array('trace' => true, 'exceptions' => false));
// Asetetaan salainen avain
$client->setPrivateKey($private_key);
// Asetetaan julkinen avain
$client->setPublicKey($public_key);
$soap_header = new SoapHeader($this->ws_ns, "Timestamp",array("expires"));
$client->__setSoapHeaders($soap_header);
$return = $client->__soapCall('downloadFileList', array($arguments));
}
What should i do that i get signed Envelope?