0

I am new to API testing and trying to figure out how i can pass post request body with a single array which contains multiple set of request and attributes in this single array in restasssured API testing.

{
    "Transactions":
    [ 
      {"ReferenceId":"01","Id":"0727", "TCID": "67180405816294"},
      {"ReferenceId":"02","Id":"0727", "TCID": "67180405816294"},
      {"ReferenceId":"03","Id":"0727", "TCID": "67180405816294"}

    ]
}
2
  • Not sure what you're asking. When you say the array contains multiple sets of "request and attributes" do you mean that you'd like each of the elements of the array to be submitted to the API-under-test individually? That is, do you wish to make 3 separate API calls, one for each array element or you wish to make one API call that includes the entire array the request body? Commented Aug 1, 2017 at 17:07
  • its a one api call that includes the entire array the request body... Commented Aug 1, 2017 at 17:50

1 Answer 1

1

It sounds like you want to post a particular object as the body of a post request using restassured. something like the below should work:

// If you are using Object Mapping (e.g. GSON or Jackson) create your test data as java objects
List<Reference> references = ...;
TransactionDTO data = new TransactionDTO(references);

// Else, not using mapping, so create test data as string:
String data = "{ \"Transactions\": [ ...]}";

given()
  .contentType("application/json")
  .body(data)
  .queryParam("key", "value") //omit if not needed
when()
  .post("/post/url/path")
then()
  .<whatever assertions you need to make>

Reference: https://github.com/rest-assured/rest-assured/wiki/Usage

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.