Submit your innovative use case or inspiring success story to the 2023 Dataiku Frontrunner Awards! LET'S GO

How to pass a JSON body from an API call to scenario

Solved!
Srini_E
Level 3
How to pass a JSON body from an API call to scenario

Hi,

 

I'm trying to pass a JSON body from an API call to trigger a scenario. The scenario has a step (set global variables) to update global variables, I want to pass the JSON body to the variables field as shown in the screenshot.

Could anyone please help me on this?

 

dataiku_setVariables_scenario.PNG

0 Kudos
1 Solution
AlexT
Dataiker

Hi @Srini_E ,


Variable expansion is not supported within the "variables" when setting a variable this must be json. 

What you can do is use evaluated variables instead by toggling it "on". 


1. Using Evaluated variables :  Screenshot 2022-10-26 at 15.00.02.png


2. Using Python step ( example below will read project variable and want to set a global variable)

import dataiku

client = dataiku.api_client()

project = dataiku.api_client().get_project(dataiku.default_project_key())
vars = project.get_variables()
#retrieve the variable
var_to_set = vars['standard']['varname']

global_variables = client.get_variables()
global_variables["varname"] = var_to_set
client.set_variables(global_variables)


Thanks

View solution in original post

0 Kudos
1 Reply
AlexT
Dataiker

Hi @Srini_E ,


Variable expansion is not supported within the "variables" when setting a variable this must be json. 

What you can do is use evaluated variables instead by toggling it "on". 


1. Using Evaluated variables :  Screenshot 2022-10-26 at 15.00.02.png


2. Using Python step ( example below will read project variable and want to set a global variable)

import dataiku

client = dataiku.api_client()

project = dataiku.api_client().get_project(dataiku.default_project_key())
vars = project.get_variables()
#retrieve the variable
var_to_set = vars['standard']['varname']

global_variables = client.get_variables()
global_variables["varname"] = var_to_set
client.set_variables(global_variables)


Thanks

0 Kudos