I am trying to retrieve information from an API. The API requires authentication in order to access it. I have the tried the following, but it says that the Authentication has failed. I already confirmed that the credentials are correct, so that is not the problem. Any suggestions?
$pro = '0000000000';
$userName = 'userName';
$password = 'password';
$userPass = $userName.':'.$password;
$host = 'https://wardtlctools.com/wardtrucking/webservices/imaging';
$post = array(
'User' => array(
'UserName' => $userName,
'Password' => $password
),
'Reference' => array(
'RefNo' => $pro,
'RefType' => 'WARDPRO',
'DelMethod' => 'Link',
'Documents' => array(
'DocType' => 'BL',
'DocType' => 'DR'
)
)
);
$ch = curl_init($host);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_USERPWD, $userPass);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$return = curl_exec($ch);
curl_close($ch);
print_r($return);
This is the documentation from the provider's website.
Related
I'm trying to build an order page where customer enters his details and than the code gets the detail place the order and redirects him to invoicing page .
It is working but it is too slow
I'm trying to get data through api with json response.
My code is working too slow. Is it possible to combine them to speed up the code?
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$fname = $_POST['firstname'];
$lname = $_POST['lastname'];
$umail = $_POST['email'];
$uadd = $_POST['address'];
$ucity = $_POST['city'];
$ustate = $_POST['state'];
$upcode = $_POST['postcode'];
$uctry = $_POST['country'];
$uphn = $_POST['phonenumber'];
$upass = $_POST['password'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'URL+++++++++++++++');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt(
$ch,
CURLOPT_POSTFIELDS,
http_build_query(
array(
'action' => 'AddClient',
'username' => '+++++++++++++++',
'password' => '+++++++++++++++++',
'firstname' => $fname,
'lastname' => $lname,
'email' => $umail,
'address1' => $uadd,
'city' => $ucity,
'state' => $ustate,
'postcode' => $upcode,
'country' => $uctry,
'phonenumber' => $uphn,
'password2' => $upass,
'responsetype' => 'json',
)
)
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$aduresponse = curl_exec($ch);
curl_close($ch);
$useraddresponse = json_decode($aduresponse, true);
$result = $useraddresponse['result'];
$clientid = $useraddresponse['clientid'];
if ($result == "error") {
echo $result['message'];
}
if (isset($result)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '+++++++++++++++++++++++++');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt(
$ch,
CURLOPT_POSTFIELDS,
http_build_query(
array(
'action' => 'AddOrder',
'username' => '++++++++++++++++++++++',
'password' => '++++++++++++++++++++++++++',
'clientid' => $clientid,
'pid' => 65,
'domain' => $orderdomain,
'billingcycle' => 'annually',
'domaintype' => 'register',
'regperiod' => 1,
'dnsmanagement' => 0,
'nameserver1' => 'ns1.domain.com',
'nameserver2' => 'ns2.domain.com',
'paymentmethod' => 'mailin',
'responsetype' => 'json',
)
)
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$orderres = curl_exec($ch);
curl_close($ch);
$orderaddresponse = json_decode($orderres, true);
$orderresult = $orderaddresponse['result'];
if ($orderresult == "error") {
echo $orderresult['message'];
}
}
if ($orderresult == "success") {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '++++++++++++++++++++++++++++');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt(
$ch,
CURLOPT_POSTFIELDS,
http_build_query(
array(
'action' => 'CreateSsoToken',
'username' => '+++++++++++++++++++++++++++',
'password' => '+++++++++++++++++++++++++',
'client_id' => $clientid,
'destination' => 'clientarea:invoices',
'responsetype' => 'json',
)
)
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$SSOresponse = curl_exec($ch);
curl_close($ch);
$ssoresult = json_decode($SSOresponse, true);
$ssourl = $ssoresult['redirect_url'];
$ssoresultstatus = $ssoresult['result'];
}
if ($ssoresultstatus == "error") {
echo $ssoresultstatus['message'];
}
if ($ssoresultstatus == "success") {
header('Location:' . $ssourl);
}
}
I retrieve the Oauth token in Trustpilot with this script
function get_accesstoken($tp_username,$tp_password,$api_key,$api_secret)
{
$url = 'https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/accesstoken';
$payloadName = array(
'grant_type' => 'password',
'username' => $tp_username,
'password' => $tp_password
);
$payload = http_build_query($payloadName);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "$api_key:$api_secret");
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$return = json_decode(curl_exec($curl));
print_r($return);
curl_close($curl);
return $return->access_token;
}
now, how can I retrieve the token, verify is exist and use it?
thanks
$url = "https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/accesstoken";
$key = "YOUR API KEY";
$secret = "YOUR API SECRET";
$username = 'YOUR LOGIN EMAIL';
$password = 'YOUR LOGIN PASSWORD';
$payload = array(
'grant_type' => 'password',
'username' => $username,
'password' => $password,
);
$authEncodedKeys = base64_encode($key.":".$secret);
$options = array(
'http' => array (
'header' => "Authorization: Basic ".$authEncodedKeys.
"Content-Type: application/x-www-form-urlencoded",
'method' => 'POST',
'content' => http_build_query($payload)
)
);
$context = stream_context_create($options);
$results = json_encode(file_get_contents($url, false, $context));
echo $results;
This works for me. Try it.
Hi I implement PayPal DoDirectPayment in my website, I want to required expire date And CVV but payment taking without those with this warning "This transaction was approved. However, the Card Security Code provided had too few, too many, or invalid character types but, as per your account option settings, was not required in the approval process"
I'm using PHP.
My Code is
$api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
$request = array
(
'METHOD' => 'DoDirectPayment',
'USER' => 'sell3_api1.pay.com',
'PWD' => '75DQHCABLDFSDF',
'SIGNATURE' => 'AFcWxV21C7fd0asdasdCpasdsdAtxzafSFsaKZ3unSUBjX9r-',
'VERSION' => '55.0',
'PAYMENTACTION' => 'Sale',
'FIRSTNAME' => $current_user->user_login,
'LASTNAME' => '.',
'IPADDRESS' => $_SERVER['REMOTE_ADDR'],
'ACCT' => $acct,
'CREDITCARDTYPE'=>
'EXPDATE' => $month.$year,
'CVV2' => $cvv,
'AMT' => $amt,
'CURRENCYCODE' => 'USD',
);
$nvp_string = '';
foreach ($request as $key => $value) {
$nvp_string .= '&'.$key.'='.urlencode($value);
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_URL, $api_endpoint);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $nvp_string);
$result = curl_exec($curl);
curl_close($curl);
parse_str($result);
How can I solve It.
I am able to get the GET request working but having issues related to authentication in POST and PUT request. I am getting the error "You must log in before using this part of Bugzilla". I have provided the correct username and password. I have tried CURLAUTH_ANY as well as CURLAUTH_BASIC. I have tried both PUT and POST request. Any help is appreciated.
$url ="http://localhost:8080/bugzilla/rest/bug/2";
$apikey = "IZC4rs2gstCal0jEZosFjDBRV9AQv2gF0udh4hgq";
$data = array(
"product" => "TestProduct",
"component" => "TestComponent",
"version" => "unspecified",
"summary" => "This is a test bug - please disregard",
"alias" => "SomeAlias",
"op_sys" => "All",
"priority" => "P1",
"rep_platform" => "All"
);
$str_data = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$str_data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array("Content-Type: application/json", "Accept: application/json"));
$username = 'ashish.sureka#in.abb.com';
$password = 'abbincrc';
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
echo $result
Following code solved my problem. I have written a blog on it which might be useful to others encountering the same problem.
<?php
$url = 'http://localhost:8080//bugzilla/xmlrpc.cgi';
$ch = curl_init();
$header = array(
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array( 'Content-Type: text/xml', 'charset=utf-8' )
);
curl_setopt_array($ch, $header);
$bugreport = array(
'login' => 'ashish.sureka#in.abb.com',
'password' => 'abbincrc',
'product' => "TestProduct",
'component' => "TestComponent",
'summary' => "Bug Title : A One Line Summary",
'assigned_to' => "ashish.sureka#in.abb.com",
'version' => "unspecified",
'description' => "Bug Description : A Detailed Problem Description",
'op_sys' => "All",
'platform' => "All",
'priority' => "Normal",
'severity' => "Trivial"
);
$request = xmlrpc_encode_request("Bug.create", $bugreport);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_exec($ch)
?>
I develop a paypal pro in magento.
my paypal code look below:
$api_username = 'sdk-three_api1.sdk.com';
$api_password = 'QFZCWN5HZM8VBG7Q';
$api_signature = 'A.d9eRKfd1yVkRrtmMfCFLTqa6M9AyodL0SJkhYztxUi8W9pCXF6.4NI';
$api_version = '57.0';
$api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
$request_params = array
(
'METHOD' => 'DoDirectPayment',
'USER' => $api_username,
'PWD' => $api_password,
'SIGNATURE' => $api_signature,
'VERSION' => $api_version,
'PAYMENTACTION' => 'Sale',
'IPADDRESS' => $_SERVER['REMOTE_ADDR'],
'CREDITCARDTYPE' => $params['creditCardType'],
'ACCT' => $params['creditCardNumber'],
'EXPDATE' => $params['expDateMonth'].$params['expDateYear'],
'CVV2' => $params['cvv2Number'],
'FIRSTNAME' => 'Tester',
'LASTNAME' => 'Testerson',
'STREET' => '707 W. Bay Drive',
'CITY' => 'Largo',
'STATE' => 'FL',
'COUNTRYCODE' => 'US',
'ZIP' => '33770',
'AMT' => $plan_data['amount'],
'CURRENCYCODE' => 'USD',
'DESC' => 'Testing Payments Pro'
);
$nvp_string = '';
foreach($request_params as $var=>$val)
{
$nvp_string .= '&'.$var.'='.urlencode($val);
}
//var_dump($nvp_string); die;
$curl = curl_init();
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_URL, $api_endpoint);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $nvp_string);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSLVERSION, 3);
curl_setopt($curl, CURLOPT_SSL_CIPHER_LIST, 'SSLv3');
//curl_setopt($curl, CURLOPT_SSL_CIPHER_LIST, 'TLSv1');
$result = curl_exec($curl);
if (curl_errno($curl))
{
echo "CURL send a error during perform operation: ".curl_error($curl);
}
else
{
curl_close($curl);
}
// Parse the API response
$nvp_response_array = parse_str($result);
var_dump($result);
But i getting an error like
error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake
failure
And if i not added this two line
curl_setopt($curl, CURLOPT_SSLVERSION, 3);
curl_setopt($curl, CURLOPT_SSL_CIPHER_LIST, 'SSLv3');
then give me an error like
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
Any help?
There was some updates to Sandbox recently, updates that will need to be applied on Live at a later time, this post will help you