public async Task <IActionResult> Index([FromBody] Payload Payload) { try { SalesforceAuthParams SalesforceAuth = JsonConvert.DeserializeObject <SalesforceAuthParams> (JsonConvert.SerializeObject(Payload.config.crm)); AuthenticationResponse AuthenticationResponse = await this.Authenticate(SalesforceAuth); if (AuthenticationResponse.access_token == null) { return(StatusCode(401, "Authentication with Salesforce failed!")); } else { if (Payload.agentWork != null) { Log("Agent Work", "Outgoing Routing", JsonConvert.SerializeObject(Payload.agentWork)); Dictionary <string, object> PendingServiceRouting = await this.RetrievePendingServiceRouting(AuthenticationResponse, Payload.agentWork.id); var response = await this.CreateAgentWork(AuthenticationResponse, Payload.agentWork, PendingServiceRouting); } } } catch (HttpRequestException ex) { return(StatusCode(500, ex.Message)); } return(Ok()); }
public async Task <AuthenticationResponse> Authenticate(SalesforceAuthParams SalesforceAuth) { try { HttpRequestMessage Authenticate = new HttpRequestMessage(HttpMethod.Post, "https://login.salesforce.com/services/oauth2/token"); var AuthString = "grant_type=password&client_id=" + SalesforceAuth.ClientId + "&client_secret=" + SalesforceAuth.ClientSecret + "&username="******"&password="******"application/x-www-form-urlencoded"); Authenticate.Content = httpContent; HttpResponseMessage AuthenticateResponse = await httpClient.SendAsync(Authenticate); AuthenticationResponse Auth = JsonConvert.DeserializeObject <AuthenticationResponse> ( await AuthenticateResponse.Content.ReadAsStringAsync()); return(Auth); } catch (Exception ex) { throw ex; } }