/// <summary> /// Update an already existing item. /// <para>Podio API Reference: https://developers.podio.com/doc/items/update-item-22363 </para> /// </summary> /// <param name="item"></param> /// <param name="spaceId"> For use in Podio platform</param> /// <param name="revision">The revision of the item that is being updated. This is optional</param> /// <param name="silent"> /// If set to true, the object will not be bumped up in the stream and notifications will not be /// generated /// </param> /// <param name="hook">If set to false, hooks will not be executed for the change</param> /// <returns>The id of the new revision / null if no change</returns> public async Task <int?> UpdateItem(Item item, int?spaceId = null, int?revision = null, bool silent = false, bool hook = true) { JArray fieldValues = JArray.FromObject( item.Fields.Select(f => new { external_id = f.ExternalId, field_id = f.FieldId, values = f.Values })); var requestData = new ItemCreateUpdateRequest() { ExternalId = item.ExternalId, Revision = revision, Fields = fieldValues, FileIds = item.FileIds, Tags = item.Tags, Recurrence = item.Recurrence, LinkedAccountId = item.LinkedAccountId, Reminder = item.Reminder, Ref = item.Ref, SpaceId = spaceId }; string url = string.Format("/item/{0}", item.ItemId); url = Utility.PrepareUrlWithOptions(url, new CreateUpdateOptions(silent, hook)); dynamic response = await _podio.Put <dynamic>(url, requestData); if (response != null) { return((int)response["revision"]); } else { return(null); } }
/// <summary> /// Adds a new item to the given app. /// <para>Podio API Reference: https://developers.podio.com/doc/items/add-new-item-22362 </para> /// </summary> /// <param name="appId">The application identifier.</param> /// <param name="item">The item.</param> /// <param name="silent">If set to true, the object will not be bumped up in the stream and notifications will not be generated</param> /// <param name="hook">If set to false, hooks will not be executed for the change</param> /// <returns>Id of the created item</returns> public async Task <int> AddNewItem(int appId, Item item, bool silent = false, bool hook = true) { JArray fieldValues = JArray.FromObject(item.Fields.Select(f => new { external_id = f.ExternalId, field_id = f.FieldId, values = f.Values })); var requestData = new ItemCreateUpdateRequest() { ExternalId = item.ExternalId, Fields = fieldValues, FileIds = item.FileIds, Tags = item.Tags, Recurrence = item.Recurrence, LinkedAccountId = item.LinkedAccountId, Reminder = item.Reminder, Ref = item.Ref }; string url = string.Format("/item/app/{0}/", appId); url = _podio.PrepareUrlWithOptions(url, new CreateUpdateOptions(silent, hook)); dynamic response = await _podio.PostAsync <Item>(url, requestData); return(response.ItemId); }