cameronmarklewis
cameronmarklewis

Reputation: 264

Gravity Forms WebAPI (GET Forbidden - PHP)

I'm trying to use the Wordpress Gravity Forms Web API to get entries from a form and simply display them. I have this so far, I have made sure to check my API Key and Private Key are correct, with no luck. No matter what I do, I get a Forbidden response.

Here is my code, is there something I'm doing wrong that you can notice?

<?php
$api_key = 'here';
$private_key = 'here';
$method  = 'GET';
$endpoint = 'http://website.co.uk/gravityformsapi/';
//$route = 'entries';
$route = 'forms/1/entries/';
$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;


$ch = curl_init($api_call);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

print_r($response);

echo $api_call;
function calculate_signature($string, $private_key) {
    $hash = hash_hmac("sha1", $string, $private_key, true);
    $sig = rawurlencode(base64_encode($hash));
    return $sig;
}
?>

Thanks!

Upvotes: 0

Views: 1139

Answers (1)

Steven Henty
Steven Henty

Reputation: 526

The user account in the impersonation settings needs to have the appropriate capability, in this case gravityforms_view_entries. You may need to explicitly assign that capability to the role.

Also, try removing the trailing slash from the route.

Upvotes: 1

Related Questions