I want to make a Adaptive payment from one account to other account.I can get a Access token .But i don't know how to make a Pay API call using Access token.
Actually I want to bypass PayPal login screen.
global $token;
$url = 'https://api.sandbox.paypal.com/v1/AdaptivePayments/Pay';
$createPacket = array(
"actionType" => 'PAY',
"currencyCode" => "SGD",
"receiverList" => array(
"receiver" => array(
array(
"amount" => '34.00',
"email" => 'abc#gmail.com',
)
)
),
"returnUrl" => $params['redirect_url'],
"cancelUrl" => $params['cancel_url'],
'senderEmail' =>'abcd#gmail.com',
"requestEnvelope" => $this->envelope);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $token,
'Accept: application/json',
'Content-Type: application/json'
));
curl_setopt($curl, CURLOPT_POSTFIELDS,json_encode($createPacket) );
#curl_setopt($curl, CURLOPT_VERBOSE, TRUE);
$response = curl_exec($curl);
Your help would be appreciated.
To the best of my knowledge, it is not possible to skip the authentication screen. At some point, the user or owner of the account you are working with must authenticate in order to prove that he has given you permission to perform the work you are doing.
You might wonder why Authentication is needed when you pass an Authorization token in the API call, but the auth token that you pass as 'Authorization: Bearer ' . $token, is actually identification of your application and not the user.
Related
I ma having an issue with getting my access token. I know I have allowed access in the settings in my app. I can read my email with there text page:
I can use the token they provide and retrieve it. But I need to be able to get my own token of course. When I have code below it opens the login page and says "There was an issue looking up your account. Tap Next to try again."
Am I using the right API?
$curl = curl_init();
$auth_data = array(
"Content-Type: application/x-www-form-urlencoded",
'client_id' => 'my-client-id',
'response_type' => 'code',
'redirect_uri' => 'https://myurl.com/authorize.php',
'response_mode' => 'query',
'scope' => 'https://graph.microsoft.com/.default',
'state' => '12345'
);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $auth_data);
curl_setopt($curl, CURLOPT_URL, "https://login.microsoftonline.com/{my_tenant_id}/oauth2/v2.0/authorize");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$result = curl_exec($curl);
if(!$result){die("Connection Failure");}
curl_close($curl);
//echo $result;
var_dump($result);
//print_r($result);
I want to make a simple post request to an API server. I know, there are lot of information about cURL in web, but I can't figure out, why am I getting:
[message] => Authorization has been denied for this request.
So the API uses standard bearer token(in the header Authorization: Bearer {tokenID})
my php code:
$body = array(
"id" => $uuid,
"userAccountId" => $userAccountId,
"email" => $email,
"first_name" => $first_name,
"last_name" => $last_name,
"phone" => $phone,
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, http_build_query(array(
'Authorization' => $token,
)));
curl_setopt($ch, CURLOPT_URL, $myurl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($body));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);
$result = json_decode($result);
The most interesting and weird thing is, that, when I send a Post request to the same url with the same body and the same header(same token) using postman, it works, however it doesn't work with php cURL. Also I tried with https://www.codepunker.com/tools/http-requests and got the same Authorization error. Has anyone any ide what could it be ?
I found the issue: I should have used json_encode($body) instead http_build_query($body) and the header in the following way:
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer .....',
'accept: application/json',
'content-type: application/json',
));
Good morning all,
I'm trying to create a lead entity in Microsoft Dynamics NAV 365, from a php CURL script. However I keep getting a "HTTP Error 401 - Unauthorised: Access is denied" in my CURL response. I can however, create a lead via the web interface fine.
I've created my object from the lead entity type as described on the MSDN docs website.
Below is my code:
$lead = array('person' =>
array(
'topic' => 'WEB LEAD',
'name' => $fullname,
'firstname' => $firstname,
'lastname' => $lastname,
'companyname' => $company,
'telephone1' => $telephone,
'emailaddress1' => $email,
'description' => $comment,
),
);
$dynamics = $url . '/api/data/v8.2/leads';
$ch = curl_init($dynamics);
$options = array(
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json; charset=utf-8',
'OData-MaxVersion: 4.0',
'OData-Version: 4.0',
'Accept: application/json',
),
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_USERPWD, 'username:password',
CURLOPT_POSTFIELDS => json_encode($lead),
);
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
$responseInfo = curl_getinfo($ch);
curl_close($ch);
You need previously get authorization token from AAD
After you get all token you need to add the authorization in the request http header
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json; charset=utf-8',
'OData-MaxVersion: 4.0',
'OData-Version: 4.0',
'Accept: application/json',
'Authorization: <put the token here completly with name>',
),
Adding curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM); solved the problem for me. The whole source looks like this:
$ch = curl_init();
if(!empty($parameters)){ //Add params (array) to your request if you want
$url .= "?".http_build_query($parameters);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
$login = sprintf('%s:%s', self::USERNAME, self::PASSWORD);
curl_setopt($ch, CURLOPT_USERPWD, $login);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Connection: Keep-Alive',
'Accept: application/json',
'Content-Type: application/json; charset=utf-8'
)
);
$response = curl_exec($ch);
$response_info = curl_getinfo($ch);
curl_close($ch);
I created a little app which uses Pushbullet's API.
It is writtent in PhP and uses cURL to proceed the different requests.
At first, I use oauth2 to recieve an access token.
Then it is /v2/pushes/ to send a push to the registred account.
The message is recieved on the Pusbullet account but nothing shows up on the smartphone. There is no notification.
I hope someone can help me.
Thanks.
My function which sends the push:
function send_push($token){
$data = array(
'type' => 'note',
'title' => 'Alert',
'body' => 'My body :)!'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.pushbullet.com/v2/pushes');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer '.$token
));
$data = curl_exec($ch);
curl_close($ch);
}
I'm having some problems using the Neteller API to transfer money out of our merchant account to a user. I've succcessfully received the accessToken, however when I try using transferOut I just get invalid credentials? The code I'm using is:
$headers = array(
"Content-type" => "application/json",
"Authorization" => "Bearer " . $accessToken
);
//build the request body structure
$requestParams = array(
"payeeProfile" => array(
"email" => $the_email_address_to_send_to
),
"transaction" => array(
"merchantRefId" => $transaction_id,
"amount" => $amount,
"currency" => $currencyCode
)
);
// encode the requestParams to a string
$requestParams = json_encode($requestParams);
// The curl stuff
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_URL, "https://api.neteller.com/v1/transferOut");
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $requestParams);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// Ok lets send this lovely looking curl over
$serverOutput = json_decode(curl_exec($curl));
Obviously all variables ($transaction_id, $amount, $currency) are set appropriately. However the response I get back is:
stdClass Object
(
[error] => stdClass Object
(
[code] => 5279
[message] => Authentication credentials are invalid
)
)
I'm confused, surely the accessToken is the credentials I need, and theyve already been received. Am I meant to include anything else in the transferOut curl postfields?
Thanks in advance
As per user3584460's comment:
$headers does not look OK - try $headers = array("Content-type: application/json", "Authorization: Bearer " . $accessToken);. At least this is the format according to http://php.net/manual/en/function.curl-setopt.php
Note, the Merchant Ref ID also needs to be a certain length. unsure what - can't find reference, but 8 characters is not long enough.