Post

4 followers Follow
0
Avatar

Javascript, Update Item field value

Can you give us an example of a properly formatted javascript request that works with the podio-js client library for updating an item's field value? 

The docs essentially run in circles and looking at the ruby/php code it seems that there is an options object that is not mentioned anywhere in the js library for put requests.

Here's what I'm trying to do:

router.get('/app/put/item/field', function(req, res) {
    podio.isAuthenticated()
    .then(function(error, response, body) {
        var requestData = {
            "values": " some string 42"
        };
    return podio.request('put', '/item/{item_id}/value/{field_id}', requestData);
    })
    .then(function(responseData) {
        console.log(responseData);
    })
    .catch(function(err) {
        res.send(err);
    });
});

 

Thanks.

Brian Keppinger

Official comment

Avatar

Hi Brian,

I can spot 2 problems with your code, so let's start with those:


#1

You are returning the result of podio.request, but that will simply be undefined because it's an async operation and the result of that operation will be available to you in the callback (that you're missing there).

E.g. 

podio.request('put', '/item/{item_id}/value/{field_id}', requestData, function(reponse) {
    console.log('Hey there', response);
});


#2

The url you're using will never work because you're not actually replacing the placeholders with real values.

Something like this will work:

var itemId = 12345;
var fieldId = 28987;
var url = '/item/' + item_id + '/value/' + field_id

Or, with the new fancy ES6 syntax (note backticks and dollar signs):

const itemId = 12345;
const fieldId = 28987;
const url = `/item/${item_id}/value/${field_id}`

podio.request('PUT', url, requestData, function(reponse) {
    console.log('Hey there', response);
});

 

Hope that helps, and for future reference you can take a look at the documentation for making API requests through the podio-js client.

Domenico Matteo

Please sign in to leave a comment.

3 comments

0
Avatar

How about for like Install Share? How do I convert this to Javascript: 

PodioAppMarketShare.phpPodioAppMarketShare::install( $share_id, $attributes = array() );

I know I have to use this: /app_store/{share_id}/install

but not sure how or where to place the space_id so Podio will know in what workspace it will be installed.

 

Thanks in advanced!

Tikboy 0 votes