0
votes

I am using the Podio-js SDK to GET data from an App Item, format it into a URL, and PUT that URL back into a field in the same item. The PUT request either returns an empty response (sometimes saying that it 'cannot read property 'values' of undefined, or it empties the existing text in the field instead of updating it. I think it has to do with my formatting of the information I pass it. I have tried formatting in JSON object format with {"key" : 'value'} pair syntax but I get similar results.

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)
        })
})
1
Can you please explain where you get /app/17969235/item/1/value/144508059/ from? I'm especially interested in item_id which is for some reason 1.Pavlo - Podio
@Pavlo The App ID number and Field ID number are pulled from the developer page of the app on Podio. The app_item_id of the Item (in this case, 1) is passed to the function and stored in itemID. /signup expects a webhook post request with the app_item_id as the request body.user2231715
Have you tried using item_id instead of app_item_id ?Pavlo - Podio
@Pavlo-Podio I tried item id instead and got a similar error message path attempted had item_id of 571453849 in place of 1user2231715
@Pavlo-Podio I realized that I need to get rid of the /app/17969235 part and just use /item/571453849/value/144508059/ as the path. However, now I am facing the issue that Podio gets the request, and i see on my webform that the field has been updated, but it remains blank. What is the correct way to format a string of data to pass as the 'requestData' parameter in the PUT request? Thanks!user2231715

1 Answers

1
votes

I was not handling promises correctly. I put the GET and PUT request in the same promise chain with the same .catch at the end. Also, I formatted my request as seen below and am successfully able to PUT data in fields.

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))
    })
})