2017-04-17 57 views
0

我使用Podio-js SDK從應用程序項目獲取數據,將其格式化爲URL,並將該URL重新放回到同一項目中的字段中。 PUT請求會返回一個空的響應(有時會說它'不能讀取未定義的屬性值',或者它清空了現場中的文本而不是更新它。我認爲這與我的信息格式I通過它,我曾嘗試在JSON對象格式{「關鍵」:「值」}格式化。對語法,但我得到了類似的結果使用Podio-js PUT請求更新應用程序項目字段

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

請問您可以解釋wh你是否從'/ app/17969235/item/1/value/144508059 /'得到了?我對item_id特別感興趣,因爲某些原因1. –

+0

@Pavlo應用程序ID號和字段ID號是從Podio應用程序的開發者頁面中提取的。 Item(此例中爲1)的app_item_id傳遞給該函數並存儲在itemID中。 /註冊期望以app_item_id作爲請求主體的webhook發佈請求。 –

+0

您是否嘗試過使用'item_id'而不是'app_item_id'? –

回答

0

我沒有正確處理的承諾,我把GET和PUT請求。在同樣的承諾鏈中.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)) 
    }) 
})