3

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 .

jason.kaisersmith
  • 8,712
  • 3
  • 29
  • 51
Sara N
  • 1,079
  • 5
  • 17
  • 45
  • 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 ? – Wilfred Clement Aug 30 '18 at 06:52
  • @WilfredClement I dont know how to pass and set it at all. thats just my guess. form-data is not working ,returns error – Sara N Aug 30 '18 at 07:54
  • 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 – Wilfred Clement Aug 30 '18 at 07:57
  • @WilfredClement I've just created it , the syntax is specified in question . and its POST request – Sara N Aug 30 '18 at 08:01
  • 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 – Wilfred Clement Aug 30 '18 at 08:03
  • @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 in Postman?" – Sara N Aug 30 '18 at 08:06

2 Answers2

4

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

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
    }
 ]
theandroid
  • 809
  • 1
  • 6
  • 13