I have a web-service.
I try to create a Soap Client in php like this:
<?php
$client = new SoapClient("link.svc?wsdl",array("trace"=>1,"exceptions"=>0));
print_r($client);
$parameters = array("request"=>array("function" => "request1"));
$values = $client->FindSomething($parameters);
print_r($values);
?>
and then use std_Object Class.
I try in this way, but I know there are other ways to create a client and obtain data (eg. in Json Rest).
This is the first time I do this. If someone already has experience, can give me an example of request (in json or php, does not matter)? Thank you in advance!
Related
Issue
I'm trying to build a little script PHP to integrate with the Microsoft Graph API.
I have an admin account in Azure, and have set up a new app through the portal. I've downloaded and installed the PHP SDK, and have managed to set everything up so that I can get a user successfully.
However, POSTing a new user returns me a 400 bad request:
$newUser = new User();
$newUser->setAccountEnabled(true);
$newUser->setGivenName('name');
$newUser->setSurname('surname');
$newUser->setUserPrincipalName('email#dot.com');
$password = new PasswordProfile();
$password->setPassword("pwd");
$password->setForceChangePasswordNextSignIn(false);
$newUser->setPasswordProfile($password);
$identities = new ObjectIdentity();
$identities->setSignInType("emailAddress");
$identities->setIssuer("a tenantId");
$identities->setIssuerAssignedId("email#dot.com");
$newUser->setIdentities($identities);
$user = $this->graph->createRequest('POST', '/users')
->attachBody($newUser)
->setReturnType(Model\User::class)
->execute();
Returns:
{"error":{"code":"BadRequest","message":"Property identities in payload has a value that does not match schema.","innerError":{"date":"2021-11-15T15:26:24","request-id":"an id","client-request-id":"an id"}}}
How can I solve this issue?
Thanks for any help.
Update
I have found a solution for this problem (obviously, is temporary).
The section "identities" must be set as an array (in JSON) like in this example
"identities": [
{
"signInType": "emailAddress",
"issuer": "contoso.onmicrosoft.com",
"issuerAssignedId": "jsmith#yahoo.com"
}
]
Probably, the PHP code above not set the section "identities" as an array.
Now, I send directly a JSON with the section "identities" as an array but I would like to use the PHP code above.
How can I transform the PHP code above to pass "identities" as an array like in the JSON example?
Thanks again.
Try creating an array and adding the identities on there like. This will add the identities property as an array of Model\ObjectIdentity()
...
$identities = [];
$identity = new Model\ObjectIdentity();
$identity->setSignInType("type");
$identity->setIssuer("issuer");
$identity->setIssuerAssignedId("issure-assigned-id");
array_push($identities, $identity);
$newUser->setIdentities($identities);
...
Ensembl is a collection of genome database and annotation source for many eukaryotic genome. They have created REST API interface for user to access their data. http://rest.ensembl.org/. Also, provide detailed steps to write our own client ( perl, python etc.). I am learning PHP and hence would like to write PHP client, any suggestion will be helpful. Are there any libraries or class that I can use to effectively implement the client and access specific data and display back on html? Below is what I tired so far and work in progress.
$server = "http://grch37.rest.ensembl.org";
$ext = "/vep/human/hgvs/";
$hgvs_notation = "AGT:c.803T>C?content-type=application/json";
# added the application header
$url = $server.$ext.$hgvs_notation;# updated based on comment
$response = file_get_contents($url);
$data = json_decode($response, true);
print_r($data);
I'm a php programmer but I'm new to APIs.
I would like to run a mysql query to get info from an XML document from madmimi.com.
documentation from madmimi.com says
GET http://madmimi.com/audience_lists/lists.xml will return the data I need. I've created a php file and connected to their API using
require(dirname(FILE) . '/MadMimi.class.php');
$mailer = new MadMimi('username', 'password');
but I don't understand how to use GET to connect to the URL and display the XML info?
What do I need to do?
All http api interaction is hidden to you behind their library. You can use it's methods to grab objects, like this to lists:
$mailer->Lists();
There is no complete documentation, but you can read raw code to search urls, described in API for finding appreciated methods.
You can use curl to get the response from the 3rd party api. Have a look at this answer:
https://stackoverflow.com/a/5159513/1369567
Based upon the code in answer given at that link, you may need to the code to match your request. E.g:
/* Script URL */
$url = 'http://madmimi.com/audience_lists/lists.xml';
/* $_GET Parameters to Send */
$params = array('username' => '*your api username*', 'password' => '*your api password*');
I would like to create a SOAP Web service for the followıng wsld
http://www.webservicex.com/CurrencyConvertor.asmx?WSDL
Could you please explain how to do this?
The following code is not working... Please help me..
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient("http://www.webservicex.com/CurrencyConvertor.asmx?wsdl");
$CURR = array("FromCurrency" => "USD","ToCurrency" => "INR");
$scramble = $client->ConversionRate($CURR);
$mirror = $client->ConversionRateResponse($scramble);
Thanks,
Praveen J
Let's start with your client URL:
http://www.webservicex.com/CurrencyConvertor.asmx?wsdl
This is wrong. The ?WDSL URL is NOT the URL you use for CALLING the web service, it is the URL you use to retrieve the WDSL that describes the web service. THis is used by automatic tools to generate a wrapper.
http://www.webservicex.com/CurrencyConvertor.asmx
is the "real" URL that you use to execute operations.
http://www.webservicex.com/CurrencyConvertor.asmx?op=ConversionRate
Has a more invormation on the conversion per se, including the exact parameters with naming you need for the Post and GET operations, including examples.
So, I figured out how to get an access token from Google using the Zend_Oauth library in 1.10. Now lets say I want to get my contacts...
$config = array(
'consumerKey' => 'zzz',
'signatureMethod' => 'HMAC-SHA1',
'consumerSecret' => 'xxx'
);
$token = unserialize($_SESSION['GOOGLE_ACCESS_TOKEN']);
$client = $token->getHttpClient($config);
$client->setMethod(Zend_Http_Client::GET);
// $client->setParameterGet('max-results', '10000');
$gdata = new Zend_Gdata($client);
$gdata->setMajorProtocolVersion(3);
$query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/contacts/default/full');
// $query->MaxResults=100;
$feed = $gdata->getFeed($query);
$feed is a lovely object with 25 contacts. But if I want to get more in a single pull, there doesn't seem to be a way of specifying max results that works.
If I uncomment client->setParameterGet it's ignored. It works if I specify $client->setUri and use $rawdata = client->request() to get the response, but then other issues crop up with handling the feed data that comes back... like getting it into GData for easy handling.
I've tried $feed = $gdata->importString($rawdata->getBody()) but while $rawdata->getBody() returns what seems to be valid XML, $feed->totalResults throws an error, while it wouldn't if I used $gdata->getFeed($query).
If I uncomment $query->MaxResults=100; use $gdata->getFeed($query) Google returns a 401 with "Unknown authorization header".
So is it possibly to specify parameters while using Zend_GData with an Oauth token? Or am I going to have to build my own requests, then use Zend_Feed (or some other XML/Feed dissector) for parsing?
I totally cannot get the whole list of contacts only 25... parameters do not seem to work using Gdata and query like this:
$http = $token->getHttpClient($oauthOptions);
$gdata = new Zend_Gdata($http, 'MY APP');
$gdata->setMajorProtocolVersion(3);
$gdata->getHttpClient()->setRequestScheme(Zend_Oauth::REQUEST_SCHEME_QUERYSTRING);
$query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/contacts/default/full?max-results=10');
$query->setMaxResults(10);
$query->maxResults = 10;
$feed = $gdata->getFeed($query);
so i;m really into finding answers here as well. If either of you gets anything working. please post :-)
thanks
It's a bit tricky mixing a process meant to work with AuthSub with OAuth. I did some digging. So far I can get it to download all my contacts like this...
$client = $token->getHttpClient($config);
$client->setMethod(Zend_Http_Client::GET);
$client->setUri('http://www.google.com/m8/feeds/contacts/default/full/');
$client->setParameterGet('max-results', '10000');
$client->setParameterGet('v','3');
$bfeed = $client->request();
Looks like the primary difference between us is I specify the Feed URL in the $client->setUri('http://www.google.com/m8/feeds/contacts/default/full/'); and set my version differently. But I can get the body() property of $bfeed and it gives me 245k of XML to dissect.
My problem is that when I'm pulling down a single contact's feed via this method, I was getting an error.
I, like you, am trying to figure this out, so please reply with anything that works for you.