Search code examples
node.jspodio

Podio - PUT via JS client results in empty field


I am using the Podio JS NPM module (podio-js) to update fields in my Podio app. However, I am having a problem where, rather than updating to the new value, the field simply empties... so it basically updates to null. Furthermore, despite the fact that some sort of update does in fact take place (albeit the wrong update), the console.log()s in the callback are never run - absolutely nothing logs to my console.

Here's the code as I am currently running it:

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

In the docs provided at https://podio.github.io/podio-js/api-requests/, the example requestData variable is defined like so:

var requestData = { data: true };

However, I found that using {data: customer.id} in my code did absolutely nothing - I had to JSON.stringify() it in order to get this to even come close to working.

In an earlier attempt at accomplishing this, I was able to successfully update Podio via AJAX from my client - the data attribute needed to be formatted like so:

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

I have tried every conceivable iteration of the requestData imaginable - stringifying it, stringifying it with additional single quotes (as in my working example), setting it like {data: {value: customer.id}}, etc...

Absolutely nothing works - at best, the field simply empties, at worst there is no effect... and no error messages to help my identify the problem.

What is the proper formatting for a PUT request to Podio via their JS SDK?

UPDATE

On a whim, I thought I'd try using superagent - the following code works perfectly:

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

I used this exact formatting of the data in my original example as well, same problem as before.

What gives?


Solution

  • Got it - had to format my data like this:

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

    Update

    Also, it is worth noting that the callback function for the podio.request() method does not seem to run using the notation described in the documentation. It's a promise, though, so you can treat it as one:

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