# Parameterize UrlEncodedHttpBody in Web Service Object does not work with variables

**URL:** <https://forum.katalon.com/t/parameterize-urlencodedhttpbody-in-web-service-object-does-not-work-with-variables/41828>\
**Category:** API Testing\
**Tags:** api-testing, katalon-studio\
**Created:** [April 2, 2020, 11:56am UTC](https://forum.katalon.com/t/parameterize-urlencodedhttpbody-in-web-service-object-does-not-work-with-variables/41828 "2020-04-02T11:56:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ixent.gallego](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/ixent.gallego/32/11861_2.png) [@ixent.gallego](https://forum.katalon.com/u/ixent.gallego)\
**Post date:** [April 2, 2020, 11:56am UTC](https://forum.katalon.com/t/parameterize-urlencodedhttpbody-in-web-service-object-does-not-work-with-variables/41828/1 "2020-04-02T11:56:48Z")

</div>

I have seen Here:  
[https://docs.katalon.com/katalon-studio/docs/parameterize-a-web-service-object.html](https://docs.katalon.com/katalon-studio/docs/parameterize-a-web-service-object.html)  
and here:

> **[REST API testing with Katalon - Mitch Valenta](https://mitch.codes/rest-api-testing-with-katalon/)**
>
> Katalon Background Recently, I had the opportunity of figuring out how to test a REST API using Katalon. Katalon is

How to dinamically parametraze your web service objects.  
But none of these works with Url Encoded Body parameters… Why Not?

This does not work:

 ![url-encoded-variables](https://europe1.discourse-cdn.com/katalon/original/2X/4/4a9d44c65ab6fbe0b1d4b656b586395ea25a01f7.png)

Also, if instead of this I want to do it programatically (which is fine for me) If we look at the class  
HttpUrlEncodedBodyContent in the documentation:  
[https://docs.katalon.com/javadoc/com/kms/katalon/core/testobject/impl/HttpUrlEncodedBodyContent.html](https://docs.katalon.com/javadoc/com/kms/katalon/core/testobject/impl/HttpUrlEncodedBodyContent.html)

There is **no method** to iterate through the ‘List\<UrlEncodedBodyParameter\> parameters’… and **not even** get them. so I can’t get the body parameters of the request, modify them, and create a new HttpUrlEncodedBodyContent to set to the request.

Creating the HttpUrlEncodedBodyContent from scratch every time is far from optimal, I have a template in the Object Repository as a Web Service Request, so it makes sense that I could get that request and modify it.

Any way to do this?

Best Regards,  
Ixent.

---

<div class="post-metadata">

**Author:** ![ThanhTo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/thanhto/32/697_2.png) [@ThanhTo](https://forum.katalon.com/u/ThanhTo)\
**Post date:** [April 2, 2020, 4:26pm UTC](https://forum.katalon.com/t/parameterize-urlencodedhttpbody-in-web-service-object-does-not-work-with-variables/41828/2 "2020-04-02T16:26:04Z")

</div>

Hi @ixent.gallego

What version are you using ?

My test script

```auto
RequestObject to = findTestObject('Object Repository/New Request', ['variable_name' : 'my value']);
println to.httpBody

```

prints

```auto
variable_name=my+value

```

where variable\_name is specified as a variable with empty default value.

---

<div class="post-metadata">

**Author:** ![ixent.gallego](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/ixent.gallego/32/11861_2.png) [@ixent.gallego](https://forum.katalon.com/u/ixent.gallego)\
**Post date:** [April 2, 2020, 6:09pm UTC](https://forum.katalon.com/t/parameterize-urlencodedhttpbody-in-web-service-object-does-not-work-with-variables/41828/3 "2020-04-02T18:09:52Z")

</div>

Hello @ThanhTo ,

Using Katalon Studio 7.2.6

I had this:

> def request = findTestObject(‘Backend/Auth/GetToken’, [(‘username’) : username, (‘password’) : password]) as RequestObject

Kept getting bad request as a response, but if I replace the values with harcoded ones in the request,  
it works fine.

Hmmmm, that’s strange. Logging the request body (with variable replacement) this appears:

grant\_type=password&client\_id=umclient&username=um\_user&password=password

which seems as expected. But I get a response as if the credentials weren’t good.

Anyway, removed a previous reply because the issues were not correct and was out of the scope of the main problem.

The approach you showed to replace the variables, and the one I initially tried (which is also the one explained in the links) wasn’t working for some reason. But it is true that Logging the request body it appears correctly.

This seems to be an issue at my side, so I’d consider this resolved.

Thanks for your time,  
Ixent.

---

<div class="post-metadata">

**Author:** ![az57](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/az57/32/30227_2.png) [@az57](https://forum.katalon.com/u/az57)\
**Post date:** [June 27, 2025, 12:58am UTC](https://forum.katalon.com/t/parameterize-urlencodedhttpbody-in-web-service-object-does-not-work-with-variables/41828/4 "2025-06-27T00:58:20Z")

</div>

This is the latest one while some of the methods are depreceated, just wanted to document here for anyone who is struggling like me to get this solution

import com.kms.katalon.core.testobject.impl.HttpFileBodyContent  
import com.kms.katalon.core.testobject.impl.HttpFormDataBodyContent  
import com.kms.katalon.core.testobject.impl.HttpUrlEncodedBodyContent as HttpUrlEncodeBodyContent  
import com.kms.katalon.core.testobject.UrlEncodedBodyParameter as UrlEncodedBodyParameter

RequestObject reqObj = findTestObject(‘Object Repository/XX/XX’)

List nameValuePairs = new ArrayList()

nameValuePairs.add(new UrlEncodedBodyParameter(“grant\_type”,GlobalVariable.API\_Grant\_Type))  
nameValuePairs.add(new UrlEncodedBodyParameter(“client\_id”, GlobalVariable.API\_Client\_ID))

nameValuePairs.add(new UrlEncodedBodyParameter(“client\_secret”,GlobalVariable.API\_Client\_Secret))

nameValuePairs.add(new UrlEncodedBodyParameter(“scope”,GlobalVariable.API\_Scope))  
reqObj.setBodyContent(new HttpUrlEncodeBodyContent(nameValuePairs))

//Sending the request

request = WS.sendRequest(reqObj)

//Verify the 200 message is displayed  
assert request.getStatusCode() == 200

//Getting the Response body value  
def slurper = new JsonSlurper()  
def response= slurper.parseText(request.getResponseText())

//Getting the token from the API’s response and passing on to the Global Variable  
def Token = response.access\_token  
GlobalVariable.TOKEN = “Bearer” + " " + Token  
println GlobalVariable.TOKEN
