重力表单Web API更新入口


Gravity Forms Web API Update Entry

我正在尝试使用重力表单Web API来更新条目,这是我目前拥有的php代码。

<?php
$api_key = '';
$private_key = '';
$method  = 'PUT';
$endpoint = 'https://www.website.co.uk/gravityformsapi/';
//$route = 'entries';
$route = 'entries/61';
$expires = strtotime('+60 mins');
$string_to_sign = sprintf('%s:%s:%s:%s', $api_key, $method, $route, $expires);
$sig = calculate_signature($string_to_sign, $private_key);
$api_call = $endpoint.$route.'?api_key='.$api_key.'&signature='.$sig.'&expires='.$expires;
//array of entries (each entry is an array with key=field id)
$entries = array(
array("status"=>"active","1.3"=>$_POST['first_name'],)
);
$ch = curl_init($api_call);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($entries));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
$result = curl_exec($ch);
function calculate_signature($string, $private_key) {
    $hash = hash_hmac("sha1", $string, $private_key, true);
    $sig = rawurlencode(base64_encode($hash));
    return $sig;
};
?>

我得到的响应是成功更新了帖子,但不是更新帖子,它似乎删除了帖子。有人能看到我的代码有什么问题吗?如果我刷新我在Wordpress上编辑的条目的页面,我得到这个错误。

Fatal error: Cannot use object of type WP_Error as array in /data02/c6536622/public_html/wp-content/plugins/gravityforms/entry_detail.php on line 57

是否有一个日志来找出使用重力表单或WordPress出了什么问题?

当您更新单个条目时,只需发送一个条目而不是集合。此外,发送整个条目,否则您将最终删除缺失字段的所有值。