Discussions
How to pass multiple records in REST API POST method?
Hi team,
I would like to create multiple records in my JSON object to insert multiples records at the same time using REST API POST. Is that possible? Please see the example below, which changes I should do in order to add more records (example diff PartyIds)?
Thanks in advance, Chris.
{
"$type":"Asi.Soa.Core.DataContracts.GenericEntityData, Asi.Contracts",
"EntityTypeName":"My_Table_Transactions",
"PrimaryParentEntityTypeName":"Party",
"Properties":{
"$type":"Asi.Soa.Core.DataContracts.GenericPropertyDataCollection, Asi.Contracts",
"$values":[
{
"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts",
"Name":"Card_Number",
"Value":"1111 1111 1111 1125"
},
{
"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts",
"Name":"PartyId",
"Value":"232323"
},
{
"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts",
"Name":"Import_Filename",
"Value":"testFile.csv"
}
]
}
}
Hi Chris,
May I inquire which version of the app you are currently using so I can better research how to assist you?
Hi Jadie,
Thanks for your response.
The iMIS Cloud version is 20.2.66.1164 (.NET framework version 4.0.30319.42000)
We need to upload the information from a .csv file with hundred or thousand of records and... instead of making one request per record,
we would like to upload the data in one post request only. I have tried different JSON file structures, but not luck, so I'm wondering if you might have some example uploading multiple records - I couldn't find anything in your documentation.
Thanks a lot for your help.
Chris,
Hi Chris,
Thank you so much for your patience.
The endpoint for adding multiple records for a specific Data Contract in 20.2.64 is /api/{service}/_addMultiple
. We do not have a list of all the services that have implemented _addMultiple
, and only a few services have them implemented, so you will need to test each of the endpoints you're working with. We currently do not have generic entity service support for multiple inserts.
An example for inserting multiple parties at the /api/Party/_addMultiple
endpoint:
{
"$type": "System.Collections.Generic.List`1[[Asi.Soa.Membership.DataContracts.PartyData, Asi.Contracts]], mscorlib",
"$values": [{
"$type": "Asi.Soa.Membership.DataContracts.PersonData, Asi.Contracts",
"PersonName": {
"$type": "Asi.Soa.Membership.DataContracts.PersonNameData, Asi.Contracts",
"FirstName": "Alice",
"LastName": "Rogers",
"FullName": "Alice A Rogers"
},
"PartyId": "23178",
"Id": "23178",
"Name": "Alice Rogers"
}, {
"$type": "Asi.Soa.Membership.DataContracts.PersonData, Asi.Contracts",
"PersonName": {
"$type": "Asi.Soa.Membership.DataContracts.PersonNameData, Asi.Contracts",
"FirstName": "Caroline",
"InformalName": "Carol",
"LastName": "Anderson",
"FullName": "Caroline Anderson"
},
"PartyId": "23179",
"Id": "23179",
"Name": "Carol Anderson"
}]
}
In 20.3, the endpoint for adding multiple records is /api/{service}/_bulkInsert
.
I hope this answers your question on multiple resources.
There is something we else noticed in the example you provided above that got our attention that we would like to mention:
We noticed in your example you're inserting credit card numbers directly into the database. We don't recommend that as it violates PCI rules. Even with encryption and engineering entity data then storing the encryption key that's not accessible by PCI may not be the safest way to store credit card information in the database. We recommend looking into AutoPayInstruction and AutoPayAccount, which would do all the right things to store the credit card in a safe way.
Is it possible to add multiple records into custom tables, the one record is very long winded, so how can I simplify it, below is only one record example:
{
"$type":"Asi.Soa.Core.DataContracts.PagedResult1[[Asi.Soa.Core.DataContracts.GenericEntityData, Asi.Contracts]], Asi.Contracts","Items": {"$type":"System.Collections.Generic.List
1[[Asi.Soa.Core.DataContracts.GenericEntityData, Asi.Contracts]], mscorlib",
"$values":[{
"$type":"Asi.Soa.Core.DataContracts.GenericEntityData, Asi.Contracts","EntityTypeName":"My_CustomTable","PrimaryParentEntityTypeName":"Party","Identity":{"$type":"Asi.Soa.Core.DataContracts.IdentityData, Asi.Contracts","EntityTypeName":"My_CustomTable","IdentityElements":{"$type":"System.Collections.ObjectModel.Collection1[[System.String, mscorlib]], mscorlib","$values":["","17861"]}},"PrimaryParentIdentity":{"$type":"Asi.Soa.Core.DataContracts.IdentityData, Asi.Contracts","EntityTypeName":"Party","IdentityElements":{"$type":"System.Collections.ObjectModel.Collection
1[[System.String, mscorlib]], mscorlib","$values":[""]}},"Properties":{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyDataCollection, Asi.Contracts","$values":[{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"ID","Value":""},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"SEQN","Value":{"$type":"System.Int32","$value":17861}},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"FirstName","Value":"Walnut W."},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"LastName","Value":"Bi"},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"Company","Value":"Place of Hour"},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"Designation","Value":"Manager"},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"Email","Value":"abc@abc.com"},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"EventCode","Value":"VLN2H3JMWPX"},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"EventTitle","Value":"Sample Webinar"},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"EventDate","Value":"2020-02-27T00:00:00"},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"AmountOrdered","Value":{"$type":"System.Decimal","$value":0.0000}},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"CO_ID","Value":"896991"},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"SOURCE","Value":"Event2020"},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"InvoiceNo","Value":"18-24022020-0329"},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"OrderNo","Value":"LVNGQJJ8GG4"},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"OrderDate","Value":"2020-02-24T00:00:00"},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"GSTAmt","Value":{"$type":"System.Decimal","$value":0.0000}},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"AmountPaid","Value":{"$type":"System.Decimal","$value":0.0000}},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"RefNo","Value":""},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"Confirmation","Value":"KFNK63PZ2TL"},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"RegType","Value":"Member"},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"PayNote","Value":"PayPal 02-Feb-2020 7:52 PM"},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"PayMethod","Value":"PayPal"},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"InviteeStatus","Value":"Accepted"},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"OnlinePay","Value":{"$type":"System.Decimal","$value":40.6600}},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"OfflinePay","Value":{"$type":"System.Decimal","$value":0.0000}},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"OfflineRefund","Value":{"$type":"System.Decimal","$value":40.6600}},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"AmountDue","Value":{"$type":"System.Decimal","$value":0.0000}},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"AmountOrderedNoGST","Value":{"$type":"System.Decimal","$value":0.0000}},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"Title","Value":""},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"TransID","Value":"7BR65617AF180504P"},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"TransDate","Value":"2020-02-03T00:00:00"},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"TransType","Value":"Online Charge"},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"CompAddress","Value":"Event Registration for Sample Post-Budget Webinar on 27 Feb 2020"},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"Phone","Value":""},{"$type":"Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts","Name":"Notes","Value":""}]}},
sefdsafsadf df gfdg
ο»Ώ