Parameterizing HTTP Body for API testing

I am trying to run some API tests where I have two different JSON file payloads I want to test with.

I followed the instructions in the guide below for POST testing, but my tests keep failing with error codes 400 Bad Request.

https://docs.katalon.com/display/KD/Parameterize+a+Web+Service+object

One difference I’ve noticed between the article’s example and my API tests is that running a test request from my Object repository file will fail since my parameter’s value isn’t specified, but in the documentation’s example, their test still works.

Is there a workaround to make the documentation’s solution work or a way that I can add multiple JSON files to my test and specify which one to use during each test?

Running from the object repository like this should fail (though it doesn’t in the guide):

But when I create a test case and add in my parameter in script mode, my test again fails with an error code of 400.

Capture.PNG

Capture1.PNG

1 Like

Looks to me that you are trying to run your parameterized request directly from the Object Repository itself, which does not work, coz the parameters are not handled there (yet).

Maybe add a feature request for being able to test Parametrized Web Services objects directly from the Repository too.

The working example you mentioned however is being runned from a script.

Thomas,
Your request could not be executed at Object Repository since it only contains parameters, not the actual value. In order to test the web service, you could create a test case, add Send Request test step for this web service and execute the test there.

Sorry I did not make this clear in my original post, but I understand that I should get a 400 error when I run directly from the object repository. My issue is that when I then created a Test Case where I specified the value of my parameter the Test Case also failed with a 400 error.

A shot in the dark: Are you maybe missing the quotes around your variable ${state01} in your HTTP body ?

Maybe use “${state01}” instead ?

1 Like

That worked, thanks!

I’ve been experiencing the same issue, and have tried with the double quotes too, but it just passes the syntax as a text string.

@Salema_Begum I experienced the same behavior.

But then I found in my case it happened when the variable type was String and I passed it null.
If I pass an empty string ‘’ or any string, it will work.

So, if you are in the same boat, just pass empty string for nulls.

1 Like

@jp12 thanks, it’s working for me now :slight_smile:

1 Like

How to pass the send request from test case, Can you give any example

Hi there, :wave:

Thank you very much for your topic! It may take a little while before Katalon team member or others forum members respond to you.

In the meantime, you can double-check your post to see if you can add any extra information i.e. error logs, HTML codes, screenshots, etc. Check out this posting guide to help us help you better!

Thanks! :sunglasses:
Katalon Community team

Click on the Plus sign in the API call . It will suggest you to add to a new test case or existing test case.

Using Web Services in a test case in Katalon Studio | Katalon Docs