jspsych / datapipe

Send data from your behavioral experiments to the OSF. Born-open data as a service.

Home Page:https://pipe.jspsych.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using validation with no required fields generates `INVALID_DATA` 400 error

adityac95 opened this issue · comments

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 @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!