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

Using validation with no required fields generates INVALID_DATA 400 error #88

Open
adityac95 opened this issue Oct 17, 2023 · 6 comments

Comments

@adityac95
Copy link

adityac95 commented Oct 17, 2023

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.

@adityac95
Copy link
Author

adityac95 commented Oct 20, 2023 via email

@jodeleeuw
Copy link
Member

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);

@adityac95
Copy link
Author

I tried both strategies and neither one worked.

@adityac95
Copy link
Author

Turns out I've fixed my problem now -- after specifying the fields from the original object, the file saved appropriately!

@jodeleeuw
Copy link
Member

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!

@adityac95
Copy link
Author

adityac95 commented Oct 20, 2023 via email

@jodeleeuw jodeleeuw changed the title Error 400 using DataPipe with Javascript Using validation with no required fields generates INVALID_DATA 400 error Oct 20, 2023
@jodeleeuw jodeleeuw reopened this Oct 20, 2023
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