kRyszard 0 Posted July 19, 2018 Share Posted July 19, 2018 Two problems: 1. problems with updating an item 2. hard to debug the above i.e. hard to read log file. I wanted to update an item but I didn't know which fields to include so started with only the field I wanted to change i.e. sortTitle. I was receiving http 400 and there were nullpointers in the log file but the stacktrace does not contain line numbers!!! I carefully analysed source file and found that I have no ProviderIds nor Tags. After filling these now the server response is 500 and the log file says: System.NullReferenceException: Object reference not set to an instance of an object. at Emby.Server.Implementations.Data.SqliteItemRepository.SaveItem(BaseItem item, BaseItem topParent, String userDataKey, IStatement saveItemStatement) the item I want to update: {"SortName":"abcd","ProviderIds":[],"Tags":[]} emby version: 3.4.1.35 2. please add line numbers to stacktrace 1. are there any code snippets or json examples of using emby api? Link to comment Share on other sites More sharing options...
ebr 15282 Posted July 19, 2018 Share Posted July 19, 2018 Hi. Those are standard .NET stack traces. Perhaps our swagger implementation would help you figure out the API. Also, if you fill us in on what you are trying to build we may be able to help. Thanks! Link to comment Share on other sites More sharing options...
kRyszard 0 Posted July 20, 2018 Author Share Posted July 20, 2018 Hi. Those are standard .NET stack traces. Ok, but is it possible to configure the server to print the line numbers? If it was I could debug exceptions myself and I would probably post less posts here. Perhaps our swagger implementation would help you figure out the API. Of course, I'm using it. But the documentation of ItemUpdateService's POST /Items/{ItemId} is rather poor: just a description of object with over 100 properties, no information if lack of property deletes the property or keeps untouched. Besides, regarding the information from the exception from the top of this topic: in the log file there is no information which reference is not set. I'll try by trial and error e.g. maybe it needs the parent reference. Also, if you fill us in on what you are trying to build we may be able to help. I'm building a program that updates tags recursively, I mentioned it here : Decided to write a script that crawls inside my filesystem, reads files with tags and uses emby rest interface to set/unset tags. Link to comment Share on other sites More sharing options...
Luke 38342 Posted July 20, 2018 Share Posted July 20, 2018 Of course, I'm using it. But the documentation of ItemUpdateService's POST /Items/{ItemId} is rather poor: just a description of object with over 100 properties, no information if lack of property deletes the property or keeps untouched. I understand, and this is simply a reflection of the fact that we have to prioritize our developer time towards user requirements. For this particular endpoint the documentation needs to be improved, however i think i can answer your question right here just to get you going. That endpoint is expecting to receive a complete representation of the object. So in other words, you pull the item down, change a few values, and then send back the whole thing. At this point it does not support just sending back a partial object graph with only the changes. Link to comment Share on other sites More sharing options...
kRyszard 0 Posted July 20, 2018 Author Share Posted July 20, 2018 (edited) you pull the item down, change a few values, and then send back the whole thing. That also ends with http 400. 1. I get the items with: http://xxxx:8096/emby//Users/.../Items?parentId=...&Fields=Tags,Path 2. From response's "Items" list I take the child I want. It looks like this: BackdropImageTags -> [] Id -> 3414b9d6be96bdb44a155eb6310b9158 ImageTags -> {Primary=55621897b7ddcaa516a07626234a5b66} IsFolder -> true LocationType -> FileSystem Name -> plener Path -> F:\disk\FOTY\2013\2013-10-12.....\plener ServerId -> ... Tags -> [] Type -> PhotoAlbum UserData -> {PlaybackPositionTicks=0.0, PlayCount=0.0, IsFavorite=false, Played=false, Key=3414b9d6-be96-bdb4-4a15-5eb6310b9158} 3. I add the "SortName" field 4. I post 5. Response is 400 and logs on server: System.ArgumentNullException: Value cannot be null. Parameter name: source at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at MediaBrowser.Api.ItemUpdateService.UpdateItem(BaseItemDto request, BaseItem item) at MediaBrowser.Api.ItemUpdateService.Post(UpdateItem request) EDIT: 6. This exception is about missing "ProviderIds" (I mention in the first post in this topic that I've checked in the source code). After adding the ProviderIds I still end up with "Object reference not set to an instance of an object." Edited July 20, 2018 by kRyszard Link to comment Share on other sites More sharing options...
ebr 15282 Posted July 20, 2018 Share Posted July 20, 2018 Make sure you are setting a proper UserID on your post. Link to comment Share on other sites More sharing options...
Luke 38342 Posted July 20, 2018 Share Posted July 20, 2018 I would suggest using the editing function in Chrome and monitoring the http request using the Chrome debugger. Rather than having me go through your requests to find out what's missing, I think that is going to be the fastest solution because you can easily compare the differences between yours and ours. Link to comment Share on other sites More sharing options...
kRyszard 0 Posted July 20, 2018 Author Share Posted July 20, 2018 1. I decided that I will just run the emby web app and update the metadata there and just take a look at Firefox'es "net" tab and grab the updated item, but: 2. the item I wanted to update is now broken. I cannot open the metadata screen and the error on the server is : System.ArgumentNullException: Value cannot be null. Parameter name: source at System.Linq.Enumerable.Where[TSource](IEnumerable`1 source, Func`2 predicate) at Emby.Server.Implementations.Dto.DtoService.AttachGenreItems(BaseItemDto dto, BaseItem item) at Emby.Server.Implementations.Dto.DtoService.AttachBasicFields(BaseItemDto dto, BaseItem item, BaseItem owner, DtoOptions options) Looks like despite all those error messages something actually happened on the server or the transaction was not properly rolled back Link to comment Share on other sites More sharing options...
kRyszard 0 Posted July 20, 2018 Author Share Posted July 20, 2018 1. I used "refresh metadata" on parent folder to fix the item I want to update. 2. I took a look at the item the web app is posting during updating metadata and used the same set of properties and that worked 3. Thanks for flash fast answers. That's awesome!!! Link to comment Share on other sites More sharing options...
Luke 38342 Posted July 20, 2018 Share Posted July 20, 2018 It may have saved some null data and then other parts of the server weren't able to handle that. This is just a function of the fact that nobody has needed that API for us, therefore we've always been able to count on it being used in a certain way. So yes there's room for improvement there, thanks. Link to comment Share on other sites More sharing options...
kRyszard 0 Posted July 21, 2018 Author Share Posted July 21, 2018 In updating the item there is also another glitch/bug and it is related to the "sort name" property. Steps to reproduce:1. Read items by parent. Make sure the "ForcedSortName" and "SortName" are among the fields.2. In the response only the "SortName" is set, "ForcedSortName" is not there3. Post the received item in unchanged form to ItemUpdateService4. Re-read the item. The "SortName" field is recomputed.As a result the API user has to remember to copy "SortName" to "ForcedSortName", every time whatever other change he does to the item. Link to comment Share on other sites More sharing options...
Luke 38342 Posted July 21, 2018 Share Posted July 21, 2018 Thanks for the info. We'll take a look. Link to comment Share on other sites More sharing options...
kRyszard 0 Posted July 23, 2018 Author Share Posted July 23, 2018 I think there is another "bug" or "unexpected feature" regarding the "SortName" property: when I want to sort folders in some specific order I assign some carefully selected "ForcedSortName" properties to these folders but these properties are further modified by emby i.e. the numbers are expanded to a 10 digit form which breaks the order I wanted i.e. "13" comes after "2" while in alphabetical order it's the opposite. I agree that when emby first scans the folders it may assign any "SortName" as it likes but manually assigned sortnames should be kept intact. Link to comment Share on other sites More sharing options...
Luke 38342 Posted July 23, 2018 Share Posted July 23, 2018 It's not a bug we've been doing that for years. the "bug" is probably just in explaining the api. The only thing that does is pad the numbers with zeroes to ensure numeric comparisons will work correctly. So if we make sure that both the 13 and 2 are prefixed with a certain number of zeros, then the comparison becomes 00000013 vs 00000002 Link to comment Share on other sites More sharing options...
kRyszard 0 Posted July 27, 2018 Author Share Posted July 27, 2018 Ok I see your point but can you please make the expanding consistent? Now I get different results for automatic and manual assigning i.e. after emby scans the directories, for folder named "2017-07-12 trip" the sort name is "0020170712 trip" but when I manually assign the exact same string it becomes "0000002017-0000000007-0000000012 trip". Link to comment Share on other sites More sharing options...
Luke 38342 Posted July 27, 2018 Share Posted July 27, 2018 You should never manually assign like that. That is private implementation detail within the server that you don't need to know about. All you need to do is set the actual sort order that you want, for example 2017-07-12. Link to comment Share on other sites More sharing options...
kRyszard 0 Posted July 27, 2018 Author Share Posted July 27, 2018 I guess I might have been unclear: for folder named "2017-07-12 trip" the sort name is "0020170712 trip" but when I manually assign a string "2017-07-12 trip" it becomes "0000002017-0000000007-0000000012 trip". Link to comment Share on other sites More sharing options...
Luke 38342 Posted July 27, 2018 Share Posted July 27, 2018 It really should be the same either way. I'll test it out. Thanks. Link to comment Share on other sites More sharing options...
kRyszard 0 Posted August 1, 2018 Author Share Posted August 1, 2018 If I may: I prefer the "longer" version of expanding numbers because sort method using it will put "2013-11 event" between "2013-10-07 other event" and "2013-11-04 whatever" (because "0000002013-0000000011" is between "0000002013-0000000010-0000000007" and "0000002013-0000000011-0000000004"). Link to comment Share on other sites More sharing options...
Luke 38342 Posted August 1, 2018 Share Posted August 1, 2018 Thanks for the info. Link to comment Share on other sites More sharing options...
kRyszard 0 Posted August 3, 2018 Author Share Posted August 3, 2018 The last post just to solve the original problem of this topic i.e. updating an item: the final solution is to re-read the item I want to update with /Users/{UserId}/Items/{Id} and not use the "partial" item received in a list of child items of a parent. This also solves the problem of the "ForcedSortName" property: when I re-read the item this property is there in the item so I don't have to copy it from the "SortName" property before updating (as I mentioned in #11). Link to comment Share on other sites More sharing options...
Luke 38342 Posted August 3, 2018 Share Posted August 3, 2018 That's correct, yes. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now