wallabag / wallabag

wallabag is a self hostable application for saving web pages: Save and classify articles. Read them later. Freely.
https://wallabag.org
MIT License
10.63k stars 778 forks source link

api/entries exports in json only. #3435

Open chabotsi opened 7 years ago

chabotsi commented 7 years ago

Issue details

I wanted to use /api/entries.epub to export all my articles into a single epub file, but I obtained a json file whatever the format I asked.

According to the api documentation, /api/entries.{_format} should export in the given {_format} ( xm|json|txt|csv|pdf|epub|mobi) and not only json.

Steps to reproduce/test case

Here is the python script I used : https://chabotsi.fr/paste/?52cb8ab63a07dbbd#E+YMTgL5VTWTcez23Cmk0xVZvDBH/vzAa0LN5O/mDaY=

cvergne commented 6 years ago

Hi,

I took a look and in fact, there is confusion in controllers between "export" feature and "api" feature. As they use the same bundle, the allowed formats for export are also allowed for api methods, but other methods than export force JSON Response. But just replace the "response" method is not enough because there is no built-in serializer for txt, pdf, epub and mobi. There is two solutions :

  1. Fix response method to return XML in addition to JSON (as it is configured in config.yml) then update the documentation to reflect the configuration.
  2. Update the configuration and methods to also handle those formats, but those are not really common API formats :)

In my opinion, it would be better to do the first solution, as there is already an "export all entries" feature in app.

What do you think guys ? :)

j0k3r commented 6 years ago

Fix response method to return XML in addition to JSON (as it is configured in config.yml) then update the documentation to reflect the configuration.

Could you elaborate?

cvergne commented 6 years ago

yep, so the idea would be to change the sendResponse method in src/Wallabag/ApiBundle/Controller/EntryRestController.php to use the view layer of FOSRestBundle. About the documentation part, after quick check, available formats are not in methods documentation, but in the self-generated documentation (I think it's the tricky part to fix).

Is it clearer ? :) (or directly a PR would it be ?)

Note: current config for /api/ methods :

- { path: "^/api", priorities: ['json', 'xml'], fallback_format: json, prefer_extension: false }
j0k3r commented 6 years ago

Give it a try. I fixed api export here https://github.com/wallabag/wallabag/pull/2453 if this could help

m4lvin commented 3 years ago

I ran into this problem now. I want to automate downloading the epub or mobi. Is there a way to use /export/ with a token?

linnabraham commented 2 years ago

Is this the same case with /api/annotations? I am not able to produce a txt or csv output with something like this. I am getting back a json response.

http GET https://app.wallabag.it/api/annotations/{entry}.txt