# Using variables inside of API

**URL:** <https://discuss.elastic.co/t/using-variables-inside-of-api/283219>\
**Category:** Elasticsearch\
**Created:** [September 2, 2021, 9:48pm UTC](https://discuss.elastic.co/t/using-variables-inside-of-api/283219 "2021-09-02T21:48:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lcarr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lcarr/32/104631_2.png) [@lcarr](https://discuss.elastic.co/u/lcarr)\
**Post date:** [September 2, 2021, 9:48pm UTC](https://discuss.elastic.co/t/using-variables-inside-of-api/283219/1 "2021-09-02T21:48:27Z")

</div>

OK - am losing my hair over this -

I have a query that I am pulling data from the sample data index - I want to put the value of that query into the Put\_role api via python script - I am getting errors as I am sure that I am doing something wrong - Can someone please look at the code below and give me some pointers -

Thanks -  
Code:

q = Q('term', Carrier='\*')

s = Search(index='kibana\_sample\_data\_flights').using(es).query(q)  
s = s.source(includes = ['Carrier']) ##(variable field)

for hit in s.scan():  
put\_role(Sample\_"{{hit.Carrier}}"\_Analysts, body={"cluster":["all"],"indices":[{"names":["kibana\_sample\_data\_flight"], "privileges" : ["all"], "query" : "{"match":{"Carrier":"{{hit.Carrier}}"" }}],}}

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 30, 2021, 9:49pm UTC](https://discuss.elastic.co/t/using-variables-inside-of-api/283219/2 "2021-09-30T21:49:29Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
