Hi All, I'm trying to create an experiment via the...
# ask-questions
r
Hi All, I'm trying to create an experiment via the API POST request and have been running into some issues. Does anyone have a list of the minimum viable request body I can send to create an experiment? (I want to create a shell of an experiment just to try it out). Based on the docs I have an Experiment request containing the following fields with everything else being the default values shown in the example payload:
Copy code
assignmentQueryId="user_id",
        trackingKey="example_experiment_trackingKey",
        name="example-experiment",
        project="my-project-id",
        variations=[variation1, variation2],
        owner="test-user@test.com"
However, I am now getting a message when I submit the request of the following:
{"message":"Unknown metric: string"}
since my default metric value is just "string". Based on the API Docs it doesn't looks like metrics is a required value. However, when I set
metrics = None
and pass that in the request body I get
{"message":"Request body: [metrics] Expected array, received null"}
Is there a default value I can pass for metrics, (and other), fields that will let me create a minimum experiment and is there a list of all fields that need to have valid data passed in as it seems that some fields which are not marked as required in the docs do require valid input. Thank you! If there is a better question for a different channel I am happy to post there, just let me know.
s
https://docs.growthbook.io/api#tag/experiments/operation/postExperiment The API docs will list the required fields for experiment creation. I think you need to include the data source id.
r
Thanks @strong-mouse-55694 - I'll try that. It doesn't look like
datasourceId
is listed as required in the docs. Do you know if there are other fields that might not have the "required" label that are needed?
s
Actually, just tested and data source isn't required. I was able to create an experiment successfully with just the required fields as stated in the docs:
Copy code
const response = await fetch("<https://api.growthbook.io/api/v1/experiments>", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer secret_admin_123`,
    },
    body: JSON.stringify({
      name: "Test exp",
      assignmentQueryId: "user_id",
      trackingKey: "text-exp",
      variations: [
        { key: "0", name: "control" },
        { key: "1", name: "treatment" },
      ],
    }),
  });
r
Interesting - and did you have to setup the assignment query separately or is that a dummy value? I'll try this out and see if I can get it working!
s
It'll be on your data source, but
user_id
is the default one used.
r
Thanks, I was able to get this to work, it turns out that I needed to exclude all the "none" values before passing the payload to the API
🙌 1