Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Suggested answer

problem to call Elastic search Geolocation into dynamics 365 using custom workflow

Posted on by 170

Hello All,

I am using Ms Dynamics 365 V9.2 on line

I am trying to get geolocation details from elastic Search and populate crm. I created a custom workflow which runs on create a contact entity or update some fields data and set gps details (latitude and longitude).

I am facing on an issue when i call Elastic search via httpclient. postAsync() it returns statucode Forbidden. But the same code in my console app works fine.

I call the below method in codeactivity Execute method.

Thanks for your help.

Ps:

Here is a part of my code.

public JToken LoadES(string addressCRM, string key, string url, ITracingService tracingService)
{

HttpClientHandler handler = new HttpClientHandler();
handler.UseProxy = true;
HttpClient _httpClient = new HttpClient(handler);
JToken gpsToken = null;
var bodydata = @"{'size': 1, 'query': {'match': { 'full_address': {'query':'" + addressCRM + "','fuzziness': 'AUTO'}}}}";
JsonSerializer jsonSerializer = JsonSerializer.CreateDefault();
using (var stream = new MemoryStream())
using (var streamWriter = new StreamWriter(stream, Encoding.UTF8))
using (var jsonWriter = new JsonTextWriter(streamWriter))
{
jsonSerializer.Serialize(jsonWriter, bodydata);
jsonWriter.Flush();
HttpContent body = new StreamContent(stream);
body.Headers.ContentType = new MediaTypeHeaderValue("application/json");
_httpClient.DefaultRequestHeaders.Add("Authorization", key);
// this response is not success . 
var response = _httpClient.PostAsync(url, body).Result; 

if (response.IsSuccessStatusCode)
{
tracingService.Trace("Success Post Async response.... ");

var result = response.Content.ReadAsStringAsync();
var res = result.Result;
if (!String.IsNullOrEmpty(res))
{
JObject jresponse = JObject.Parse(res);
gpsToken = jresponse["hits"]["hits"][0]["_source"]["gps"];
}
}
else {

tracingService.Trace("Post Async Failed.... " +response.ReasonPhrase);
}

}
return gpsToken;


}

  • CDamy Profile Picture
    CDamy 170 on at
    RE: problem to call Elastic search Geolocation into dynamics 365 using custom workflow

    Hello Wahaj,

    I asked our it infra, they block access, i can't make server to server call. For the security reason they are trying to see how to control and open for server to server calls. for instance i transfered the logic on client-side and it works.

    Thanks a lot.

    Kind regards

  • CDamy Profile Picture
    CDamy 170 on at
    RE: problem to call Elastic search Geolocation into dynamics 365 using custom workflow

    Hi Wahaj,

    I will ask to the Infra team and will let you know if it fix the issue.

    Thanks for all.

    Kind regards

  • Suggested answer
    Wahaj Rashid Profile Picture
    Wahaj Rashid 11,319 on at
    RE: problem to call Elastic search Geolocation into dynamics 365 using custom workflow

    Hi,

    Thank you for your query.

    Seems like the Dynamics 365 IP address is forbidden to make request to Elastic Search.

    It is likely that your machine (or work network) is white-listed, that is the reason you can make successful requests form your machine.

    When you use a workflow, the request is originated form one of the Dynamics 365 Online servers, hence, you need to white-list Dynamics 365 IP ranges.

    Here you can find more details:

    Requirements/supported configurations - Power Platform | Microsoft Docs

    If you are not sure how to this, forward this to your Infra. team, they should able to help you.

    You need to make sure to white-list full range of IPs, as request IP can change depending on server availability.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,532 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,501 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans