Using validation with no required fields generates `INVALID_DATA` 400 error
Thanks for all your work in building this tool, which I am trying to integrate with an experiment I've built using Javascript (not jsPsych). I copied and modified the sample code from the experiment page at the point in my script where I'd like to call the DataPipe API:
fetch("https://pipe.jspsych.org/api/data/", {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "*/*",
},
body: JSON.stringify({
experimentID: "MY_EXPERIMENT_ID", // I replaced this with my experiment ID
filename: "UNIQUE_FILENAME.json", // I replaced this with my filename
data: dataAsString, // this variable is already JSON-stringified from earlier in the code
}),
});
Data validation is enabled and I've allowed JSON. However, every time I get to the data submission stage, I get an error 400 without any additional explanation. When I disabled data validation, a file was piped through to my OSF repo, but it only contained the data [object Object]. When I navigated to https://pipe.jspsych.org/api/data/, it showed a MISSING_PARAMETER error, but I don't have a sense of whether that applies directly to the error on my end.
You should be able to reproduce the error if you try the task at this link -- I recommend just mashing the X, Y and Z keys with the audio off to get through the task quickly and without irritation.
For what it's worth, while I've been testing out the functionality of my experiment, I've also been sending the data to a personal Google Firestore database and it's been showing up just fine there. I'd really appreciate any assistance you have!
EDIT (2023-10-18): turns out that the error I'm getting is actually INVALID_DATA. This happens whether or not I use the dataAsString or the original dictionary variable that holds the data. I have no required fields.
Hi Josh,
Yes, this is what it looks like:

Perhaps I am misunderstanding the purpose of the “required fields” field? I assumed it was just checking for the presence of whatever field you specify in this box, while allowing others to exist too.
Best wishes Aditya ━━━━━━━━━━━━━━━━ Aditya Chander, he/him PhD Candidate, Music Theory Yale University tel: +1 (650) 283 8142, +44 (0) 7951 407283 alternative email: @.*** website: https://ccrma.stanford.edu/~aditya/adityachander/
On 20 Oct 2023, at 2:26 pm, Josh de Leeuw @.***> wrote:
Hi @adityac95 https://github.com/adityac95,
Do you have the "allow JSON" option checked? What does this section of your experiment configuration look like?
https://user-images.githubusercontent.com/595524/277022042-4c1cbf07-89dc-47e5-91e0-453bec2eb522.png — Reply to this email directly, view it on GitHub https://github.com/jspsych/datapipe/issues/88#issuecomment-1773202619, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOR2R2WKCBGCVQKPX3RCB4DYAK66BAVCNFSM6AAAAAA6EPU7GCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZTGIYDENRRHE. You are receiving this because you were mentioned.
Hi @adityac95,
(sorry, I replied earlier without fully understanding the post)
It looks like in the code that is live at the link you shared the data is not being converted to a string before being sent:
fetch("https://pipe.jspsych.org/api/data/", {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "*/*",
},
body: JSON.stringify({
experimentID: "0dioRZjGJz00",
filename: filename,
data: data, // valid JSON data
}),
});
data is an object here:
const data = {
initials: initials,
datetime: datetime,
questionnaireResponses: JSON.parse(questionnaireResponses),
trialOrder: trialOrder,
melodies: melodies
};
Did you try saving jsonData, which you've created above?
const jsonData = JSON.stringify(data);
I tried both strategies and neither one worked.
Turns out I've fixed my problem now -- after specifying the fields from the original object, the file saved appropriately!
Just to be clear: you had to add the fields to the required_fields list? That's not the intention for behavior, so that's a bug if that is what is happening!
Yes, that’s the only way I got it to work.
On Fri, 20 Oct 2023 at 2:58 pm, Josh de Leeuw @.***> wrote:
Just to be clear: you had to add the fields to the required_fields list? That's not the intention for behavior, so that's a bug if that is what is happening!
— Reply to this email directly, view it on GitHub https://github.com/jspsych/datapipe/issues/88#issuecomment-1773248053, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOR2R2V3TPFTWKJZDOYXQADYALCUHAVCNFSM6AAAAAA6EPU7GCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZTGI2DQMBVGM . You are receiving this because you modified the open/close state.Message ID: @.***>