hi team, I need assistance with integrating Growth...
# ask-questions
hi team, I need assistance with integrating Growthbook into a Java backend application. Specifically, I would like to know how to create an Experiment object dynamically by passing attributes at runtime using the GrowthBook client to obtain the experiment variant. Tried below snippet but looks like code is not correct
Copy code
GrowthBook client = new GrowthBook(GBContext.builder().url("<http://localhost:3000>").build());
        Experiment<Float>donutPriceExperiment = Experiment
                .conditionJson("{\"id\": 1}")

        ExperimentResult<Float> donutPriceExperimentResult = client.run(donutPriceExperiment);
I'm not an expert in Java - are you setting any attributes?
yes , i want to pass attribute like user_id, mobile etc
attributesJson() - that's probably it. You're doing inline experiments with the conditionJson, not sure if you mean to do that
are you reading the docs here? https://docs.growthbook.io/lib/java
yes , referring same doc and looking for Inline Experiments
Just help me with the code snippet in Java, how to get experiment variant
The way GrowthBook works is with deterministic hashing - so you have to give it some kind of attribute to bucket on, or to target to
for instance, in your inline experiment there, you're targeting on id - but you are not defining what id are the users are
If we have attributes like "id, mobile, and city" and an experiment named "click_test" with the Assignment Attribute set as "id" and variants configured as "control, two_click, three_click" --- Now i have two input attribute 1. id = 123, mobile= 99999999 and city = New York 2. id = 456, mobile= 88888888 and city = Washington ----- Based on GrowthBook hashing on Id , suppose 1st data (id= 123) is returning "control" variant of experiment and 2nd data (id= 456) is returning "two_click" variant of experiment ---- Basically how to get experiment variants (control, two_click, three_click ) by passing input attribute wrt Java
ya, you can do that
can you share Java code snippet to achieve the requirement ^^