Godaddy api authorization error - php

I am trying to develop client application for GoDaddy based on their API that they provide here https://developer.godaddy.com
And I have a problem with simple example, I am trying to use the next PHP code to check if domain available:
use GuzzleHttp\Client;
try {
$client = new Client([
'base_uri' => 'https://api.godaddy.com',
]);
$responce = $client->get(
'/v1/domains/available?domain=example.guru',
[
'headers' => [
'Authorization' => "sso-key $myKey:$mySecret",
'X-Shopper-Id' => "$myID",
'Accept' => 'application/json',
]
]
);
echo $responce->getBody();
} catch (Exception $e) {
echo $e->getMessage();
}
And all the time I get error: "Client error: 401". Same problem I have with using cURL library. I didn't find any online support.
I need help with it, can someone explain how I should authorize at their api service? Maybe I need to send any other http headers or additional params?

Are the key and secret you're using for production? When I go through the process, by default it creates a TEST key/secret, which I think are meant to go against https://api.ote-godaddy.com
If you are using production keys, try doing a manual Curl request from the command like; something like:
curl -H 'Authorization: sso-key {KEY}:{SECRET}' -H 'Content-Type: application/json' https://api.godaddy.com/v1/domains/available?domain=example.guru'
Let us know how it works out!

The problem was that I was using TEST {KEY}:{SECRET} and set wrong URL.
For the test {KEY}:{SECRET} URL has to be: https://api.ote-godaddy.com.
Also the method for checking domain availability (/v1/domains/available) doesn't need parameter 'X-Shopper-Id' in header. It works well without it. With parameter X-Shopper-Id request returns error "NOT_FOUND: The specified shopperId could not be found"(but it's other problem, maybe I didn't activate some option)
So if to take into account all changes, the working code for checking domain availability with test key/secret should be like this:
use GuzzleHttp\Client;
try {
$client = new Client([
'base_uri' => 'https://api.ote-godaddy.com'
]);
$responce = $client->get(
'/v1/domains/available?domain=example.guru',
[
'headers' => [
'Authorization' => "sso-key $myKey:$mySecret",
'Accept' => 'application/json',
]
]
);
echo $responce->getBody();
} catch (Exception $e) {
echo $e->getMessage();
}

I am using php and curl.
$domain = "jaisinghverma.com";<br>
$apiURL = 'https://api.ote-godaddy.com/v1/domains/available?
domain='.$domain.'&checkType=FULL&forTransfer=false';<br>
$headers = array(
'Accept: application/json',
'Authorization: sso-key ?????????',
);<br>
$ch = curl_init();<br>
curl_setopt($ch, CURLOPT_URL, $apiURL);<br>
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<br>
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);<br>
$server_output = curl_exec ($ch);<br>
curl_close ($ch);<br>
print_r(json_decode($server_output));
above code is working fine for me.

Related

Struggling to Get Token for REST API in PHP OAuth 2 Client. Have Successfully Tested with Postman

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

Consuming cURL in restful codeigniter

