Search code examples
podio

Podio - updating item field results in empty field


I'm trying to update an item field value in Podio via AJAX request - I can make the requests successfully, but rather than updating the field value to the value passed in the request, the item field in Podio is simply emptied (as though updated to an empty value). Here's the call:

    $.ajax({
        type:'PUT',
        beforeSend: function (xhr) {
                xhr.setRequestHeader('Authorization', 'OAuth2 ' + response.access_token)
            },
        url:'https://api.podio.com/item/654321/value/12345',
        data: JSON.stringify({'value': 'new_value'})
    }).done(function(response){
        console.log(response)
    }).fail(function(error){
        console.log(error)
    })

But the result of this will be to simply erase the old field value. Close, but no cigar.

How should the data attribute be formatted for Podio to correctly update the field value?

(I understand that there are a number of Podio client libraries that can help with this, but they are not useful to us in our current situation - we need to handle this process via good ol' AJAX)


Solution

  • Got it - it was an easy fix, just had to set the contentType. Silly me.

    $.ajax({
        type:'PUT',
        beforeSend: function (xhr) {
                xhr.setRequestHeader('Authorization', 'OAuth2 ' + response.access_token)
            },
        contentType: 'application/json',
        url:'https://api.podio.com/item/654321/value/12345',
        data: JSON.stringify({'value': 'new_value'})
    }).done(function(response){
        console.log(response)
    }).fail(function(error){
        console.log(error)
    })