Alright, i have searched this and many more forums, no solution for me.
I have this code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payment");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer ' . $this->auth['access_token']
));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array(
'intent' => 'sale',
'redirect_urls' => array(
'return_url' => 'http://andershagbard.wep.dk/goingpro/',
'cancel_url' => 'http://andershagbard.wep.dk/goingpro/'
),
'payer' => array (
'payment_method' => 'paypal'
),
'transactions' => array(
'amount' => array(
'total' => '5.00',
'currency' => 'USD'
),
'description' => 'This is the payment transaction description.'
)
)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
And it returns
(
[name] => MALFORMED_REQUEST
[message] => Incoming JSON request does not map to API request
[information_link] => https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST
[debug_id] => 27f7487f9c07f
Related
Here is curl code which is working very good
$data = array(
"to" => $to ,
"from" => $options['from_email'] ,
"subject" => $subject,
"body" => $message,
);
$url = 'https://example.com';
$api_key = 'apikeyhere'
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Content-Type: application/json',
'X-API-KEY:'.$api_key
));
$response = curl_exec($ch);
But if i try to convert this above code to worpress wp_remote_post i am getting error.
$response = wp_remote_post( $url, array(
'method' => 'POST',
'timeout' => 45,
'blocking' => true,
'sslverify' => false,
'httpversion' => '1.0',
'redirection' => 5,
'headers' => array(
'Accept: application/json',
'Content-Type: application/json',
'X-API-KEY:'.$api_key
),
'body' => json_encode($data),
) );
here is response i am getting
https://pastebin.com/Ap5LpfZb
Please let me know where i am doing wrong ?
I got it there was problem with the header array i was passing that array wrongly
Wrong code was
$response = wp_remote_post( $url, array(
'method' => 'POST',
'timeout' => 45,
'blocking' => true,
'sslverify' => false,
'httpversion' => '1.0',
'redirection' => 5,
'headers' => array(
'Accept: application/json',
'Content-Type: application/json',
'X-API-KEY:'.$api_key
),
'body' => json_encode($data),
) );
Here is correct version of code
$response = wp_remote_post( $url, array(
'method' => 'POST',
'timeout' => 45,
'blocking' => true,
'sslverify' => false,
'httpversion' => '1.0',
'redirection' => 5,
'headers' => array(
'Accept'=> 'application/json',
'Content-Type' =>'application/json',
'X-API-KEY' => $api_key,
),
'body' => json_encode($data),
) );
I am using this script in PHP to capture google products through ZenSerp. I can get an output with all the terms.
Example;
Title
Description
Price
Image
URL Link
Is there a way to print
1.price
2.title
3.description
on another page?
thanks.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$data = [
"q" => "Tools",
"tbm" => "shop",
"device" => "desktop",
"location" => "Manhattan,New York,United States",
];
curl_setopt($ch, CURLOPT_URL, "https://app.zenserp.com/api/v2/search?" . http_build_query($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"apikey: XXXX",
));
$response = curl_exec($ch);
curl_close($ch);
$json = json_decode($response);
echo '<pre>' . var_export($json, true) . '</pre>';
?>
Output:
(object) array(
'title' => 'Craftsman 320-Piece Mechanic S Tool Set',
'link' => '/aclk?sa=L&ai=DChcSEwjn5sb54NDtAhXHfysKHWT9BIIYABBXGgJzZg&sig=AOD64_1kzP9frQqO7uULjK4LGcDJkpuuGA&ctype=46&q=&ved=0ahUKEwjP9cL54NDtAhUBjeYKHaqqBzgQ_-QECL8H&adurl=',
'description' => 'Mechanic ยท CRAFTSMAN',
'price' => '$149.99',
'source' => 'Sears',
'stars' => 4.5999999999999996447286321199499070644378662109375,
'reviews' => 1084,
'thumbnail' => 'data:image/jpeg;base64,/',
'extensions' =>
array (
),
'product_id' => '13276029442981215243',
'price_parsed' =>
(object) array(
'currency' => 'USD',
'value' => 149.990000000000009094947017729282379150390625,
I have tried reloadly API stated on their doc but no success, i could not find exactly the correct API end point to make Curl call.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://topups.reloadly.com/accounts/balance
");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/com.reloadly.topups-v1+json",
"Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik0wWXpRa"
));
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
I got from their their API doc https://topupsapi.docs.apiary.io it stated on sending airtime but no correct endpoint stated. thank
Is there any function or correct endpoint i didn't know about?
the endpoint is https://topups.reloadly.com/topups , and it's supposed to look something like this:
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => 'https://topups.reloadly.com/topups',
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => array(
"Accept: application/com.reloadly.topups-v1+json",
"Content-Type: application/json",
"Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSU",
),
CURLOPT_POSTFIELDS => json_encode(array(
'recipientPhone' => array(
'countryCode' => 'HT',
'number' => '+50936377111',
),
'senderPhone' => array(
'countryCode' => 'US',
'number' => '+13059547862',
),
'operatorId' => 173,
'amount' => 15,
'customIdentifier' => 'transaction by john#example.com',
))
));
curl_exec($ch);
curl_close($ch);
<?php
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => 'https://topups.reloadly.com/topups',
CURLOPT_POST => 1,
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/com.reloadly.topups-v1+json",
"Authorization: Bearer your_access_token")),
CURLOPT_POSTFIELDS => json_encode(array(
'recipientPhone' => array(
'countryCode' => 'HT',
'number' => '+50936377111'
),
'senderPhone' => array(
'countryCode' => 'US',
'number' => '+13059547862'
),
'operatorId' => 173,
'amount' => 15,
'customIdentifier' => 'transaction by john#example.com'
))
));
$response = curl_exec($ch);
curl_close($ch);
echo '<pre>';
var_dump($response);
echo '</pre>';
[enter image description here][1]?>
I am using one signal API For push notification. And I want to know how can I send button with value(Confirm = 1, Deny =0) so that I can post it from the notification screen. I am not able to send action button through API t the app. I want to post the value of the action button in the database. Please help
This is my code.
function sendMessage(){
$heading=array(
"en" => 'TEST'
);
$content = array(
"en" => 'TEST.'
);
$hashes_array = array();
array_push($hashes_array, array(
"id" => "1",
"text" => "Confirm",
"icon" => "http://i.imgur.com/N8SN8ZS.png",
"url" => "https://yoursite.com"
));
array_push($hashes_array, array(
"id" => "0",
"text" => "Deny",
"icon" => "http://i.imgur.com/N8SN8ZS.png",
"url" => "https://yoursite.com"
));
$fields = array(
'app_id' => "xxxxxxx-xxxxxxx-45b8-97d4-02982b59c14f",
'include_player_ids' => array($GLOBALS['one_signal_id']),
'data' => array("Status" => 200),
'small_icon' => 'https://lh3.googleusercontent.com/TzYz9McRVy8fD_WnpKiCK5anw20So6eyPR9ti-LwTd_QIer8BpAg8cMkRoO4sUv2xCDw=w300-rw',
'large_icon' => 'https://lh3.googleusercontent.com/TzYz9McRVy8fD_WnpKiCK5anw20So6eyPR9ti-LwTd_QIer8BpAg8cMkRoO4sUv2xCDw',
'headings' => $heading,
'contents' => $content,
'web_buttons' => $hashes_array
);
$fields = json_encode($fields);
// print("\nJSON sent:\n");
// print($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
'Authorization: Basic xxxxxxxxxxxxxxxxxxxxxx5NjktMjRkZWM0ZjFhMjZl'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
$response = sendMessage();
The following is my script. I am continuously getting an invalid_scope error.
$arr = array(
'file' =>
array(
'name' => 'pdf.pdf',
'source' => 'upload',
),
'document' =>array(
'signer_sequencing' => 'false',
'expires_in' => '12',
'name' => 'Signme',
'roles' =>array(
'name' => 'a',
'signer_email' => 'example#gmail.com',
'signer_name' => 'farqalit',
),
),
'sending_request' =>array(),
);
$post_json = json_encode($arr);
$endpoint = "https://api.rightsignature.com/public/v1/sending_requests?access_token=API_TOKEN";
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_json);
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' ));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);