erikbrinkman / rmapi-js

JavaScript implementation of the reMarkable api
https://erikbrinkman.github.io/rmapi-js/modules.html
MIT License
9 stars 1 forks source link

SyntaxError: Unexpected non-whitespace character after JSON at position 2 #6

Closed Bartek532 closed 9 months ago

Bartek532 commented 11 months ago

When I'm trying to fetch entry with the type of "DocumentType" using getMetadata I'm receiving the following error:

SyntaxError: Unexpected non-whitespace character after JSON at position 2

Version: 3.1.0

erikbrinkman commented 11 months ago

can you print what it looks like if you fetch the same hash with getText? It sounds like invalid json, likely something like "[],..." or "{},..." but I'm not really sure what. I don't think that should ever happen normally.

Bartek532 commented 11 months ago

I'm receiving something like this as an output:

3
67871f18728137a246b0740cf8ca7879c4a19d22ba2f41656a1d2e78b1d0aa66:0:353eb836-8e64-4d12-8fa9-9211dc9e1843.content:0:38654
084cfd85b23e92704246f4a7c891d4c504fa56c7836331348b4cd8ae46169a48:0:353eb836-8e64-4d12-8fa9-9211dc9e1843.epub:0:1634192
7156e983588f801573d11069078d7fd7d48e714dabef1d0aa368b6b170b6da32:0:353eb836-8e64-4d12-8fa9-9211dc9e1843.metadata:0:392
f4df6fc04bb0b8f6949216d54d3f9f7b6453d5989e73e5685adc7fd3ccf47f0a:0:353eb836-8e64-4d12-8fa9-9211dc9e1843.pagedata:0:3606
23a1aa0e324112b5118e26dbe3cf4dca8341a1af8a87279801d1c46e57e890a1:0:353eb836-8e64-4d12-8fa9-9211dc9e1843.pdf:0:6695458
erikbrinkman commented 11 months ago

Are you sure this is a DocumentType? This looks like entries metadata for a CollectionType (folder), and you should fetch it using getEntries(hash).

Bartek532 commented 11 months ago

Yes, it's DocumentType

erikbrinkman commented 10 months ago

Can you provide some example code about what your doing?

The text you've presented is an entries format file, and should be read with getEntries(). It's not a json metadata file. Trying to fetch it with getMetadata() won't work. Maybe it's a case I haven't seen personally and that's the problem, but in general the API is reverse engineered, so if there's a file that's marked as a DocumentType but is in fact a CollectionType by format, I'm not sure what to do.

erikbrinkman commented 10 months ago

On reflecting more, I think you may be using the API wrong. Even DocumentType elements are initially Entry's. If you look at the files returned by entries for the example you listed, you'll see there are five extensions: content, epub, metadata, pagedata, and pdf. If you want to read metdata, you have to call getMetadata on the hash of the metadata entry. Does that make sense?