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]?>
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,
Whenever I try this it replies with "400 bad request"
I've tried adding a client id but I'm not exactly sure how to get that
$url = 'https://discordapp.com/api/v6/science';
$data = json_decode($response);
$ch = curl_init();
$json = array( "channel_id" => $data->channel->id,
"channel_type" => $data->channel->type,
"client_performance_cpu" => 48,
"client_performance_memory" => 833620,
"client_send_timestamp" => time(),
"client_track_timestamp" => time(),
"client_uuid" => $data->channel->id,
"code" => $_GET["invite"],
"destination_user_id" => null,
"guild_id" => $data->channel->id,
"invite_type" => "Server Invite",
"inviter_id" => $data->inviter->id,
"location" => "Join Guild Modal",
"resolved" => "true",
"size_online" => $data->approximate_presence_count,
"size_total" => $data->approximate_member_count,
"type" => "resolve_invite",
"token" => $_GET["token"]
);
$payload = json_encode($json);
echo $payload;
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => array('Authorization: ' . $_GET["token"]),
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_VERBOSE => 1,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_POSTFIELDS => $json
));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($payload)
));
$response = curl_exec($ch);
fclose($f);
curl_close($ch);
echo "<br/><br/>" . $response;
(data is defined it's just on another part of my code)
I want it to accept the invite
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);
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