Question

Inserting Bulk Contacts from REST API

Hi Experts,

Need your help on how can we insert bulk Contacts. I have written the below code. But need your suggestions to know is there any way that we can insert all the records with a single statement instead of inserting one by one inside loop? I have written this code inside "Script Task".

====================================================================

var userConnection = (UserConnection)HttpContext.Current.Session["UserConnection"];

string requestString = string.Format("https://jsonplaceholder.typicode.com/users");

var request = HttpWebRequest.Create(requestString) as HttpWebRequest;

request.Method = "GET";

request.ContentType = "application/json";

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Set("ProcessSchemaParameter2", "Response Code:"+response.StatusCode +" and Response message is:"+response.StatusDescription);

StreamReader reader = new StreamReader(response.GetResponseStream());

string jsonStr= reader.ReadToEnd();

Set("ProcessSchemaParameter1", reader.ReadToEnd());

dynamic array = JsonConvert.DeserializeObject(jsonStr);

foreach(var item in array)

{

    var insert = new Insert(userConnection).Into("Contact")

        .Set("Name",Column.Const((string) item.name));

    insert.Execute();

}

return true;

========================================================================

Thanks,

Venkat.

Like 1

Like

2 comments

Dear Venkat,

Unfortunately, there is no batch query realization with C# in the system. Please proceed every Contact separately.

Regards, 

Anastasia

Anastasia Botezat,

Thanks Anastasia

Show all comments