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.

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.



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.

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