Type mismatch error when trying to pass a string as parameter to .body for a POST request

Hi Everyone,
I am new to Gatling and I am trying to fire a basic POST request with a single parameter. It is throwing me an type mismatch error when I passed a string as parameter to the ‘.body’ method. I also tried using ‘.param’ but got a ‘406 Not acceptable’ as response from the server. Any help is greatly appreciated. I was able to successfully test the same scenario with JMeter.

URL to test: https://uat.servicegateway.com/api/FindServiceProviderBySPID?authtoken=MFxnKqyKgcQqBPrT93OJOGqgJs/qOadikDvBY5bEk8GGoMMPhqrp
POST body or param : {“ServiceProviderIdentifier”:2108231}

My Simulation:

import io.gatling.core.Predef._
import io.gatling.core.session.Expression
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
import io.gatling.http.Headers.Names._
import io.gatling.http.Headers.Values._
import io.gatling.http.request._
import scala.concurrent.duration._
import bootstrap._
import assertions._

class ServiceGatewayRequest extends Simulation {

val httpProtocol = http

val header = Map(
“”“Access-Control-Allow-Origin”"" → “”"*""",
“”“Access-Control-Allow-Headers”"" → “”“Origin, X-Requested-With, Content-Type, Accept”"",
“”“Content-Type”"" → “”“application/json”"")

val scn = scenario(“Servive Gateway Request”)
.exec(http(“Fetch SP Details and Categories”)
.body("""{ “ServiceProviderIdentifier”:“2108231” }""").asJSON)
// .param(“ServiceProviderIdentifier”,“2108231”))

setUp(scn.inject(atOnce(1 user))).protocols(httpProtocol)

The error I am getting when i ran the above simulation is:

13:38:52.555 [ERROR] i.g.a.ZincCompiler$ - C:\Users\uguduru\Desktop\Work\rapid-fire-master\user-files\simulations\ServiceGatewayRequest.scala:35: type mismatch;
found : String("{ “ServiceProviderIdentifier”:“2108231” }")
required: io.gatling.http.request.Body
13:38:52.559 [ERROR] i.g.a.ZincCompiler$ - .body("""{ “ServiceProviderIdentifier”:“2108231” }""").asJSON)
13:38:52.560 [ERROR] i.g.a.ZincCompiler$ - ^
13:38:52.604 [ERROR] i.g.a.ZincCompiler$ - one error found

You can try the following :

.body(BodyString("""{ “ServiceProviderIdentifier”:“2108231” }""")).asJSON

A bit more detailed: I’d say you’re using Gatling 2 (which is a work in progress) with the Gatling 1 syntax. As mentioned on every page, the wiki is about Gatling 1, except for the page named Gatling 2: https://github.com/excilys/gatling/wiki/Gatling%202#wiki-bodies

Hi Stephane,
Thanks for the help. It worked.