Post

1 follower Follow
0
Avatar

.NET - Item attachments

Hi -

Any ideas why attachments is turning up null.  I have only one item in my app and it definitely has an attachment.

                var attachments = item.Files;

                if (attachments != null)

                foreach (var attachment in attachments)

                {

                    Console.WriteLine(attachment.Link);

                }

Rich Stoldt Answered

Please sign in to leave a comment.

6 comments

0
Avatar

Are you getting out multiple items using Get items or just a single item using Get item? If you get multiple items, you will not get the attachments for each item for performance reasons. You will need to get just a single item to get attachments.

Casper Fabricius 0 votes
Comment actions Permalink
0
Avatar

item is derived from a getItems collection.  So, I should build an array of item id's from a getItems call - then loop through the array calling getItem for each?

Hmmm ....

Rich Stoldt 0 votes
Comment actions Permalink
0
Avatar

If you must access all attachments of all items in an app, then that is currently your best option, yes.

We are working on making the API more flexible in terms of how much data it returns and how deeply nested it should return data.

Casper Fabricius 0 votes
Comment actions Permalink
0
Avatar

OK - so I try this but the getItem method explodes - I did this in Java with no problem but ....

            var items = client.ItemService.GetItems(appId, limit, offset);

            ArrayList list = new ArrayList();

            foreach (var item in items.Items)

            {

                var itemId = item.ItemId;

                list.Add(itemId);

                Console.WriteLine("id: " + item.ItemId.ToString());

                //                Console.WriteLine("title: " + item.Title);

            }

            foreach (object id in list)

            {

                int iid = Convert.ToInt32(id);

                Console.WriteLine("iid: " + iid);

                //Console.WriteLine("id: " + id);

                //return;

                var item = client.ItemService.GetItem(iid, true);  //KABOOM

                var fields = item.Fields;

                string value = null;

                foreach (var field in fields)

                {

                    Console.WriteLine("field type: " + field.Type);

                    Console.WriteLine("field title: " + field.Label);

.......

C:\Users\rich\Documents\Visual Studio 2012\Projects\CapiTest\CapiTest\bin\Debug>

capitest

id: 23673529

iid: 23673529

Unhandled Exception: Newtonsoft.Json.JsonSerializationException: Cannot deserial

ize the current JSON object (e.g. {"name":"value"}) into type 'System.Collection

s.Generic.Dictionary2[System.String,System.Object][]' because the type requires
 a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or chang
e the deserialized type so that it is a normal .NET type (e.g. not a primitive t
ype like integer, not a collection type like an array or List<T>) that can be de
serialized from a JSON object. JsonObjectAttribute can also be added to the type
 to force it to deserialize from a JSON object.
Path 'participants', line 1, position 1976.
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(Js
onReader reader, Type objectType, JsonContract contract, JsonProperty member, Js
onContainerContract containerContract, JsonProperty containerMember, Object exis
tingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInte
rnal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty mem
ber, JsonContainerContract containerContract, JsonProperty containerMember, Obje
ct existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValu
e(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract
containerContract, JsonProperty containerProperty, JsonReader reader, Object tar
get)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(
Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty m
ember, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(Js
onReader reader, Type objectType, JsonContract contract, JsonProperty member, Js
onContainerContract containerContract, JsonProperty containerMember, Object exis
tingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInte
rnal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty mem
ber, JsonContainerContract containerContract, JsonProperty containerMember, Obje
ct existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(Jso
nReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type
 objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonConvert
er[] converters)
   at Podio.API.Utils.PodioRestHelper.Deserialize[T](String json) in c:\Users\ri
ch\Documents\Visual Studio 2012\Projects\Podio.API-for-.NET\Podio.API\Utils\Rest
Helper.cs:line 272
   at Podio.API.Utils.PodioRestHelper.PodioResponse
1.get_Data() in c:\Users\ric

h\Documents\Visual Studio 2012\Projects\Podio.API-for-.NET\Podio.API\Utils\RestH

elper.cs:line 91

   at Podio.API.Services.ItemService.GetItem(Int32 itemId, Boolean markAsViewed)

 in c:\Users\rich\Documents\Visual Studio 2012\Projects\Podio.API-for-.NET\Podio

.API\Services\ItemService.cs:line 29

   at CapiTest.Program.Main(String[] args) in c:\Users\rich\Documents\Visual Stu

dio 2012\Projects\CapiTest\CapiTest\Program.cs:line 49

Rich Stoldt 0 votes
Comment actions Permalink
0
Avatar

Thanks Rick. The .NET client is not exactly bug free yet, and unfortunately we don't have many resources to throw at it at the moment.

I can see from the stack trace that it's trying to deserialize the participants on a meeting (an item in app where type is set to "event"). I don't think that has been tested yet in the .NET client, so I'll add it to my list of bugs and get it tested and fixed when there's time.

Casper Fabricius 0 votes
Comment actions Permalink
0
Avatar

I am unable to reproduce this error in the .NET client. I've tried various scenarios that I thought might trigger the bug, but they all work for me.

Are you still seeing this problem, and can you either:

  1. Tell me in details what the structure of the app is (field types, app type, etc.) and what the data is for the item that results in the error?
  2. Invite me to the space (as a space admin), if you have only test data in it anyway, so I can reproduce the error using your data?

Also would be good to know if you get that for all items in that particular app, and what behaviour you are seeing with other apps when running the same code.

Casper Fabricius 0 votes
Comment actions Permalink