AnsweredAssumed Answered

Need help with RestSharp call to POST /bulk endpoint

Question asked by Jeff Whitney on Apr 16, 2019
Latest reply on May 2, 2019 by Ken McCartney

Has anyone used RestSharp in .NET to make a POST to the /bulk interface? I'm currently creating several related records by looping thru them individually...each loop makes a separate POST call using the same info other than the Parameter JSON string. The BaseUrl, RestUrl, ModuleUrl, EndpointUrl, MethodUrl, and Header values are fixed during the loop. How can this be done with one RestSharp Request / Response? From what I  understand, I should use a POST / bulk call, but I'm confused on how to structure the parameter string, especially when I also creating related records in the loop. If my looping pseudo code is the following...

 

For Each Related Record To Create

  ParameterString = Current Related Record JSON Parameters String
  RestObject.Initialize()
  RestObject.ModuleName = "ParentModuleName"
  RestObject.RespModName = "RelatedModuleName"
  RestObject.EndpointUrl = "/" & ParentRecord.id & "/link/RelationshipName"
  RestObject.Client = New RestClient(BaseUrl & RestUrl & ModuleUrl & EndpointUrl & MethodUrl)
  RestObject.Request = New RestRequest(Method.POST)
  RestObject.Request.AddHeader("OAuth-Token", GlobalSugarOAthObject.AccessToken)
  RestObject.Request.AddParameter("undefined", ParameterString, ParameterType.RequestBody)
  RestObject.Response = RestObject.Client.Execute(RestObject.Request)

Next

 

ParameterString is the only variable changing each time. How can this be structured to make a single POST /bulk call?

 

Thanks

Outcomes