Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

body is not stored in NoteData #22

Closed
alglez opened this issue Jul 8, 2023 · 2 comments
Closed

body is not stored in NoteData #22

alglez opened this issue Jul 8, 2023 · 2 comments

Comments

@alglez
Copy link

alglez commented Jul 8, 2023

When getting the body of a note with get_note. The body is none

note = joplinApi.get_note("123456")
print(note.body) # this is none 

But if you do:

note = joplinApi.get_note("123456", fields="body")
print(note.body) # this return the body string

The second note still is NoteData type, but with no id, no title, only body

The method to access the body of a note seems inconsistent, and I don't understand why those two NoteData are separated and if that behavior is expected or if it has something to do with the dataclasses merge (#17)

@marph91
Copy link
Owner

marph91 commented Jul 9, 2023

That's not a problem in Joppy, but rather expected behavior of Joplin's data API:

$ curl http://localhost:41184/notes/8e91940c76014e8480825a72d93755b4
{"id":"8e91940c76014e8480825a72d93755b4","parent_id":"e7ec4ca2780146c798031e09e79af8fc","title":"test note","type_":1}

$ curl http://localhost:41184/notes/8e91940c76014e8480825a72d93755b4?fields=body
{"body":"test body","type_":1}

$ curl http://localhost:41184/notes/8e91940c76014e8480825a72d93755b4?fields=id,title,body
{"id":"8e91940c76014e8480825a72d93755b4","title":"test note","body":"test body","type_":1}

So in your case, id, title and body can be passed as comma-separated values. This can be done in a single request:

note = joplinApi.get_note("123456", fields="id,title,body")

NB: Joppy is a thin API wrapper. Each request returns a separate object. There is no implicit merging of NoteData objects. That means if you want to do an action on the same note, you would have to pass the id. If you want to operate on the note objects directly, you might take a look at https://github.com/S73ph4n/python_joplin (not sure if there is any development activity, though).

@alglez
Copy link
Author

alglez commented Jul 9, 2023

Ok, perfect. Thanks for the explanation.

@alglez alglez closed this as completed Jul 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants