Creating a form post (adding) via API

When I try to create a form posting via the API I just get an error message “A valid URL was not provided”

This is the code I am using ?

<?php

/*

Template Name: test api */

function calculate_signature( $string, $private_key ) {

$hash = hash_hmac( ‘sha1’, $string, $private_key, true );

$sig = rawurlencode( base64_encode( $hash ) );

return$sig;

}

$base_url = ‘https://xx.xx.com/gravityformsapi/’;

$api_key = ‘xx’;

$private_key = ‘xx’;

$method = ‘POST’;

$route = ‘forms/12/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 );

$url = $base_url . $route . ‘?api_key=’ . $api_key . ‘&signature=’ . $sig . ‘&expires=’ . $expires;

var_dump($url);

$entries = array(

array(

‘date_created’ => ‘2018-12-17 11:08:23’,

‘is_starred’ => 0,

‘is_read’ => 0,

‘ip’ => ‘::1’,

‘source_url’ => ‘https://xx.xx.com/emai/?email=267’,

‘currency’ => ‘USD’,

‘created_by’ => 1,

‘user_agent’ => ‘Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0’,

‘status’ => ‘active’,

‘8’ => ‘xx@hotmail.com’,

‘1.3’ => ‘xx’,

‘1.6’ => ‘xx’,

‘3’ => ‘xx@hotmail.com’,

‘5’ => ‘1234’,

‘2’ => ‘The Crows’,

‘4’ => ‘The Crows MSG’,

),

);

//json encode array

$entry_json = json_encode( $entries );

echo"<br/>";

echo"<br/>";

var_dump($entry_json);

//retrieve data

$response = wp_remote_request( urlencode( $url ), array( ‘method’ => ‘POST’, ‘body’ => $entry_json ) );

echo"<br/>";

echo"<br/>";

var_dump($response);

if ( wp_remote_retrieve_response_code( $response ) != 200 || ( empty( wp_remote_retrieve_body( $response ) ) ) ){

//http request failed

die( ‘There was an error attempting to access the API.’ );

}

//result is in the response "body" and is json encoded.

$body = json_decode( wp_remote_retrieve_body( $response ), true );

if( $body[‘status’] > 202 ){

$error = $body[‘response’];

//entry update failed, get error information, error could just be a string

if ( is_array( $error )){

$error_code = $error[‘code’];

$error_message = $error[‘message’];

$error_data = isset( $error[‘data’] ) ? $error[‘data’] : ‘’;

$status = "Code: { $error_code } . Message: { $error_message } . Data: { $error_data } .";

}

else{

$status = $error;

}

die( "Could not post entries. { $status } " );

}

$entry_ids = $body[‘response’];

$entry_ids_created = ‘The following entry ids were created:</br>’;

foreach ( $entry_idsas$entry_id ){

$entry_ids_created .= $entry_id . ‘</br>’;

}

I recommend submitting a support ticket for this issue:

https://www.gravityforms.com/open-support-ticket/

Or you actually could help and show the community that you are there to assist since all I see Chris are road blocks to using your product.

It’s probably only 5 mins of your time to look and give some help on the subject . I have inherited this site and don’t have a login for a support ticket even though I sent you proof I’m using a valid license.

This is not a support forum, and we’re able to provide support only to registered license holders. I’m sorry you’re not able to open a support ticket.

Looking at your code, rather than the above, can you try this instead?

$response = wp_remote_request( $url, array( ‘method’ => ‘POST’, ‘body’ => $entry_json ) );

Thank you

It did help but now I get the response

status":401,“response”:"Permission denied

why would I get this error? I can update an existing entry without any issues. I can’t create an entry?

Many Thank