如何访问触发文件中的身份验证响应

时间:2019-07-01 06:32:24

标签: php command-line-interface zapier

当用户尝试连接我的Zapier应用时,我会要求登录。我使用了自定义身份验证,您可以在下面看到代码。

const testAuth = (z , bundle) => 
   {
    var email = bundle.authData.email;
    var password = bundle.authData.password;
    return z.request({
      method: 'POST',
      url: 'http://mysite/check_login',
     }).then((response) => {
     if (response['status'] === 201) {
       throw new Error('Your credentials is not match with our database');
     }
     else
     {
       var obj = JSON.parse( response.content );
       var  user_id =obj.user_id;
       return user_id;
     }
   });

此操作已成功运行,现在我要在以下位置使用此返回数据user_id 触发下面列出的page(list.js)代码,

const list = (z, bundle) => {
 //I WANTS TO USE THAT USER_ID OVER HERE
 //USER_ID=;
 const promise = z.request('http://mysite/list_data/'+USER_ID,
 {
   params: {} 
 });
 return promise.then((response) => response.json);
};

请帮助我了解如何在触发文件中访问身份验证响应。

3 个答案:

答案 0 :(得分:0)

为类似screnshot下面的触发器创建动态下拉字段

this

在执行API调用中访问user_id。

以下是利用动态下拉菜单功能的示例应用程序:

https://github.com/zapier/zapier-platform-example-app-dynamic-dropdown

更多有用的文章:

  1. https://platform.zapier.com/cli_tutorials/dynamic-dropdowns
  2. https://platform.zapier.com/cli_docs/docs#dynamic-dropdowns

答案 1 :(得分:0)

Zapier Platform团队的David在这里。好问题!

通常,computed fields是这里的答案,但是目前无法使用OAuth之外的那些。

在您的情况下,有两种选择:

  1. 如果用户有一种简便且明显的方式来手动提供其ID,则可以将其添加到auth字段中,并根据需要使用它
  2. 否则,在运行每个触发器以获取用户ID之前,您需要调用登录端点。您有30秒的执行时间,因此可以执行第二个API请求。

答案 2 :(得分:0)

是的,不是发送auth响应返回的user_id,而是在URL末尾发送bundle.authData.email。

access_token

};