# Passing in data

**URL:** <https://community.gatling.io/t/passing-in-data/1087>\
**Category:** Gatling (Open-Source)\
**Created:** [June 10, 2014, 10:05pm UTC](https://community.gatling.io/t/passing-in-data/1087 "2014-06-10T22:05:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![William\_Chung](https://avatars.discourse-cdn.com/v4/letter/w/47e85d/32.png) [@William\_Chung](https://community.gatling.io/u/William_Chung)\
**Post date:** [June 10, 2014, 10:05pm UTC](https://community.gatling.io/t/passing-in-data/1087/1 "2014-06-10T22:05:04Z")

</div>

I just found Gatling yesterday after using a paid tool and or Soap/Load UI for awhile.

My development skills are kinda low but I can read and understand … enough.

Hoping you all can help me. To get the key I need for my calls I need to call a service and save it’s full response as a variable to use as part of the header for the other endpoints.  
What am I doing wrong here? The response for the key generator is only composed of the key.

val usersDataSource = csv(“domains.csv”)

val scn = scenario(“Testing”)  
.feed(usersDataSource)  
.exec(http(“Get API Key”)  
.post("/login")  
.body("""{“username”: “ausername”, “password”: “apassword”, “domain”: “${domain}”}""").asJSON  
.check(regex(.))  
.saveAs(“apiKey”)

.pause(222 milliseconds)  
.exec(http(“cEndpoint”)  
.get("/cendpoint")  
.header(“aKey”, “${apiKey}”)  
.queryParam("""\_""", “”“1402401310313"”")

Thanks!

---

<div class="post-metadata">

**Author:** ![Sajjad\_Lateef](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@Sajjad\_Lateef](https://community.gatling.io/u/Sajjad_Lateef)\
**Post date:** [June 10, 2014, 10:52pm UTC](https://community.gatling.io/t/passing-in-data/1087/2 "2014-06-10T22:52:53Z")

</div>

The problem may be with the “check(regex(.))” … that will probably match a single character.  
If your apiKey is more than 1 character long, well, that regex will not work.

Try regex(.\*) … presuming that is there is no other text other than apiKey in the response.

---

<div class="post-metadata">

**Author:** ![William\_Chung](https://avatars.discourse-cdn.com/v4/letter/w/47e85d/32.png) [@William\_Chung](https://community.gatling.io/u/William_Chung)\
**Post date:** [June 10, 2014, 11:17pm UTC](https://community.gatling.io/t/passing-in-data/1087/3 "2014-06-10T23:17:58Z")

</div>

Thanks… I’m getting this error. Am I calling it wrong?

19:14:41.678 [ERROR] c.e.e.g.a.ZincCompiler$ - D:\Users\w.chung\Desktop\Gatling\user-files\simulations\API\APICalls.scala:36: illegal start of simple expression  
19:14:41.685 [ERROR] c.e.e.g.a.ZincCompiler$ -.check(regex(.\*))  
19:14:41.687 [ERROR] c.e.e.g.a.ZincCompiler$ - ^  
19:14:41.688 [ERROR] c.e.e.g.a.ZincCompiler$ - D:\Users\w.chung\Desktop\Gatling\user-files\simulations\API\APICalls.scala:137: ‘)’ expected but ‘}’ found.  
19:14:41.689 [ERROR] c.e.e.g.a.ZincCompiler$ - }  
19:14:41.689 [ERROR] c.e.e.g.a.ZincCompiler$ - ^  
19:14:41.724 [ERROR] c.e.e.g.a.ZincCompiler$ - two errors found

---

<div class="post-metadata">

**Author:** ![Sajjad\_Lateef](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@Sajjad\_Lateef](https://community.gatling.io/u/Sajjad_Lateef)\
**Post date:** [June 10, 2014, 11:27pm UTC](https://community.gatling.io/t/passing-in-data/1087/4 "2014-06-10T23:27:18Z")

</div>

I only use jsonPath, not regex. I had to look it up - is the main [gatling.io](http://gatling.io) page link to documentation not live?

Anyway, you should first check the mailing list archives first … that’s how I learn.

The following post will show you how to use regex correctly.  
[https://groups.google.com/forum/#!searchin/gatling/check%28regex/gatling/GaCZDvbo-tE/wfk6KbWszO4J](https://groups.google.com/forum/#!searchin/gatling/check%28regex/gatling/GaCZDvbo-tE/wfk6KbWszO4J)

---

<div class="post-metadata">

**Author:** ![William\_Chung](https://avatars.discourse-cdn.com/v4/letter/w/47e85d/32.png) [@William\_Chung](https://community.gatling.io/u/William_Chung)\
**Post date:** [June 11, 2014, 1:53am UTC](https://community.gatling.io/t/passing-in-data/1087/5 "2014-06-11T01:53:31Z")

</div>

Is there any other way to just throw the whole return body into a variable? Everything between the { } in the return is what i’m trying to capture. Or am i doing this totally the wrong way?

When I take this out it compiles fine… putting it in gives me the errors

.exec(http(“Get API Key”)  
.post("/login")  
.body("""{“username”: “ausername”, “password”: “apassword”, “domain”: “${domain}”}""").asJSON  
.check(regex(.\*).saveAs(“apiKey”))

---

<div class="post-metadata">

**Author:** ![William\_Chung](https://avatars.discourse-cdn.com/v4/letter/w/47e85d/32.png) [@William\_Chung](https://community.gatling.io/u/William_Chung)\
**Post date:** [June 11, 2014, 2:06am UTC](https://community.gatling.io/t/passing-in-data/1087/6 "2014-06-11T02:06:58Z")

</div>

This is the error

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [June 11, 2014, 5:34am UTC](https://community.gatling.io/t/passing-in-data/1087/7 "2014-06-11T05:34:16Z")

</div>

What you pass to regex is not a valid String =\> double quotes!!!  
regex(".\*")

---

<div class="post-metadata">

**Author:** ![William\_Chung](https://avatars.discourse-cdn.com/v4/letter/w/47e85d/32.png) [@William\_Chung](https://community.gatling.io/u/William_Chung)\
**Post date:** [June 11, 2014, 11:32am UTC](https://community.gatling.io/t/passing-in-data/1087/8 "2014-06-11T11:32:02Z")

</div>

Thanks!!! I actually figured it out yesterday late nite and forgot to post 🙂 I was too concentrated on getting the regex right which i didn’t know much about 😑

Now i’m getting this \<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<  
00:20:20.530 [WARN] c.e.e.g.c.s.ELParser$ - Couldn’t resolve EL ${apiKey}

Am I saving it the wrong way?

**Access-Control-Allow-Credentials:** true

**Access-Control-Allow-Headers:** X-Requested-With,content-type, Key,accept

**Access-Control-Allow-Methods:** GET, POST, OPTIONS, PUT, PATCH, DELETE

**Content-Length:** 216

**Content-Type:** text/html; charset=utf-8

**Server:** nginx/1.4.7

**X-Powered-By:** Express

##### BODY

```auto
vBOHpOGlxZmft5uQc/dUuVkwOZnroVpuGyRbULoDK+J9MYEgfE+8e0+fMgt8mQj02j28NvDc5jBmEeX/PI2Ke3kQWvH1qDbVN0gD/SDqJfHRhnUaChR8UvwQI2TXqwz6ZT1YF9dnb70ZminZXaBGFLxHeJe7i/OgdNY1JeScLJwYd1W7C1DN9P/LJt7Bc8YySto+/wtFY4b0lSdqCK0blw==

```

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [June 11, 2014, 11:59am UTC](https://community.gatling.io/t/passing-in-data/1087/9 "2014-06-11T11:59:37Z")

</div>

Your first request, “Get API Key”, failed (maybe because it returned a bad status code), so “apiKey” wasn’t saved.
