Post

2 followers Follow
0
Avatar

Add tags to an item

I am trying to add tags to an item. But when i use the PUT command into /item/{item_id/

with this payload:

 

{

"tags": ["mytag"]

}

It removes the existing tags. I can get the current tags, and put a new one in it, but that would need 2 calls. Since we are getting a list of users and doing a mail-action to them, I want to tag everyone who got the mail. Since the tag can be anything for new kinds of mail in future, a category with set fields is not an option (lots of different tags).

Is there a way to ADD a tag without having to GET the item first?

PS using Google Apps Script, so the communication is in 'bare POST commands' :) 

Callserver Answered

Please sign in to leave a comment.

9 comments

0
Avatar

I lost it at {ref_type} and {ref_id}, what are those/where to find them?

Then for tags it is fine, but this behaviour was with updating every item. I do use Andreas advice by getting all data I need in one call, then making my sets of arrays and appending new stuff where needed.

That makes sense too. 

Brings me to a question: is it possible to update several items in one call? Like I probably want to do something with the filtered items and basically I want to have a tag/category/item to set in Podio when something was done succesfully (i.e. sending an invoice to new people, and if invoice is sent, update status).

Callserver 0 votes
0
Avatar

ref_type and ref_id are our generic way or talking about references. For example when you create a comment you can create it on a status message or on a task and instead of creating multiple API operations we just have one where you specify the ref_type (task or status) and the ref_id (task_id or status_id) or the entity you want to create the comment on.

In this case you want a ref_type of "item" and use the item_id as the ref_id.

We currently don't have a way of updating multiple items in one API operation (other than the excel importer interface which is very cumbersome). We are working on it, but we don't have it nailed yet.

Andreas Haugstrup Pedersen 0 votes
0
Avatar

Thank you, makes sense again. 

Allright, well I am not hitting the 250 calls anyway, but it would be cleaner. Looping trough 10-15 items and doing  a seperate POST each time just feels awkward, but it is doable. 

 

Callserver 0 votes
0
Avatar

I am trying to add a TAG to an EXISTING podio item using the podio-php API. I used $ref_type='item' and $ ref_id= the ID of the item. But I do not know how to set the $atttibutes array() correctly. Do you have any sample PHP code, for adding a TAG to an EXISTING podio item (using podio-php)?

My Code:

// after authentication

$ref_type='item';

$ref_id = 16650; //the ID of the item

$attributes = array('text' => 'mytag');

PodioTag::create( $ref_type, $ref_id, $attributes);

=======================================

THE RESULT:

Fatal error: Uncaught PodioBadRequestError: "Invalid value {"text": "mytag"} (object): must be array"

Request URL: http://api.podio.com/tag/item/16650/

Dan | CPA Gardens 0 votes
0
Avatar

Hi Dan,

You can see the format for the raw data expected on https://developers.podio.com/doc/tags/create-tags-22464

It's an array of tab objects. From the error message you got you can see that the value you're sending is just a single object. It's not wrapped in the required array.

So in PHP terms you need to wrap your associative array in a plain array like so:

$ref_type='item'; 

$ref_id = 16650; //the ID of the item 

$attributes = array(array('text' => 'mytag'));

PodioTag::create( $ref_type, $ref_id, $attributes);

/Andreas

Andreas Haugstrup Pedersen 0 votes
0
Avatar

Thank you for your fast answer! I already tried using $attributes = array(array('text' => 'mytag'));

And the response is still an error:

Fatal error: Uncaught PodioBadRequestError: "Invalid value {"text": "mytag"} (object): must be non empty string"

Request URL: http://api.podio.com/tag/item/16650/

Could you  please help me with any sample code to create a tag from podio-php API? Thanks again!

 

Dan | CPA Gardens 0 votes
0
Avatar

That's because I can't read my own documentation. Slightly embarrassing one could argue. Ahem, moving on. You just send an array of strings like so:

PodioTag::create('item', 16650, array('mytag', 'myothertag'));

Voila! :)

/Andreas

Andreas Haugstrup Pedersen 0 votes