# REST API testing with gatling

**URL:** <https://community.gatling.io/t/rest-api-testing-with-gatling/3094>\
**Category:** Gatling (Open-Source)\
**Created:** [June 21, 2016, 10:18am UTC](https://community.gatling.io/t/rest-api-testing-with-gatling/3094 "2016-06-21T10:18:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Naveen\_Goud](https://avatars.discourse-cdn.com/v4/letter/n/22d042/32.png) [@Naveen\_Goud](https://community.gatling.io/u/Naveen_Goud)\
**Post date:** [June 21, 2016, 10:18am UTC](https://community.gatling.io/t/rest-api-testing-with-gatling/3094/1 "2016-06-21T10:18:35Z")

</div>

Hello everyone,  
I am trying to test REST API using gatling. But I am getting “**status.find.is(200), but actually found 400**”. It’s for **POST** scenario. I have body parameters. So I configured “Headers and body”. please help me **ASAP.** I couldn’t figure out what went wrong in this.

package computerdatabase

import io.gatling.core.Predef.\_  
import io.gatling.http.Predef.\_  
import scala.concurrent.duration.\_

class BasicSimulation1 extends Simulation {

val httpConf = http.baseURL(“[http://192.168.0.10:23180/highresvu](http://192.168.0.10:23180/highresvu)”)  
.acceptHeader(“text/html,application/xhtml+xml,application/xml;q=0.9,_/_;q=0.8”) // Here are the common headers  
.doNotTrackHeader(“1”)  
.acceptLanguageHeader(“en-US,en;q=0.5”)  
.acceptEncodingHeader(“gzip, deflate”)  
.userAgentHeader(“Mozilla/5.0 (X11; Linux x86\_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36”)

val headers\_10 = Map(“Content-Type” → “application/xml”)  
// Note the headers specific to a given request

val scn = scenario(“My Scenario”) // A scenario is a chain of requests and pauses  
.exec(http(“Top Speed”)  
.post("/topspeed")  
.headers(headers\_10)  
.body(StringBody("""{“highResVehicleUtilization”:{"-xmlns": “[http://wirelesscar.com/highresvu/highresvehicleutilization/1\_0",“request”:{“vehicleDetails”:{"vin](http://wirelesscar.com/highresvu/highresvehicleutilization/1_0%22,%22request%22:%7B%22vehicleDetails%22:%7B%22vin)”: “RIGUD000000000057”,“chassisId”: “RIGUD-000057”},“driveSessions”:{ “driveSessionId”: “1460453954” },“duration”:{“fromDate”: “2016-05-27T10:30:10.000Z”,“toDate”: “2016-05-16T10:55:10.000Z”}}}}"""))  
.check(status.is(200)))

setUp(scn.inject(atOnceUsers(100)).protocols(httpConf))  
}

---

<div class="post-metadata">

**Author:** ![alitsiya.yusupova](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@alitsiya.yusupova](https://community.gatling.io/u/alitsiya.yusupova)\
**Post date:** [June 23, 2016, 11:31pm UTC](https://community.gatling.io/t/rest-api-testing-with-gatling/3094/2 "2016-06-23T23:31:17Z")

</div>

I’m new to Gatling, but the one thing I do differently is a payload. Try  
.body(StringBody("{“highResVehicleUtilization”:{"-xmlns": “[http://wirelesscar.com/highresvu/highresvehicleutilization/1\_0](http://wirelesscar.com/highresvu/highresvehicleutilization/1_0)”,“request”:{“vehicleDetails”:{“vin”: “RIGUD000000000057”,“chassisId”: “RIGUD-000057”},“driveSessions”:{ “driveSessionId”: “1460453954” },“duration”:{“fromDate”: “2016-05-27T10:30:10.000Z”,“toDate”: “2016-05-16T10:55:10.000Z”}}}}")) or define payload variable and convert it to json before executing scenario (like described [here](http://stackoverflow.com/questions/30884841/converting-json-string-to-a-json-object-in-scala)).

---

<div class="post-metadata">

**Author:** ![Alexander\_Gehret](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@Alexander\_Gehret](https://community.gatling.io/u/Alexander_Gehret)\
**Post date:** [August 18, 2016, 5:10am UTC](https://community.gatling.io/t/rest-api-testing-with-gatling/3094/3 "2016-08-18T05:10:12Z")

</div>

Basically your API returns a 400 instead of the expected 200. Therefore you need to check if your request is really something that is expected on your API
