2

I need to pass the following URL:

https://api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests?objectFilter={"virtualGuests":{"hostname":{"operation":"hostnameTest"}}}

I tried by different ways, but it doesn't work, this is part of my code:

System.out.println(
                given().
                 when().get("https://api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests?objectFilter={\"virtualGuests\":{\"hostname\":{\"operation\":\"hostnameTest\"}}}").asString());

    }

Exception:

java.lang.IllegalArgumentException: Invalid number of path parameters. Expected 1, was 0. Undefined path parameters are: "virtualGuests":{"hostname":{"operation":"hostnameTest".

According to the exception, I think I should need to use path parameters, I tried with that but I didn't have success.

Also, I tried to replace { with character escape code %7B.

Any ideas? Thanks in advance

2 Answers2

0

I just tried this:

encodeURI('{"virtualGuests":{"hostname":{"operation":"hostnameTest"}}}')

And it gives me:

"%7B%22virtualGuests%22:%7B%22hostname%22:%7B%22operation%22:%22hostnameTest%22%7D%7D%7D"
Sebastian Brand
  • 547
  • 4
  • 10
0

Thanks a lot Sebastian and Robert!

I didn't have success using the encodeURI, however I used queryParam and it works

given().
                        queryParam("objectFilter", "{\"virtualGuests\":{\"hostname\":{\"operation\":\"hostnameTest\"}}}").
                 when().get("/SoftLayer_Account/getVirtualGuests")
                .then().assertThat().body("id", hasItem(1111111));   

Many Thanks!