Updating Podio Item using Podio API in C# .Net

565 Views Asked by At

I am new to Podio and consuming Podio API in c# .net. I am able to fetch item collections, create item using API and webhooks in .Net. But I am stuck up on updating item. I am using webhook on item update of ITEMX.Update. But I am getting error while updating the item.

While testing I have tried,

  • To assign new values to fields.
  • Just fetched item using ItemId and immediately called ItemUpdate() method without any change to fetched item

But still getting error. Last sentence of error message says:

"\\"item_id\\": 99999999, \\"revision\\": 0} (object): must be integer\",\"request\":{\"url\":\"http://api.podio.com/item/9999999\",\"query_string\":\"\",\"method\":\"PUT\"}}"}

I tried many things and refereed lot of documentation but didn't found solution. Can someone please help to get this done?

'

  public static async Task<int> UpdateCalculationsInGMApp(int appItemId)
{
    //Get related GMApp

    try
    {
        var _Podio = new Podio(Helper.ApiClientId, Helper.ClientSecret);
        AppMaster Ratesapp = Helper.GetAppToken("Costing Rates", "VikramTestWS");
        await _Podio.AuthenticateWithApp(Ratesapp.AppId, Ratesapp.Token);

        Item ratesPodioItem = await _Podio.ItemService.GetItem(appItemId);
 //Item fetched successfully here
        //thentried to set one of the field with new value. Later on commented and tested but didn't worked
        //var pm_Rate = ratesPodioItem.Field<NumericItemField>("pm-rate");
        //pm_Rate.Value = 100;

        try
        {
            int x = (int)await _Podio.ItemService.UpdateItem(ratesPodioItem, null, null, true, true);
        }
        catch (Exception excp)
        {
            Logger.AddToLog(DateTime.Now, excp.Message, "Error: updating podio item" + ratesPodioItem.ItemId.ToString());
        }
    }
}'
2

There are 2 best solutions below

1
On BEST ANSWER

You might be using the fetched item object itself to to update back to Podio. That will not work. You need to create a brand new Item object and do the update job. See the documentation here: http://podio.github.io/podio-dotnet/items/

0
On
  1. Instead of retrieving and updating an existing item, create a NEW item!

  2. Set the ItemId to the id of the Item you want to update.

  3. Set whatever fields you want to update to the NEW item.

  4. update that new item.

    Item itemToUpdate = new Item(); itemToUpdate.ItemId = appItemId; // The item_id of the item you need to update. var textfield = itemToUpdate.Field("notes-text"); textfield.Value = "update test " + DateTime.Now.ToShortDateString();

         try
         {
             int x = (int)await _Podio.ItemService.UpdateItem(itemToUpdate , null, null, true, true);
         }
         catch (Exception excp)
         {
             Logger.AddToLog(DateTime.Now, excp.Message, "Error: updating podio item" + ratesPodioItem.ItemId.ToString());
         }