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

Getting zip while trying to pull study results via API as JSON #294

Open
fuimsr opened this issue Oct 18, 2023 · 6 comments
Open

Getting zip while trying to pull study results via API as JSON #294

fuimsr opened this issue Oct 18, 2023 · 6 comments

Comments

@fuimsr
Copy link

fuimsr commented Oct 18, 2023

Hey,

I'm trying to automate data collection via the API, which has been a really useful tool so far.
Unfortunately I can not move the API to return a JSON, only ZIPs in all forms.

What I've tried with the documentation (https://petstore.swagger.io/?url=https://raw.githubusercontent.com/JATOS/JATOS/main/jatos-api.yaml#/results/post_jatos_api_v1_results_data):

curl -X 'POST' 'https://example.com/jatos/api/v1/results/data?studyUuid=XXXXXXX-XXXXXXX-XXXXXXXX-XXXXXXX&componentUuid=YYYYYYYYY-YYYYYYYYY-YYYYYYYY-YYYYYYY' -H "Authorization: Bearer ZZZZZ_ZZZZZZZZ_ZZZZZZZ" -H 'accept: application/octet-stream' -H 'Content-Type: application/json' --output test.txt

The file can be opened as an archive, but is definitely no .txt:
grafik

Did I do something wrong or is there a bug in the API?

@kristian-lange
Copy link
Member

From the API docs: "The results will be packed in an ZIP archive with an .jrzip suffix."

Packing the result data in a zip is actually intended. JATOS doesn't know (maybe in the future we will add some content detection) the format of your data apart from it being text. So for JATOS it can be JSON, CSV, base64 encoded binaries etc.

I assume what you want is that JATOS combines the JSON, that your components produce, into one big JSON file. And this not-zipped file would have a format like { cr1: jsonof1, cr2: jsonof2, ...}. Another option would be the the JSON line format: each line a different component's JSON. Is this what you intend to do?

@fuimsr
Copy link
Author

fuimsr commented Oct 19, 2023

Thanks for the prompt answer and for letting me know that I'm at fault here.

I've misinterpreted the documentation as I was trying to get all results in one big JSON identical to the download option in the v3.7.6 web interface. This just gave me one file with all the results and nothing else. I know that this is also not ideal, but the scripts are already written ¯\_(ツ)_/¯
Can I somehow get to this via the API?

@kristian-lange
Copy link
Member

Hm, we could add the all-in-one-big-text-file result data option in the API too. It's afaik already implemented and, as you mentioned, used in the GUI. With the new API we wanted to enforce a cleaner format: one file per component result. The one line per component result tend to be untidy since each component result itself can already have arbitrary line breaks. Hm, but I guess I could add it for backwards compatibility in the API too. But this would come only in the next release.

@fuimsr
Copy link
Author

fuimsr commented Oct 25, 2023

Thanks for the offer. I've talked to the people and it would be great if there would be the option to implement the all-in-one-big-text-file to keep things backwards compatible.

The API seems to be able to do this already, you're right:

public Result exportResultData(Http.Request request, boolean asPlainText, boolean isApiCall)

And the route can use the "asPlainText", but defaults to false? (

GET /jatos/api/v1/results/data @controllers.gui.Api.exportResultData(request: Request, asPlainText: Boolean ?= false, isApiCall: Boolean ?= true)
)

Would there be an option to do a hot fix? Not sure how to horribly mangle the final thing to get this out, I'm not a java person at all..

@kristian-lange
Copy link
Member

It seems to work already :) (you pointed at the right route). It's just not documented. Just add the query parameter asPlainText=true and you get the result in a text file. I just tried it on Mindprobe and it worked:

curl -X 'POST' 'https://jatos.mindprobe.eu/jatos/api/v1/results/data?studyResultId=303145&asPlainText=true'  -H 'accept: application/octet-stream'  -H 'Authorization: Bearer jap_xxxxxxxxxxxx' -H 'Content-Type: text/plain' -d '' --output jatosresult.txt

@fuimsr
Copy link
Author

fuimsr commented Oct 25, 2023

Awesome, that works. Thanks and kisses.

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