Podio - 通过 JS 客户端 PUT 结果为空字段
Podio - PUT via JS client results in empty field
我正在使用 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 向跑道发送 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)
}
})
我在原始示例中也使用了这种精确的数据格式,与之前的问题相同。
什么给了?
知道了 - 必须像这样格式化我的数据:
let requestData = {'value': `${customer.id}`}
更新
此外,值得注意的是 podio.request()
方法的回调函数似乎没有 运行 使用文档中描述的表示法。不过,这是一个承诺,因此您可以将其视为一个承诺:
podio.request('PUT', `${url}/scustomer-id`, requestData)
.then((response) => {
//do stuff...
})
我正在使用 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 向跑道发送 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)
}
})
我在原始示例中也使用了这种精确的数据格式,与之前的问题相同。
什么给了?
知道了 - 必须像这样格式化我的数据:
let requestData = {'value': `${customer.id}`}
更新
此外,值得注意的是 podio.request()
方法的回调函数似乎没有 运行 使用文档中描述的表示法。不过,这是一个承诺,因此您可以将其视为一个承诺:
podio.request('PUT', `${url}/scustomer-id`, requestData)
.then((response) => {
//do stuff...
})