使用php通过api在formstack中创建webhook-url

时间:2014-04-16 04:11:35

标签: php formstack

我想通过id创建一个可怜的形式的webhook网址这里是我的代码我不知道我的错误是什么

 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));

1 个答案:

答案 0 :(得分:1)

你在CURL电话中错了,目前你是以GET形式传递数据,你需要传递像这样(POST表格/:id / webhook),你可以这样做:

$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'
)));

你得到这样的反应

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