Passing list of objects in Postman POST request -Body

25,751

example is if

@POST
    @Path("update_accounts")
    @Consumes(MediaType.APPLICATION_JSON)
    @PermissionRequired(Permissions.UPDATE_ACCOUNTS)
    void createLimit(List<AccountUpdateRequest> requestList) throws RuntimeException;

where AccountUpdateRequest :

public class AccountUpdateRequest {
    private Long accountId;
    private AccountType accountType;
    private BigDecimal amount;
...
}

then your postman request would be: http://localhost:port/update_accounts

[
         {
            "accountType": "LEDGER",
            "accountId": 11111,
            "amount": 100
         },
         {
            "accountType": "LEDGER",
            "accountId": 2222,
            "amount": 300
          },
         {
            "accountType": "LEDGER",
            "accountId": 3333,
            "amount": 1000
          }
]
Share:
25,751

Related videos on Youtube

Sara N
Author by

Sara N

web/windows Developer

Updated on July 13, 2020

Comments

  • Sara N
    Sara N almost 4 years

    I have this syntax in API-HTTP POST request

    public IHttpActionResult SyncWealthItemsForAccount([FromBody] List<IntegrationWealthItem> wealthItems, Data.EnumerationsIntegration.IntegrationType integrationType, string accountGuidId)
    

    I want to test it in Postman:I pass Authorization and content-type in header:

    Content-Type:application/x-www-form-urlencoded
    

    This is the way I'm passing the WealthItems list

    enter image description here

    [0].ExternalID means WealthItems[0].ExternalID

    I guess its not the correct way of passing it. I have the error below

    {
        "Message": "The request is invalid.",
        "ModelState": {
            "wealthItems": [
                "Ambiguous match found."
            ]
        }
    }
    

    Any help would be appreciated .

    • Wilfred Clement
      Wilfred Clement over 5 years
      Why does it feel like your request isn't the right format ? They "Key" parameter seems ominous. You are passing it as "x-www-form-urlencoded" - Is this how the server expects ?
    • Sara N
      Sara N over 5 years
      @WilfredClement I dont know how to pass and set it at all. thats just my guess. form-data is not working ,returns error
    • Wilfred Clement
      Wilfred Clement over 5 years
      What does the API specification say ? Is that an open API that you are hitting ? I can check for the details in that case. The response that you see is a valid response from the client since they expect the response to be ( for an example ) XML, JSON etc
    • Sara N
      Sara N over 5 years
      @WilfredClement I've just created it , the syntax is specified in question . and its POST request
    • Wilfred Clement
      Wilfred Clement over 5 years
      I don't see the API specification in the question, Is this a localhost that you are hitting at ? I'd give it a try if its open
    • Sara N
      Sara N over 5 years
      @WilfredClement I'm still coding it. its not in production, still Local. my main question is "how can we test API with Body of type List<Object> in Postman?"