Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Send API data via POST on page load? WordPress

  • SOLVED

Hello,

I'm creating a simple email signup form with Formidable as a way to act as a double opt-in for a service that does not currently have a way to handle double opt in confirmations (https://roboticdogs.actionkit.com/docs/manual/api/rest/actionprocessing.html) . The process is intended to work like this:

1. User enters email address on website
2. Formidable sends a confirmation email w/ a link to click to the confirm. That url has a few parameters in it (domain.com/newsletter/?verified=1&key=[formkey]&email=[email]
3. What I would then like to do is grab the url parameters (easy enough) and use that to make a POST to the ActionKit API, and if the response is successful show the related confirmation template data on the WordPress site.

The JSON submission to the AK API only needs to keys -- page (which is taken from within actionkit itself) and the email (which would come from the url parameter)

[https://roboticdogs.actionkit.com/docs/manual/api/rest/actionprocessing.html#authenticated]

I've done work with REST APIs in the past but I just want to make sure I have the order correct here and its done in an efficient and secure way.

Thanks!

Answers (2)

2020-01-28

John Cotton answers:

I'm assuming you mean this code to run when the user clicks on the link in your email?

That being the case something like this should work:

$args = array();
$args['headers'] = array(
'Authorization' => 'Basic ' . base64_encode( "{YOUR_USER_NAME}:{YOUR_PASSWORD} ),
'Content-type' => 'application/json' );

$args['body'] = json_encode( array( 'page': YOUR_PAGE_VALUE, 'email': $_REQUEST['email'] ) );

$response = wp_remote_post( 'https://roboticdogs.actionkit.com/rest/v1/action/', $args );

2020-01-29

Darlene Grace Arcenal answers:

Is this the one you are looking for?


$url = "http://domain.com/newsletter/?verified=1&key=[formkey]&email=[email]";
$json = file_get_contents($url);
$json_data = json_decode($json, true);
$email = $json_data["email"];
$key = $json_data["key"];