Passing list of objects in Postman POST request -Body

Sara N picture Sara N · Aug 30, 2018 · Viewed 23.3k times · Source

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 .

Answer

Pinki Bhinder Mittal picture Pinki Bhinder Mittal · Jan 29, 2020

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
          }
]