API Gravity form, problem with size of JSON - json

I have a problem with the Rest API of gravity forms, I use it with the cURL method, I have no problem with, except with the size of the JSON chain, he only give me 10 last entries to the concerned forms, if anyone knows how to ask more entry (or all the entries of the form, that would be perfect but some forms have more than 1000 entry, I think it's too heavy for the JSON link).
$CK =ck_12345;
$CS =cs_12345;
$curl = curl_init('https://yoursite.wpserveur.net/wp-json/gf/v2/forms/(form:id)/entries');
curl_setopt_array ($curl, [
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERNAME => "$CK",
CURLOPT_PASSWORD => "$CS",
]);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
$data = curl_exec($curl);
if ($data === false) {
var_dump(curl_error($curl));
}
else {
$data = json_decode($data, true);
}
curl_close($curl);

Related

Easiest way to display specific value from reddit comments .json file?

Is there a simple way to display on my website a specific value, for example "Gonna make this my new alarm ringtone" from following reddit comments .json file: https://www.reddit.com/r/funny/comments/mi0lic/.json
I've found a simple php script that works with reddit user .json files:
... $content = file_get_contents("https://www.reddit.com/user/joshfolgado/about.json");
$result = json_decode($content);
print_r( $result->data->subreddit->title ); ...
But I can't make this work using the comments .json file:
... $content = file_get_contents("https://www.reddit.com/r/funny/comments/mi0lic/.json");
$result = json_decode($content);
print_r( $result->data->children->data->title ); ...
Any other simple script that does the job is also welcome.
The issue can be found here:
print_r( $result->data->children->data->title ); ...
$result->data->children is an Array holding all the comments returned by the API.
We should 'search' all those comments (in your example, it's just 1) for the desired object.
Consider the following code example we're I've used array_filter to custom filter the objects found in $result->data->children array.
<?php
// Search string
$search = 'Gonna make this my new alarm ringtone';
// Get json using CURL
$json = getJson('t3_mi0lic');
// Search ->children
$res = array_filter($json->data->children, function ($child) use ($search) {
// Include if ->data->title qeuals search
return $child->data->title === $search;
});
// Show result
var_dump($res);
// Get JSON by $userId
function getJson($userId) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.reddit.com/api/info/?id=' . $userId,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)'
));
$response = curl_exec($curl);
curl_close($curl);
return json_decode($response);
}

why do i get an error in this json request?

this is my function:
function transaction_create($wallet_id, $passphrase, $payment_address, $payment_amount, $metadata = array()) {
$api_host = "";
$api_user = "";
$api_pass = "";
$api_url = "/v2/";
$api_endpoint = "wallets/" . $wallet_id . "/transactions";
// post body
$transaction = array(
"passphrase" => $passphrase,
"payments" => array(
"address" => $payment_address,
"amount" => array(
"quantity" => $payment_amount,
"unit" => "lovelace"
),
),
"metadata" => $metadata,
"time_to_live" => array(
"quantity" => 10,
"unit" => "second"
)
);
$curl = curl_init('https://' . $api_user . ":". $api_pass . "#". $api_host . $api_url . $api_endpoint);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($transaction));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$api_response = curl_exec($curl);
curl_close($curl);
// $api_response - available data from the API request
return $api_response;
}
this is the docs about the api:
https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/postTransaction
the part that is giving me the problem is formatting the "payments" array. the results of my function are:
"{"code":"bad_request","message":"Error in $.payments: parsing
NonEmpty failed, expected Array, but encountered Object"}"
then if i create a class and make the "payments" into a real object, i get the opposite error, it wants an array not an object... ??!!?? im confused.
From the doc, Amount is an object, not an array - Also, so is Time to Live. PHP seems to have some gotcha's when it comes to JSON - my recommendation would be to try to capture the post as it is presented, and make sure arrays are [] and objects are {}.

Is there any API for ether sent transaction in ethereum