In native PHP, I have a consuming restful server like this:
$url = "http://localhost/pln/api/json?rayon=$rayon&id_pel=$id_pel&nama=$nama";
$client = curl_init($url);
curl_setopt($client,CURLOPT_RETURNTRANSFER,true);
$respone = curl_exec($client);
$result = json_decode($respone);
How can I access cURL like this when using CodeIgniter?
There's no active cURL library around for CodeIgniter 3.x. There were one for CI 2.x which is no longer maintained.
Consider using Guzzle which is very popular and considered as a de-facto HTTP interfacing library for PHP. Here's an usage example from the docs:
$client = new GuzzleHttp\Client();
$res = $client->request('GET', 'https://api.github.com/user', [
'auth' => ['user', 'pass']
]);
echo $res->getStatusCode();
// "200"
echo $res->getHeader('content-type');
// 'application/json; charset=utf8'
echo $res->getBody();
// {"type":"User"...'
I also recommend using Requests which is inspired by Python Requests module and is way more easier than Guzzle to get started with:
$headers = array('Accept' => 'application/json');
$options = array('auth' => array('user', 'pass'));
$request = Requests::get('https://api.github.com/gists', $headers, $options);
var_dump($request->status_code);
// int(200)
var_dump($request->headers['content-type']);
// string(31) "application/json; charset=utf-8"
var_dump($request->body);
// string(26891) "[...]"
As CodeIgniter 3.x has support for Composer packages out of the box, you can easily install one of these packages through composer and start using it right away.
I stongly recommend you to not to go down the "Download Script" way as suggested in Manthan Dave's answer. Composer provides PHP with a sophisticated dependency management ecosystem; Utilize that! "Download This Script" dog days are over for good.
I used the following function in codeigniter for curl url and works fine, try it out:
function request($auth, $url, $http_method = NULL, $data = NULL) {
//check to see if we have curl installed on the server
if (!extension_loaded('curl')) {
//no curl
throw new Exception('The cURL extension is required', 0);
}
//init the curl request
//via endpoint to curl
$req = curl_init($url);
//set request headers
curl_setopt($req, CURLOPT_HTTPHEADER, array(
'Authorization: Basic ' . $auth,
'Accept: application/xml',
'Content-Type: application/x-www-form-urlencoded',
));
//set other curl options
curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
curl_setopt($req, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($req, CURLOPT_TIMEOUT, 30);
//set http method
//default to GET if data is null
//default to POST if data is not null
if (is_null($http_method)) {
if (is_null($data)) {
$http_method = 'GET';
} else {
$http_method = 'POST';
}
}
//set http method in curl
curl_setopt($req, CURLOPT_CUSTOMREQUEST, $http_method);
//make sure incoming payload is good to go, set it
if (!is_null($data)) {
if (is_array($data)) {
$raw = http_build_query($data);
} else {
//Incase of raw xml
$raw = $data;
}
curl_setopt($req, CURLOPT_POSTFIELDS, $raw);
}
//execute curl request
$raw = curl_exec($req);
if (false === $raw) { //make sure we got something back
throw new Exception(curl_error($req) . $url, -curl_errno($req));
}
//decode the result
$res = json_decode($raw);
if (is_null($res)) { //make sure the result is good to go
throw new Exception('Unexpected response format' . $url, 0);
}
return $res;
}
You could use default Curl library of codeigniter:
$this->load->library('curl');
$result = $this->curl->simple_get('http://example.com/');
var_dump($result);
For more details refer this link :
https://www.formget.com/curl-library-codeigniter/
Adding to #sepehr answer. Requests library can be configured in a very easy way in codeigniter as described here
https://stackoverflow.com/a/46062566/2472685

Accessing Picasa Web API using PHP

Does anyone here know about how to access Google Photos API now that Google has started using OAuth2? The PHP client library in their developer website is now obsolete and does not work!
I have used OAuth to work with Google Drive but Photos does not work! :(
First I use Google_Client to successfully authenticate user. Then in the redirect page I am trying following:
require_once("Google/Client.php");
//set up path for Zend GData, because Google Documentation uses that lib
$clientLibraryPath = '/path/to/ZendGData/library';
$oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $clientLibraryPath);
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_Photos');
try
{
$authCode = $_GET['code']; //authorization code returned from google
//next create google OAuth Client object and validate...
$webAuth= new Google_Client();
$webAuth->setClientId($clientId);
$webAuth->setClientSecret($clientSecret);
$webAuth->authenticate($authCode); //this authenticate() works fine...
//now my problem is HOW do I tie this to GData API for Picasa :(
//I tried following but it throws error
//*Token invalid - Invalid token: Request token used when not allowed.*
$client = Zend_Gdata_AuthSub::getHttpClient($authCode);
$gp = new Zend_Gdata_Photos($client, "GData:2.0");
$userFeed = $gp->getUserFeed("default");
I have also tried a bunch of third party libraries, tried hooking up my $webAuth into Zend_GData_Photos in everywhich way I can try...I even tried raw curl calls, but nothing is working!
Can anyone help me please? I am at my wits end....I can't believe Google left a fully functional library (PicasaWeb PHP API Ver 1.0) hanging like that when they updated their authentication to OAuth.
I had the same problem but finally I got it working again.
The best thing is, that you do not need any client library to get access to private photos.
I have spent two days trying to make it work with 'service account' but with no luck.
Then I have found this page:
https://holtstrom.com/michael/blog/post/522/Google-OAuth2-with-PicasaWeb.html
which helped me to achieve what I wanted.
It is pretty long article but it should not take to long to sort it out and get it working. Basically you will need to use 'OAuth 2.0 client ID' instead of 'Service account' in your project at https://console.developers.google.com
Within your 'OAuth 2.0 client ID' you will have following information:
Client ID (something-random.apps.googleusercontent.com)
Client Secret (random-client-secret)
Name (www.yoursite.com)
Authorized JavaScript origins (https://www.yoursite.com)
Authorized redirect URIs (https://www.yoursite.com/oauth2.php)
You will use this data in your verification process.
Before you begin, you will need to complete OAuth Consent Screen.
In that tutorial there is a note to store these tokens in DB, but in this case I'd rather suggest to display them directly in web page. This is much easier.
There is suggestion to use https rather than http but it should work on both.
I have used https for my application.
This is shorter version of the article from the link above.
Create oauth2.php file and place it on https://www.yoursite.com/oauth2.php
<?php
if (isset($_GET['code']))
{
$clientId = 'your-client-id.apps.googleusercontent.com';
$clientSecret = 'your-client-secret';
$referer = 'https://www.yoursite.com/oauth2.php';
$postBody = 'code='.urlencode($_GET['code'])
.'&grant_type=authorization_code'
.'&redirect_uri='.urlencode($referer)
.'&client_id='.urlencode($clientId)
.'&client_secret='.urlencode($clientSecret);
$curl = curl_init();
curl_setopt_array( $curl,
array( CURLOPT_CUSTOMREQUEST => 'POST'
, CURLOPT_URL => 'https://accounts.google.com/o/oauth2/token'
, CURLOPT_HTTPHEADER => array( 'Content-Type: application/x-www-form-urlencoded'
, 'Content-Length: '.strlen($postBody)
, 'User-Agent: www.yoursite.com/0.1 +https://www.yoursite.com/'
)
, CURLOPT_POSTFIELDS => $postBody
, CURLOPT_REFERER => $referer
, CURLOPT_RETURNTRANSFER => 1 // means output will be a return value from curl_exec() instead of simply echoed
, CURLOPT_TIMEOUT => 15 // max seconds to wait
, CURLOPT_FOLLOWLOCATION => 0 // don't follow any Location headers, use only the CURLOPT_URL, this is for security
, CURLOPT_FAILONERROR => 0 // do not fail verbosely fi the http_code is an error, this is for security
, CURLOPT_SSL_VERIFYPEER => 1 // do verify the SSL of CURLOPT_URL, this is for security
, CURLOPT_VERBOSE => 0 // don't output verbosely to stderr, this is for security
) );
$response = curl_exec($curl);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
echo($response);
echo($http_code);
}
else { echo 'Code was not provided.'; }
?>
Prepare and visit this link:
https://accounts.google.com/o/oauth2/auth?scope=https://picasaweb.google.com/data/&response_type=code&access_type=offline&redirect_uri=https://www.yoursite.com/oauth2.php&approval_prompt=force&client_id=your-client-id.googleusercontent.com
fields to adjust: redirect_uri and client_id
After visiting link from step 2. you should see your consent screen where you will have to approve it and you will be redirected to your oauth.php page but this time with code parameter:
https://www.yoursite.com/oauth2.php?code=some-random-code
'code' parameter will be then sent by oauth.php to: https://accounts.google.com/o/oauth2/token
which will return(print) json formatted data containing: access_token, token_type, expires_in and refresh_token.
Http Response code should be 200.
Access_token will be the one to use to get privet albums data.
Create index.php with content:
<?php
$curl = curl_init();
$url = 'https://picasaweb.google.com/data/entry/api/user/default';
curl_setopt_array( $curl,
array( CURLOPT_CUSTOMREQUEST => 'GET'
, CURLOPT_URL => $url
, CURLOPT_HTTPHEADER => array( 'GData-Version: 2'
, 'Authorization: Bearer '.'your-access-token' )
, CURLOPT_RETURNTRANSFER => 1 // means output will be a return value from curl_exec() instead of simply echoed
) );
$response = curl_exec($curl);
$http_code = curl_getinfo($curl,CURLINFO_HTTP_CODE);
curl_close($curl);
echo($response . '<br/>');
echo($http_code);
?>
After running script from step 5. you should receive your default feed from picasaweb API. When I say 'default' it ,eans default when you are logged that is with private albums. From now on, you should be able to use that approach to get access to your picasa photo library.
Access token will expire after 3600 seconds (1 hour) so you will have to get new one. this can be achieved with script like this one below:
$clientId = 'your-client-id.apps.googleusercontent.com';
$clientSecret = 'your-client-secret';
$referer = 'https://www.yoursite.com/oauth2.php';
$refreshToken = 'your-refresh-token';
$postBody = 'client_id='.urlencode($clientId)
.'&client_secret='.urlencode($clientSecret)
.'&refresh_token='.urlencode($refreshToken)
.'&grant_type=refresh_token';
$curl = curl_init();
curl_setopt_array( $curl,
array( CURLOPT_CUSTOMREQUEST => 'POST'
, CURLOPT_URL => 'https://www.googleapis.com/oauth2/v3/token'
, CURLOPT_HTTPHEADER => array( 'Content-Type: application/x-www-form-urlencoded'
, 'Content-Length: '.strlen($postBody)
, 'User-Agent: www.yoursite.com/0.1 +https://www.yoursite.com/'
)
, CURLOPT_POSTFIELDS => $postBody
, CURLOPT_RETURNTRANSFER => 1 // means output will be a return value from curl_exec() instead of simply echoed
, CURLOPT_TIMEOUT => 15 // max seconds to wait
, CURLOPT_FOLLOWLOCATION => 0 // don't follow any Location headers, use only the CURLOPT_URL, this is for security
, CURLOPT_FAILONERROR => 0 // do not fail verbosely fi the http_code is an error, this is for security
, CURLOPT_SSL_VERIFYPEER => 1 // do verify the SSL of CURLOPT_URL, this is for security
, CURLOPT_VERBOSE => 0 // don't output verbosely to stderr, this is for security
) );
$response = curl_exec($curl);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if (strlen($response) < 1)
{ echo('fail 01'); }
$NOW = time();
$responseDecoded = json_decode($response, true); // convert returned objects into associative arrays
$expires = $NOW - 60 + intval($responseDecoded['expires_in']);
if ( empty($responseDecoded['access_token'])
|| $expires <= $NOW )
{ echo('fail 02'); }
echo($http_code . '<br/>');
echo($response . '<br/>');
echo($expires . '<br/>');
?>
You can run code from step 7. in separate script manually, just to get new access-token for another 3600 seconds, but normally you would want to have it automated so when access_token expires, you automatically ask for new one using a call with refresh_token from step 4.
Ufff. That is is. I hope you'll get this up and running.

Having Trouble in Generating Amazon AWS Signature With PHP

I was trying to make a HTTP POST Request to amazon's AGCOD Service API , I followed all the steps to make a signature and all the hashed keys matched the instructions here, but I still got a "The security token included in the request is invalid." ERROR.
<?php
define('PARTNER_ID','Test');
define('ACCESS_KEY','fake-aws-key');
define('SECRET_KEY','fake-secret-key');
define('TIME_STAMP_ISO_8601',date('Ymd\THisO'));
//define('TIME_STAMP_ISO_8601','20140205T171524Z');
//define('TIME_STAMP','20140205');
define('TIME_STAMP',date('Ymd'));
define('REGION_CODE','us-east-1');
define('SERVICE_NAME','AGCODService');
$secretKey = 'AWS4'.SECRET_KEY;
$hashedDateKey = hash_hmac('sha256', TIME_STAMP, $secretKey, true);//41b8dd5e0d1716ba90401d46b58b12d500accdd2ea9c2b22a2d275946c9d978e
$hashedRegionKey = hash_hmac('sha256', REGION_CODE, $hashedDateKey, true);//7b47360ce7afbe1b839e0b0e55834df99979a5414bc7f846b17c9374d230d45d
$hashedServiceKey = hash_hmac('sha256', SERVICE_NAME , $hashedRegionKey, true);//68136b0a64b2d01c8934370288b46500243645e468f521503e0d1fa73526d409
$signingKey = hash_hmac('sha256', 'aws4_request', $hashedServiceKey,true);//27cb9f5b991c2933f5faae716e99bd50c66a45811b1424128269312bdd570dff
$payload = "<CreateGiftCardRequest><creationRequestId>Test001</creationRequestId><partnerId>Test</partnerId><value><currencyCode>USD</currencyCode><amount>10</amount></value></CreateGiftCardRequest>";
$hashedPayload = hash('sha256',$payload);//50bf24a091a7463bb4a2661f93a7299c94774bc81f9fddf02af2925922b869dc
$CanonicalRequestStr = "POST\n/CreateGiftCard\n\naccept:charset=UTF-8\ncontent-type:charset=UTF-8\nhost:agcod-v2-gamma.amazon.com\nx-amz-date:".TIME_STAMP_ISO_8601."\nx-amz-target:com.amazonaws.agcod.AGCODService.CreateGiftCard\n\naccept;content-type;host;x-amz-date;x-amz-target\n".$hashedPayload;
$hashedCanonicalRequest = hash('sha256',$CanonicalRequestStr);//7d9f2765e4f23e85d3dce4ae264dac4f784c152f3746aff45ac7f3afd7fad649
$str2Sign = "AWS4-HMAC-SHA256\n".TIME_STAMP_ISO_8601."\n".TIME_STAMP."/".REGION_CODE."/".SERVICE_NAME."/aws4_request\n".$hashedCanonicalRequest;
$signature = hash_hmac('sha256', $str2Sign, $signingKey);//e32110cf663ed86460621dff12bb1139afe29d015584d208df09f149fa1b69d1
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'https://agcod-v2-gamma.amazon.com/CreateGiftCard');
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
//curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'accept:charset=UTF-8',
'content-type:charset=UTF-8',
'host:agcod-v2-gamma.amazon.com',
'x-amz-date:'.TIME_STAMP_ISO_8601,
'x-amz-target:com.amazonaws.agcod.AGCODService.CreateGiftCard',
'Authorization:AWS4-HMAC-SHA256 Credential='.ACCESS_KEY.'/'.TIME_STAMP.'/us-east-1/AGCODService/aws4_request, SignedHeaders=accept;content-type;host;x-amz-date;x-amz-target,Signature='.$signature,
));
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$return = curl_exec($ch);
$return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
var_dump($return_code);
?>
The AWS SDK for PHP has a SignatureV4 implementation. There is no PHP client included for AGCOD, since it is not an AWS service, but the DynamoDB service works very similarly to how AGCOD works. I was able to hack the DynamoDB client to send requests to AGCOD instead.
<?php
require 'vendor/autoload.php'; // If installed via Composer.
// Instantiate DynamoDB client, but overwrite a bunch of the settings
// to work with the AGCOD service
$client = \Aws\DynamoDb\DynamoDbClient::factory([
'base_url' => 'https://agcod-v2-gamma.amazon.com',
'key' => 'AWS_ACCESS_KEY_ID',
'secret' => 'AWS_SECRET_ACCESS_KEY',
'region' => 'us-east-1',
'signature' => 'v4',
'signature.service' => 'AGCODService',
'signature.region' => 'us-east-1',
]);
// Add wire logger for debugging
$client->addSubscriber(\Guzzle\Plugin\Log\LogPlugin::getDebugPlugin());
$body = <<<JSON
{"requestId": "Awssb0327141418PM", "partnerId": "Awssb", "utcStartDate":
"2014-03-27T00:10:10Z", "utcEndDate": "2014-03-27T23:59:59Z", "pageIndex": 0,
"pageSize": 200, "showNoOps": "true"}
JSON;
try {
// Use underlying Guzzle feature to send request,
// to skip some of the DynamoDB-specific logic.
$response = $client->put('GetGiftCardActivityPage', [
'x-amz-target' => 'com.amazonaws.agcod.AGCODService.GetGiftCardActivityPage',
'accept' => 'application/json'
], $body)->send();
} catch (\Aws\Common\Exception\ServiceResponseException $e) {
echo $e; // This exception class has a __toString() method.
}
Note sure if this will help much, but it could be used as a starting point if you decide to cherry pick code from the AWS SDK for PHP.

Implement an Air API by sending a SOAP request

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.

Categories