Not reaching web service on live server but i reach it on local machine in laravel 4.2 - laravel

am trying to consume a web service in laravel 4.2 but works on local machine but does to work on live server
my controller
ini_set('max_execution_time',10);
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"trace" => 1, // enable trace to view what is happening
"exceptions" => 0, // disable exceptions
"cache_wsdl" => 0
); //SOAPAction: your op URL
$vendorCode = Input::get('name');
$password = Input::get('password');
$client = new SoapClient('https://xxxxxxxxx.asmx?WSDL', $headers);
$params = array(
'vendorcode'=> $vendorCode,
'password'=> $password,
);
$results = $client->GetAccountBalance($params);
$response = $results->GetAccountBalanceResult;
the error it brings looks like this
SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://XXXXXXXXX.asmx?WSDL' : failed to load external entity "https://XXXXXXXXX.asmx?WSDL"
thanks in advance

Related

API to get a price sheet from partner center

I am attempting to do an API call to the following: https://learn.microsoft.com/en-us/partner-center/develop/get-a-price-sheet To get a price sheet for a given market and view. But i can not make it work.
I got a token using https://login.microsoftonline.com/x/oauth2/token
But when I try to call the following API: https://api.partner.microsoft.com/v1.0/sales/pricesheets(Market='be',PricesheetView='updatedlicensebased')/$value
I get a
401, "Unauthorized: Invalid Authorization header"
Can someone give me some advice to what could be the problem? Thanks.
in your POST request to https://login.microsoftonline.com/x/oauth2/token you should use a 'resource' => 'https://api.partner.microsoft.com'.
This PHP code works for me:
public static function getTokenFromCode($code){
$data = array(
'resource' => 'https://api.partner.microsoft.com',
'client_id' => $appId,
'code' => $code,
'redirect_uri' => $redirectURL,
'grant_type' => 'authorization_code',
'client_secret' => $appKey
);
$header = array(
'Accept: application/json',
'return-client-request-id: true',
'Expect: 100-continue'
);
$token = self::callApi("POST", 'https://login.microsoftonline.com/'.$accountId."/oauth2/token", $header, $data);
return $token;
}
public static function getNcePriceList($timeline = "current"){
$header = array(
'Authorization: Bearer '.$token['access_token'],
'Host: api.partner.microsoft.com',
);
return self::callApi("GET", "https://api.partner.microsoft.com/v1.0/sales/pricesheets(Market='DE',PricesheetView='updatedlicensebased')/\$value?timeline=".$timeline, $header);
}

Opayo merchant session key. Authentication values are missing

We are getting the following error when executing this:
[description] => Authentication values are missing [code] => 1001
Can anyone see what I am doing wrong.
I tried removing the base64_encode function but this didn't have any impact.
I got the integration key and password from opayo (sagepay) - the test environment.
My php code follows:
$key = base64_encode("My Integration Key");
$password = "My Integration Password";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://pi-test.sagepay.com/api/v1/merchant-session-keys",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => '{ "vendorName": "MY VENDOR" }',
CURLOPT_HTTPHEADER => array(
"Authorization: Basic $key:$password",
"Cache-Control: no-cache",
"Content-Type: application/json"
)
));
$response = curl_exec($curl);
$response = json_decode($response, true);
$err = curl_error($curl);
curl_close($curl);
Tia for any help
Both the key and password had to be base 64 encoded.
ie $key = base64_encode("My Integration Key:My Integration Password");
and then fed in to the curl http header as
"Authorization: Basic $key",
I had the same issue, so created a NuGet package for this API-client code: https://github.com/joeratzer/opayo-admin-and-reporting-api-client.
You can find the NuGet package here:
https://www.nuget.org/packages/Joe.Opayo.Admin.Api.Client/1.1.0
The client app allows code like this:
var client = new OpayoAdminApiClient();
var isTest = true;
var request = new OpayoApiRequest(ApiCommandType.GetTransactionDetail, "password", isTest, "user-name", "vendor-name");
var commandSpecificXml = "<vendortxcode>01Jan2010Transaction12345</vendortxcode>";
return await client.ProcessApiCommandAsync<TransactionDetail>(request, commandSpecificXml);

Restful API with Laravel

