简体   繁体   中英

Create webhook-url in formstack via api using php

I want to create a webhook url for pitifuller form by id here is my code i don't know what is my mistake

 define('CLIENT_ID', 'client_id');
 define('CLIENT_SECRET', 'client_secret');
 define('REDIRECT_URL', 'redirect url'); // for testing, use    the URL to this PHP file.

 define('AUTHORIZE_URL', 'https://www.formstack.com/api/v2/oauth2/authorize');
 define('TOKEN_URL', 'https://www.formstack.com/api/v2/oauth2/token');
 $ch = curl_init(TOKEN_URL);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
'grant_type' => 'authorization_code',
'client_id' => CLIENT_ID,
'redirect_uri' => REDIRECT_URL,
'client_secret' => CLIENT_SECRET,
'id' => 'id', // here is my id
'url' => 'web_hook_url' // here is my webhook url which i want to create
 )));
// oauth2 contains the the access_token.
 $oauth2 = json_decode(curl_exec($ch));

You did mistake in your CURL call, currently you are pass post data in GET form and you need to pass Like this(POST form/:id/webhook), and you can do this:

$ch = curl_init('https://www.formstack.com/api/v2/form/your-form-id/webhook');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $oauth2->access_token
));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
'id' => $_POST['id'],
 'url' => 'http://www.getbravo.com/formstack/index.php',
'append_data' => '1'
)));

and you get response like this

 $forms = json_decode(curl_exec($ch)); 
 print '<pre>';
 print_r($forms);
 print '</pre>'; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM