Podio - PUT通过JS客户端导致空字段

时间:2017-03-28 18:11:07

标签: node.js podio

我正在使用Podio JS NPM模块(podio-js)来更新我的Podio应用程序中的字段。但是,我遇到了一个问题,即该字段只是清空而不是更新到新值,所以它基本上更新为null。此外,尽管事实上确实发生了某种更新(虽然更新错误),但回调中的console.log()永远不会运行 - 绝对没有任何日志记录到我的控制台。

这是我正在运行的代码:

podio.isAuthenticated().then(() => {
    let url = `/item/${podio_item_id}/value/customer-id`
    let requestData = JSON.stringify({data: customer.id})

    podio.request('PUT', url, requestData, (responseData) => {
        console.log("made it")
        console.log(responseData)
    })
})

https://podio.github.io/podio-js/api-requests/提供的文档中,示例requestData变量的定义如下:

var requestData = { data: true };

然而,我发现在我的代码中使用{data: customer.id}并没有做任何事情 - 我必须JSON.stringify()才能让它接近工作。

在早期的尝试中,我能够通过AJAX从我的客户端成功更新Podio - 数据属性需要格式化如下:

data: JSON.stringify({'value': 'true'})

我已经尝试了requestData可想象的每一个可想象的迭代 - 将其字符串化,用其他单引号进行字符串化(如我的工作示例中所示),将其设置为{data: {value: customer.id}}等等......

绝对没有任何作用 - 充其量,该字段只是清空,最坏的情况是没有效果......并且没有错误消息来帮助我识别问题。

通过他们的JS SDK向Podio发出PUT请求的正确格式是什么?

更新

一时兴起,我以为我尝试使用superagent - 以下代码完美运行:

superagent                  
   .put(`https://api.podio.com/item/${podio_item_id}/value/customer-id`)
   .set('Authorization', `OAuth2 ${accessToken}`)
   .set('Content-Type', 'application/json')
   .send(JSON.stringify({'value': `${customer.id}`}))
   .end(function(err, res){
       if (err || !res.ok) {
           console.log(err)
       } else {
           console.log(res)
       }
})

我在原始示例中使用了这种数据的精确格式,与之前的问题相同。

是什么给出了?

1 个答案:

答案 0 :(得分:1)

得到它 - 必须格式化我的数据:

let requestData = {'value': `${customer.id}`}

<强>更新

另外,值得注意的是podio.request()方法的回调函数似乎没有使用文档中描述的符号运行。不过,这是一个承诺,所以你可以把它当成一个:

podio.request('PUT', `${url}/scustomer-id`, requestData)
.then((response) => {
    //do stuff...
})
相关问题