Search code examples
c#podio

Getting the profileid for a userid


In our company we created a custom Issues app. Additionally to using this app in the web interface, we also want to be able to change the state of an issue (new, acknowledged, test, resolved, ...) automatically via git commit hooks. The basics are working fine (ie change state, add notes, ...), but we also want to change the responsibility for the current item to a specific user. In that special case, it's the creator if this item.

My first try was the following:

var appid = 1234; var itemid = 1;
var item = podio.ItemService.GetItemByAppItemId(appid, itemid);
var update = new Item {ItemId = item.ItemId};

var creator = item.CreatedBy.Id;
var resp = update.Field<ContactItemField>("responsibility");
resp.ContactIds = new List<int>{creator.Value};

//change some other fields as well

podio.ItemService.UpdateItem(update);

This throws an "Object not found" exception, because in the resp.ContactIds one must not set the UserId but the ProfileId.

I then tried to get the ProfileId of the item-creator via

podio.ContactService.GetUserContactField(creator.Value, "profile_id");

but this also throws an exception "(Authentication as app is not allowed for this method").

So how can I get an appropriate profile id for the user when I use authentication as app?


Solution

  • OK, I found a workaround for it, not sure, if this is possible for other scenarios, but it works for the current case.

    Instead of using the C# interface for setting the ContactIds for the ContactItemField, I set the json values directly.

    var appid = 1234; var itemid = 1;
    var item = podio.ItemService.GetItemByAppItemId(appid, itemid);
    var update = new Item {ItemId = item.ItemId};
    
    var creator = item.CreatedBy.Id;
    var resp = update.Field<ContactItemField>("responsibility");
    resp.ContactIds = new List<int>(); // set to an empty list, so that resp.Values is initialized to an empty JArray
    
    var u = new JObject { {"value", new JObject { {"type" , "user" }, {"id", creator } } } };
    responsibleField.Values.Add(u); //add the new user to the Values of the field
    
    //change some other fields as well
    podio.ItemService.UpdateItem(update);
    

    And if I set the value with type user I can use the known userid and the API on the server takes care of the lookup.