I have a php web site. Here I need to implement air ticket searching and booking functionality. In order to do this, I have used a paid API from ARZOO web site... I got all the documentation from ARZOO. I have read the entire doc. The Doc Says
"Accessing this service requires standard SOAP client. SOAP client should authenticate
itself through user name and password. Client should get their IPs registered with
Arzoo and get a user account created. The Arzoo web service provides a service
point URL. Web service clients should post SOAP request message as an attachment
for the desired response. The XML structure of different web services is discussed in
the respective documents."
You can connect to Arzoo XML services with the following test service point URLs:-
FlightAvailability:http://<url>/DOMFlightAvailability?wsdl
I think need to send the request via soap is it?
But in the air availability contains
Example Request Xml
<Request>
<Origin>BOM</Origin>
.............
.............
</Request>
I have used the following code
$post_string.="<Request>";
$post_string.="<Origin>$from</Origin><Destination>$to</Destination>";
........
......
$post_string.="</Request>";
$path = ":http://<url>/DOMFlightAvailability?wsdl";
$ch = curl_init($path);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); //Send the data to the file
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$val = curl_exec($ch);
$headers = curl_getinfo($ch);
$errr=curl_error($ch);
But it's not giving any result.
The documents says
RESPONSE XML:-
The response will be in <arzoo_response> </arzoo_response>. This contains the Request
also.
I don't know SOAP.
I am totally disappointed. Please Help me.
I think I will get an xml response after posting the request. But how I will post my data?
Please reply
Many thanks, if anyone help me, its great appreciable
i also getting error while using SOAP CLIENT but when i use nusoap then they give me result..using this code if u get error like ip/password mismatch then You will call arzoo to verify your clientid and clientpassword
<?php
ini_set('max_execution_time','180');
include 'lib/nusoap.php';
$location_URL ='http://avail.flight.arzoo.com';
$action_URL ='http://demo.arzoo.com/ArzooWS/services/DOMFlightAvailability?wsdl';
$Request = '<Request>
<Origin>BOM</Origin>
<Destination>DEL</Destination>
<DepartDate>2017-02-02</DepartDate>
<ReturnDate>2017-02-02</ReturnDate>
<AdultPax>1</AdultPax>
<ChildPax>0</ChildPax>
<InfantPax>0</InfantPax>
<Currency>INR</Currency>
<Clientid>Given by Arzoo.com</Clientid>
<Clientpassword>Given by Arzoo.com</Clientpassword>
<Clienttype>ArzooFWS1.1</Clienttype>
<Preferredclass>E</Preferredclass>
<mode>ONE</mode>
<PreferredAirline>AI</PreferredAirline>
</Request>';
$clientinfo = array('soap_version'=>SOAP_1_1,
'location' =>$location_URL,
'uri' =>$action_URL,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
'trace' => 1,
);
$client = new nusoap_client('http://demo.arzoo.com/ArzooWS/services/DOMFlightAvailability?wsdl', $clientinfo);
//print_r($client);
$result = $client->call('getAvailability', array($Request));
echo"<pre>";
print_r($result);
$clientInfo =simplexml_load_string(utf8_encode($result));
$flight = $clientInfo->Response__Depart->OriginDestinationOptions->OriginDestinationOption;
$error =$clientInfo->error__tag;
//echo $error;
var_dump($flight);
//exit;
//echo"<pre>";
//print_r($result);
//ECHO $error;
?>
Since they are mentioned standard SOAP client and you are sending the cURL request to the Server that will never give any response.
$location_URL = "http://xx.xxx.xx.xxx/ArzooWS/services/DOMFlightAvailability";
$action_URL ="http://com.arzoo.flight.avail";
$client = new SoapClient('http://xx.xxx.xx.xxx/ArzooWS/services/DOMFlightAvailability?wsdl', array(
'soap_version' => SOAP_1_1,
'location' => $location_URL,
'uri' => $action_URL,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
'trace' => 1,
));
try
{
$result = $client->__call('getAvailability',array($req_int));
$response= htmlentities($result);
}
You can use SOAP1.1 Request.
Related
I need to add some functionality to my site to connect via REST to a provider and exchange data. I've used Postman for several years to test these APIs for myself and customers, but this is the first time I have tried to add the functionality to my site.
I've Googled numerous sites. I tried a few different things. First I tried the league/oauth2-client library. The requests went through without any errors, but all I received back was a response like this.
JSON response = {"status":"400","timeStamp":"2022-01-22T16:21:19+0000","error":{"errorId":"ea7bc74d-21ca-4503-92ad-3a76b05d7554","message":null,"code":"invalid_request","description":"Cannot generate token. Bad request","details":null}}
So I went to look at other examples. I found this nice and simple code from
UC San Diego Example for Client Credentials. I tried it and got the same type of results. "Cannot generate token. Bad request." For now, I like the simple option of the UCSD example if I can make it work.
As I said, I can successfully make this request and use the API all day long in Postman. So I know the Client ID, Client Secret, and URL are correct.
Unfortunately, I don't know how to troubleshoot this in PHP. I looked in the server log and I didn't find any errors. I tried to echo something out to see if I could see what was wrong, but I couldn't get the request to echo to the page. I tried using Fiddler to see if I could find the request with no luck.
Here's where I am right now. Any suggestions for what I am missing?
Thanks in advance for your help!
<?php
$token_url = "https://xxxx.xxxxx.com/services/api/oauth2/token";
$test_api_url = "https://xxxx.xxxxx.com/services/api/x/users/v2/employees/12345";
// client (application) credentials on xxxx.xxxxxx.com
$client_id = "xxxxxxxxxxx";
$client_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$access_token = getAccessToken();
$resource = getResource($access_token);
echo "</br>access_token = " . $access_token;
echo "</br>resource = " . $resource;
// step A, B - single call with client credentials as the basic auth header
// will return access_token
function getAccessToken() {
global $token_url, $client_id, $client_secret;
$content = "grant_type=client_credentials";
$authorization = base64_encode("$client_id:$client_secret");
$header = array("Authorization: Basic {$authorization}","Content-Type: application/x-www-form-urlencoded");
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $token_url,
CURLOPT_HTTPHEADER => $header,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $content
));
$response = curl_exec($curl);
curl_close($curl);
echo "</br>JSON response = " . $response;
return json_decode($response)->access_token;
}
// step B - with the returned access_token we can make as many calls as we want
function getResource($access_token) {
global $test_api_url;
$header = array("Authorization: Bearer {$access_token}");
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $test_api_url,
CURLOPT_HTTPHEADER => $header,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true
));
$response = curl_exec($curl);
curl_close($curl);
return json_decode($response, true);
}
?>
So it seems that with a little bit of research and learning on my part the answer to my question was in Postman. Postman includes a feature that will translate your request into any number of code languages.
All I had to do was select the PHP option and copy and paste the results into my project. Boom, there you go. That was easy.
Here's a YouTube video showing how it works.
Postman: Import/Export and Generating Code Samples
I have developed a system which will send SMS to the customer after making insert to the database
but the system which I worked on is public ie. when my client asked me to buy the system he must insert his SMS API configuration to send a message to his customers
when I searched on the internet I found that every API have a differnt way to send SMS message
I have account in click tell API but when I send message by curl there is nothing happen
the code is
$url = 'https://platform.clickatell.com/messages/http/send?' . http_build_query(
[
'apiKey' => 'oGjnzDdSRhqdhhgnjFj3ZmzYA==',
// 'api_secret' => '4c98619ffb9af51585',
'to' => '94233698311783',
'content' => 'Hello from Netcom'
]
);
echo($url);echo('<br/>');
echo'https://platform.clickatell.com/messages/http/send?apiKey=oGkmzDdSRgekvjFjaZnzYA==&to=905373545631&content=Test+message+text"';
$ch = curl_init($url);
echo($ch);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
echo $response;
Where my code is wrong and what is the way to send SMS dynamically depending on the client's API info
For quick fix and testing add this in your curl request and check response.(Because url is https)
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
But it is recomonded to downloading a CA root certificate bundle at the curl website and saving it on your server which protect your site
I am not aware of Clickatell, but Aws SNS is quite simple,
$payload = array(
'Message' => $message,
'PhoneNumber' => $mobile,
'MessageAttributes' => $msgAttributes
);
$result = $sns->publish($payload);
I am trying to get data of certain Twitch clip, for example this one https://clips.twitch.tv/MushyJollyWalrusUWot
$videosApi = 'https://api.twitch.tv/kraken/clips/savjz/MushyJollyWalrusUWot';
$clientId = 'my client id';
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_HTTPHEADER => array(
'Client-ID: ' . $clientId
),
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $videosApi
));
$response = curl_exec($ch);
curl_close($ch);
$json = json_decode($response, TRUE);
print_r($json);
I am getting an array with 404 error, but this code works fine with another Twitch api stuff, for example Twitch vod:
$videosApi = 'https://api.twitch.tv/kraken/videos/125820676';
//the rest is same
Like I have found with videos, clips are addressed by their name and nothing else, so I removed the username from your example.
I ended up using this URL https://api.twitch.tv/kraken/clips/MushyJollyWalrusUWot, which successfully returned a slightly large JSON blob containing the clip's information, and I have saved it at this URL: PasteBin - "SO Answer - Getting Twitch clip data via Twitch API and php"
I used to be able to query some base URL like https://api.twitch.tv/kraken/ in order to see a list of available resources that I could query from then on by successively adding to the path, but the /kraken and /kraken/ roots give user information, and /kraken/base does not seem to be a valid resource.
The API documentation for accessing this from the shell seems to be here: Twitch Developers - Twitch API Overview
By the way, I just used the shell, and may have had to provide both a Client ID and an OAuth token with user_read scope. I followed this guide for my reoccurring situation: GitHub - raine/twitch-cli - Setup.
It's not PHP, so I did not review your code in full detail, but some of these steps may help you along with your conceptual troubleshooting.
just add your key
parameters(optional):
limit=10
game=Overwatch
trending=true
//set header for pretty print
header('Content-Type: application/json');
$videosApi = 'https://api.twitch.tv/kraken/clips/top?limit=100&channel=ratirl';
$clientId = 'secret app id provided by twitch';
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_HTTPHEADER => array(
//standard api requirement from twitch api headers
'Accept: application/vnd.twitchtv.v5+json',
'Client-ID: ' . $clientId
),
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $videosApi
));
$response = curl_exec($ch);
curl_close($ch);
//decode the response
$json = json_decode($response, JSON_PRETTY_PRINT);
//print response
print_r($json);
I have an application that has a Web Services RESTful API. When I make HTTP GET requests in the browser I get XML responses back.
When I make the same request using PHP I get the correct information but it is not formatted in XML and so I can't pass it to Simple XML.
Here's my code.
<?php
//Deifne user credentials to use with requests
$user = "user";
$passwd = "user";
//Define header array for cURL requestes
$header = array('Contect-Type:application/xml', 'Accept:application/xml');
//Define base URL
$url = 'http://192.168.0.100:8080/root/restful/';
//Define http request nouns
$ls = $url . "landscapes";
//Initialise cURL object
$ch = curl_init();
//Set cURL options
curl_setopt_array($ch, array(
CURLOPT_HTTPHEADER => $header, //Set http header options
CURLOPT_URL => $ls, //URL sent as part of the request
CURLOPT_HTTPAUTH => CURLAUTH_BASIC, //Set Authentication to BASIC
CURLOPT_USERPWD => $user . ":" . $passwd, //Set username and password options
CURLOPT_HTTPGET => TRUE //Set cURL to GET method
));
//Define variable to hold the returned data from the cURL request
$data = curl_exec($ch);
//Close cURL connection
curl_close($ch);
//Print results
print_r($data);
?>
Any thoughts or suggestions would be really helpful.
S
EDIT:
So this is the response I get from the PHP code:
0x100000rhel-mlsptrue9.2.3.0101
This is the response if I use the WizTools Rest Client or a browser.
<?xml version="1.0" encoding="UTF-16"?>
<landscape-response total-landscapes="1" xmlns="http://www.url.com/root/restful/schema/response">
<landscape>
<id>0x100000</id>
<name>rhel-mlsp</name>
<isPrimary>true</isPrimary>
<version>9.2.3.010</version>
</landscape>
</landscape-response>
As you can see the information is there but the PHP is not really presenting this in a useful way.
I was able to find the answer to this question so I thought I would share the code here.
//Initialise curl object
$ch = curl_init();
//Define curl options in an array
$options = array(CURLOPT_URL => "http://192.168.0.100/root/restful/<URI>",
CURLOPT_PORT => "8080",
CURLOPT_HEADER => "Content-Type:application/xml",
CURLOPT_USERPWD => "<USER>:<PASSWD>",
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_RETURNTRANSFER => TRUE
);
//Set options against curl object
curl_setopt_array($ch, $options);
//Assign execution of curl object to a variable
$data = curl_exec($ch);
//Close curl object
curl_close($ch);
//Pass results to the SimpleXMLElement function
$xml = new SimpleXMLElement($data);
print_r($xml);
As you can see the code is not all that different, the main thing was separating the port option out of the URL and into its own option.
Hopefully this helps someone else out!!!
S
Try this
$resp = explode("\n<?", $data);
$response = "<?{$resp[1]}";
$xml = new SimpleXMLElement($response);
Does it print anything at all (your code)? Try using echo $data but hit F12 to view the results on the console.
I've been trying to integrate BitBucket to my application for the past 4 hours to no avail.
While reading through BitBucket's RESTful API documentation, I noticed that you need to use OAuth — it's OK, I'm using J.R Conlin's OAuthSimple library, which if fine by me (I tried oauth-php but it was kinda complicated — I didn't need all of those options for such a small integration).
For what I understand, the first step to authenticate with OAuth is to request a new token via POST. When providing the necessary parameters, you should get a response from BitBucket, like this:
oauth_token=Z6eEdO8lOmk394WozF9oJyuAv899l4llqo7hhlSLik&oauth_token_secret=Jd79W4OQfb2oJTV0vzGzeXftVAwglnEJ9lumzYcl&oauth_callback_confirmed=true
To do that, I'm using cURL and OAuthSimple:
$key = 'key_provided_by_bitbucket';
$secret = 'key_provided_by_bitbucket';
$path = 'https://api.bitbucket.org/1.0/oauth/request_token';
$params = array(
'oauth_consumer_key' => $key,
'oauth_nonce' => base_convert(mt_rand(10000, 90000), 10, 32) . 'a',
'oauth_signature' => 'HMAC-SHA1',
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_timestamp' => time(),
'oauth_callback' => base_url('dashboard'),
'oauth_version' => '1.0a'
);
$oauth = new OAuthSimple($key, $secret);
$result = $oauth->sign(array(
'action' => 'POST',
'path' => $path,
'parameters' => $params
));
// load resulting url into a string
$ch = curl_init($result['signed_url']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$r = curl_exec($ch);
curl_close($ch);
The thing is that, when I send my request, one of two things happen:
If I send it like posted here, I will get a 401 error (I can see that via curl_getinfo($ch))
If I set curl_setopt($ch, CURLOPT_POST, 1), I get a 400 Bad request
The resulting string (stored in $r) is an empty string. The signed_url is a correctly formed URL AFAIK, which is something like this:
https://api.bitbucket.org/1.0/oauth/request_token?oauth_callback=http%3A%2F%2Flocalhost%2Fidv&oauth_consumer_key=key_provided_by_bitbucket&oauth_nonce=b47a&oauth_signature=3A1R%2FoKxTqh6Q23poaS%2BVNzhwpE%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1347167282&oauth_version=1.0a
If I enter manually that address into my address bar in a browser, I'll get an Authentication Dialog to the BitBucket API, port 443. I can't login with my credentials, though. Then it will just keep saying "Could not verify OAuth request."
I don't know what I'm doing wrong, since it's my first time using OAuth.
Any help's appreciated!
The problem is that Curl will verify the SSL certificate.
To solve the problem you can tell Curl to ignore the verification of the SSL certificates:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);