-1

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?

derpirscher
  • 14,418
  • 3
  • 18
  • 35
  • I know the person has found the solution. But just in case if anyone gets Exception "Authentication as app is not allowed for this method" while accessing `podio.ContactService.GetUserContactField(creator.Value, "profile_id");` will be because we cannot use app authenticated client for getting contact information as it is not App Specific, instead we will have to use User authenticated client for the above code to work. – Cijo Jose V Jan 06 '17 at 06:20
  • Well, that's exactly what the exception says. So what is the point of your comment? Using userauthentication was not possible in my case because the call was Part of an automated workflow. – derpirscher Jan 07 '17 at 07:45

1 Answers1

1

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.

derpirscher
  • 14,418
  • 3
  • 18
  • 35