我正在使用Podio-js SDK从应用程序项中获取数据,将其格式化为URL,并将该URL返回到同一项中的字段中。 PUT请求要么返回一个空响应(有时会说它不能读取属性'未定义的值,或者它会清空字段中的现有文本而不是更新它。我认为它必须处理我传递的信息的格式。我尝试使用{"键":'值'}对语法格式化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)
})
})
答案 0 :(得分:0)
我没有正确处理承诺。我将GET和PUT请求放在同一个promise链中,最后使用相同的.catch。此外,我格式化了我的请求,如下所示,并成功地能够在字段中PUT数据。
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))
})
})