Sara N
Sara N

Reputation: 1209

Passing list of objects in Postman POST request -Body

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.

Upvotes: 4

Views: 54664

Answers (2)

Pinki Bhinder Mittal
Pinki Bhinder Mittal

Reputation: 111

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

Upvotes: 4

theandroid
theandroid

Reputation: 1043

Request must be passed as JSON. So you should set Headers section in Postman to have Content-Type to be application/json. enter image description here

Your body section in postman should have the option Raw chosen and the body can be like the snippet below, enter image description here Note: In this sample MessagePartTransfer is a list and each MessagePartTransfer has 2 properties - MessagePartId and MessagePartTypeId

Service Method that is being tested:

public ICollection<MessagePartTransferResponse> DistributeMessages(ICollection<MessagePartTransfer> messageParts, long applicationId, long transactionId)

MessageTransferPart class and properties:

[DataContract(Name = "MessagePartTransfer")]
public class MessagePartTransfer
{
    public MessagePartTransfer();

    [DataMember]
    public long MessagePartId { get; set; }
    [DataMember]
    public long MessagePartTypeId { get; set; }
}

Postman request Body: (In this example I am sending 2 objects of type MessagePartTransfer)

[
    {

        "MessagePartId": 1,
        "MessagePartTypeId":2
    },
    {
        "MessagePartId":3,
        "MessagePartTypeId":4
    }
 ]

Upvotes: 4

Related Questions