I want to do a transaction (sent ether or token) by API, not from web3.js
I have tried etherscan, block cypher
This is a get balance API code like this I want send transaction code
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.etherscan.io/api?module=account&action=balance&address=0xC1A71f1eFC01D77aA102A9CE248c5360C347Abc8&tag=latest&apikey=YourApiKeyToken",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_TIMEOUT => 30000,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
// Set Here Your Requesred Headers
'Content-Type: application/json',
),
));
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
What you need to do is to make a RPC call to a ethereum node. Basically, web3 libraries are wrappers around this.
Docs can be found here : https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sendtransaction

WordPress Cron Job import posts

I am building a site to import products from an JSON feed, and then display them as posts in my site.
I am using a cron job to run an import every day at 3am, but I have a question regarding the setup of it all.
Would it be good practice to import the feed, create posts based on the feed and then populate the posts on the site?
To remove duplicates I would run a DB check for the product ID and skip those that are already created.
I am really new to cron and dynamically creating posts so I am not sure if this is the best way to go about it.
I solved it by adding an AJAX handler to my functions.php, fetch the jobs through a curl request and then looping through the feed inserting new posts to DB and updating already existing posts.
//CURL request to fetch feed when getting AJAX call
function import_feed() {
$url = "http://url-to-jsonfeed.com";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$data = json_decode($response, true);
create_posts($data);
wp_die();
}
add_action('wp_ajax_import_feed', 'import_feed');
//Loop through JSON data and create post
function create_posts($jsonfeed) {
$data = $jsonfeed['Report'];
if (!empty($data) ) {
foreach ($data as $entry) {
//Set post data before creating post
$post_data = array(
'post_title' => $entry['Entry_Title'],
'post_name' => $entry['EntryID'],
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'entries'
);
if (get_page_by_title($post_data['post_title'], 'entries') == null && empty(get_posts(array('post_type' => 'entries', 'name' => $post_data['post_name'])))) {
wp_insert_post($post_data, $wp_error);
} else if (!empty(get_posts(array('post_type' => 'entries', 'name' => $post_data['post_name'])))) {
$post = get_posts(array('post_type' => 'entries', 'name' => $post_data['post_name']));
$post_id = $post[0]->ID;
$post_data['ID'] = $post_id;
wp_update_post($post_data, $wp_error);
}
}
}
}

Can't create a Folder using BOX API v2.0

function post($url, $params, $headers) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$parent_id = 0;
$name = 'examplefolder';
$params = array('name' => $name => json_encode(array('id' => $parent_id)));
$resp = post('https://api.box.com/2.0/folders', $params, array('Authorization: Bearer ' . $ACCESS_TOKEN_HERE));
When this code executes I got this error in Json format
{"type":"error","status":400,"code":"bad_request","context_info":{"errors":[{"reason":"missing_parameter","name":"parent","message":"'parent' is required"},{"reason":"missing_parameter","name":"name","message":"'name' is required"}]},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Bad Request","request_id":"204107642652b93aceca050"}
Is there anything I'm missing?
Additional note.
I even tried to make the params a query string like this.
name=examplefolder&parent={"id":0}
and this gives me a different error
{"type":"error","status":400,"code":"bad_request","context_info":{"errors":[{"reason":"invalid_parameter","name":"entity-body","message":"Invalid value 'name=examplefolder&parent={\"id\":0}'. Entity body should be a correctly nested resource attribute name\/value pair"}]},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Bad Request","request_id":"154368831052b93bb027779"}
I'm not totally familiar with this language syntax, but it looks to me like the parent object is not declared in your POST body. You need to be sending this:
{"name":NAME, "parent":{"id":"0"}}
You might be able to accomplish that by changing your $params like so:
$params = array('name' => $name, 'parent' => json_encode(array('id' => $parent_id)));
Also, per the documentation the $parent_id should be serialized as a string, not as an integer.
{"name":NAME, "parent":{"parent_id":"0"}}
This worked for me when I was working Angular 1 - angular file upload module.
However it is different with angular2, still working on..
vm.uploader.onBeforeUploadItem = function (item) {
if (!vm.parentFolderId || item.isVersionUpload) return;
item.headers = { Authorization: 'Bearer ' + vm.userToken };
item.formData = {
name: item.file.name,
parent: {
parent_id: vm.parentFolderId
}
};
}