public async Task <List <Entity> > QualifyLeadAsync(QualifyLeadRequest action) { string fullUrl = $"{ApiUrl}/leads({action.LeadId:P})/Microsoft.Dynamics.CRM.QualifyLead"; JObject jObject = action.GetRequestObject(); var request = new HttpRequestMessage(new HttpMethod("POST"), fullUrl) { Content = new StringContent(JsonConvert.SerializeObject(jObject), Encoding.UTF8, "application/json") }; HttpResponseMessage response = await Authorization.GetHttpClient().SendAsync(request); ResponseValidator.EnsureSuccessStatusCode(response); string responseContent = await response.Content.ReadAsStringAsync(); var data = JsonConvert.DeserializeObject <JObject>(responseContent); List <Entity> entities = QualifyLeadResponseFormatter.GetCreatedEntities(data); foreach (Entity entity in entities) { EntityDefinition entityDefinition = WebApiMetadata.GetEntityDefinition(entity.LogicalName); string primaryKey = entityDefinition?.PrimaryIdAttribute; if (entity.Contains(primaryKey)) { entity.Id = Guid.Parse(entity.GetAttributeValue <string>(primaryKey)); } } return(entities); }
public async Task <Guid> AddToQueueAsync(Guid queueId, EntityReference entity) { string fullUrl = $"{ApiUrl}/queues{queueId:P}/Microsoft.Dynamics.CRM.AddToQueue"; EntityDefinition entityDefinitions = WebApiMetadata.GetEntityDefinition(entity.LogicalName); var target = new JObject(); target[entityDefinitions.PrimaryIdAttribute] = entity.Id.ToString("D"); target["@odata.type"] = $"Microsoft.Dynamics.CRM.{entityDefinitions.LogicalName}"; var requestObject = new JObject(); requestObject.Add("Target", target); var request = new HttpRequestMessage(new HttpMethod("POST"), fullUrl) { Content = new StringContent(JsonConvert.SerializeObject(requestObject), Encoding.UTF8, "application/json") }; HttpResponseMessage response = await Authorization.GetHttpClient().SendAsync(request); ResponseValidator.EnsureSuccessStatusCode(response); var data = JsonConvert.DeserializeObject <JObject>(await response.Content.ReadAsStringAsync()); return(data["QueueItemId"].ToObject <Guid>()); }