public async Task <IActionResult> GetServiceReps() { using (SqlConnection con = new SqlConnection(ConnectionString)) { con.Open(); try { ServiceReps res = await TempWorksAPI.GetServiceRepsFromTempworksAsync(); foreach (ServiceRep rep in res.data) { try { DataLayer.TempWorks.AddServiceRepProc(con, rep); } catch (Exception ex) { _context.SaveErrorProc(con, "Error servicerep " + rep.serviceRepFullName.ToString(), ex.Message); } } } catch (Exception ex) { _context.SaveErrorProc(con, "Error JobOrder", ex.Message); return(BadRequest(ex.Message)); } } return(Ok()); }
public static async System.Threading.Tasks.Task <ServiceReps> GetServiceRepsFromTempworksAsync() { using (HttpClient client = new HttpClient()) { // Call asynchronous network methods in a try/catch block to handle exceptions client.DefaultRequestHeaders.Add("x-tw-token", APIKey); var result = await client.GetAsync("https://api.ontempworks.com/datalists/ServiceReps?skip=0&take=10000&includeInactives=true"); ServiceReps res = await result.Content.ReadFromJsonAsync <ServiceReps>(); return(res); } }