【问题标题】:Update App Item Field using Podio-js PUT request使用 Podio-js PUT 请求更新应用项目字段
【发布时间】:2017-04-17 14:43:34
【问题描述】:

我正在使用 Podio-js SDK 从 App Item 获取数据,将其格式化为 URL,然后将该 URL 放回同一项目的字段中。 PUT 请求要么返回一个空响应(有时说它'无法读取未定义的属性'值',或者它清空字段中的现有文本而不是更新它。我认为这与我的信息格式有关通过它。我尝试使用 {"key" : 'value'} 对语法以 JSON 对象格式格式化,但我得到了类似的结果。

app.post('/signup',urlencodedParser, function(req, res) {

  //gather information from the item student registry entry and format a link
  //to pre-populated Podio webform

  podio.isAuthenticated().then(function() {

    var itemID = Object.keys(req.body)[0];
    var token = podio.authObject.accessToken;
    var itemPath = `/app/${creds.appID}/item/${itemID}?oauth_token=${token}`;
    var fieldPath = `/item/571453849/value/signup-link`;
    var link;   

    podio.request('GET', itemPath).then(function(responseData) {

        //this request works
        //console.log(JSON.stringify(responseData, null, 4));

          var student = {
            "studentID": responseData.app_item_id,
         }

         var requestData = { url: `www.example.com/${student.studentID}` }

         console.log('\n');
         console.log('fieldpath: ' + fieldPath + '\n');
         console.log('generatedlink: ' + link + '\n');

    }).catch(function(f) {
        console.log(f)
        })

    podio.request('PUT', fieldPath, link).then(function(responseData) {
        //I want to PUT this item 'link' back into a field in the same 
        //item, but I get the error message below
        console.log(JSON.stringify(responseData, null, 4));
        res.end();
    }).catch(function(f) {
        console.log(f)
        })
})

【问题讨论】:

  • 你能解释一下你从哪里得到/app/17969235/item/1/value/144508059/吗?我对 item_id 特别感兴趣,出于某种原因 1。
  • @Pavlo App ID 号和 Field ID 号是从 Podio 上应用的开发者页面拉取的。 Item 的 app_item_id(在本例中为 1)被传递给函数并存储在 itemID 中。 /signup 需要一个以 app_item_id 作为请求正文的 webhook 发布请求。
  • 你试过用item_id代替app_item_id吗?
  • @Pavlo-Podio 我尝试了 item id 并尝试了类似的错误消息路径,其中 item_id 为 571453849 代替了 1
  • @Pavlo-Podio 我意识到我需要摆脱 /app/17969235 部分,只需使用 /item/571453849/value/144508059/ 作为路径。但是,现在我面临着 Podio 收到请求的问题,我在我的网络表单上看到该字段已更新,但它仍然是空白的。格式化数据字符串以作为 PUT 请求中的“requestData”参数传递的正确方法是什么?谢谢!

标签: javascript podio


【解决方案1】:

我没有正确处理承诺。我将 GET 和 PUT 请求放在同一个承诺链中,最后使用相同的 .catch。此外,我格式化了我的请求,如下所示,并且能够成功地将数据放入字段中。

app.post('/signup', urlencodedParser, (req, res) => {

    podio.isAuthenticated()
    .then(function() {

        var appItemID = Object.keys(req.body)[0];
        var token = podio.authObject.accessToken;
        var itemPath = `/app/${creds.appID}/item/${appItemID}?oauth_token=${token}`;

        return podio.request('GET', itemPath)
    })
    .then(function(responseData) {
        //this request works
        //console.log(JSON.stringify(responseData, null, 4));
        var student = {
            "itemID": responseData.item_id,
        }

        var fieldPath = `/item/${student.itemID}/value/signup-link-2`;  
        var requestData = { url: `https://podio.com/webforms/[formattedLink`

        return podio.request('PUT', fieldPath, requestData)
    })
    .then(function(responseData) {

        res.end(JSON.stringify(responseData, null, 4))
    })
    .catch(function(f) {
        console.log(f)
        res.end(JSON.stringify(f, null, 4))
    })
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-30
    • 1970-01-01
    • 2021-12-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多