I'm developing a restful API with laravel. Authorization is done using a SECRET_KEY & PUBLIC_KEY as shown in the sample request code below.
How do i retrieve the Authorization header key value from the Request?
I would also appreciate links to any resources that would guide me through better implementation & best practice in creating a Restful API with Laravel.
$curl = curl_init();
$url = "http://api.example.com/v1/users";
$secretKey = env('SECRET_KEY');
$publicKey = env('PUBLIC_KEY');
$firstName = "John";
$lastName = "Doe";
$email = "example#gmail.com";
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\r\n \"firstName\": \"$firstName\",\r\n \"lastName\": \"$lastName\",\r\n \"email\": \"$email\",\r\n \"secretKey\": \"$secretKey\",\r\n}",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
'Authorization: Bearer ' . $publicKey,
),
));
$response = curl_exec($curl);
curl_close($curl);
The request() helper contains everything from the request.
Just dd(request()->header()) to see the full list of the request headers.
You can check the official documentaion : https://laravel.com/docs/7.x/eloquent-resources#introduction
Also you might want to use a tool like Postman to test your API easily.

Getting Google YouTube API Service Account Access Token in PHP

I'm trying to obtain an access token from Google so I can use a 'service account' to upload videos to YouTube automatically.
This code:
$credentials = array(
'client_id' => $my_client_id
);
$jwt = JWT::encode($credentials, $private_key);
$client = new Google_Client();
if ($client->authenticate($jwt))
{
// do something
}
Fails with this exception:
Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Error fetching OAuth2 access token, message: 'invalid_request: Client must specify either client_id or client_assertion, not both'' in /home/google/client/google-api-php-client/src/Google/Auth/OAuth2.php:120
Where am I going wrong?
TY!
I had missed a large section of the documentation as shown here:
https://developers.google.com/accounts/docs/OAuth2ServiceAccount#creatingjwt
I had also missed that the algorithm had to be RSA256 not HSA256 as defaulted to in the JWT PHP encode function.
And further, that I needed to POST a request, appropriately, directly to get an access token to endpoint:
https://www.googleapis.com/oauth2/v3/token
The Google private JSON private key for the service account also was invalid for use by openssl due to the final character being encoded/included as:
\u003d
Swapping this, literally, with:
=
solved that problem.
Here is my now working (ish, see closing statement) code:
$claimset = array(
'iss' => $client_email,
'scope' => 'https://www.googleapis.com/auth/youtube.upload',
'aud' => 'https://www.googleapis.com/oauth2/v3/token',
'exp' => time() + 1800,
'iat' => time(),
'sub' => 'my google account email#gmail.com'); // not sure if reqd
$jwt = JWT::encode($claimset, $private_key, 'RS256');
// Now need to get a token by posting the above to:
// https://www.googleapis.com/oauth2/v3/token
# Our new data
$data = array(
'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
'assertion' => $jwt
);
# Create a connection
$url = 'https://www.googleapis.com/oauth2/v3/token';
$ch = curl_init($url);
# Form data string
$postString = http_build_query($data, '', '&');
# Setting our options
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
# Get the response
$response = curl_exec($ch);
curl_close($ch);
print "and here is what we got: ";
print_r($response);
exit;
Unfortunately, for some reason the response I'm getting is:
{ "error": "unauthorized_client", "error_description": "Unauthorized client or scope in request." }
Suspect my service account does not yet have the right to upload to YouTube.
I'm not an experr, but you should probably look at removing the "," at the end of you line here:
'client_id' => $private_key['client_id'],
//'client_email' => $private_ket['client_email']
change to:
'client_id' => $private_key['client_id']
//'client_email' => $private_ket['client_email']
I've used this example to get oauth working. It may be helpful:
http://msdn.microsoft.com/en-us/library/dn632721.aspx
you could also try oauth testing here:
https://developers.google.com/oauthplayground/
Good luck!

Invalid domain error in gmail setting api

I want to create a label in gmail account using goggle admin sdk api.
I am sending a Http Post Request to
https://apps-apis.google.com/a/feeds/emailsettings/2.0/{domain}/{username}/label/
But i get this response :-
Invalid domain.
Error 403
Following is the code for this task :-
$domain = explode('#',$user->email);
$headers = array(
"X-HTTP-Method-Override: POST",
"Authorization: {$obj->token_type} "." {$obj->access_token}",
"Content-type: application/atom+xml",
);
$options = array(CURLOPT_URL => "https://apps-apis.google.com/a/feeds/emailsettings/2.0/$domain[1]/$domain[0]/label",
CURLOPT_HEADER => 1,
CURLOPT_RETURNTRANSFER => 1,
// CURLOPT_USERAGENT => '',
CURLOPT_FOLLOWLOCATION => 1,
// CURLOPT_VERBOSE => 1,
// CURLOPT_POST => true
);
$ch = curl_init();
curl_setopt_array($ch, $options);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
echo "<pre>";print_r($result);echo"</pre>";
If you actually trying to access labels on your gmail.com account from your domain's admin account, it will not work. The email setting API works only on Premier and Edu Google Apps domains administrators.

Resources