web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

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

(0) ShareShare
ReportReport
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;


}

I have the same question (0)
  • Suggested answer
    Wahaj Rashid Profile Picture
    11,321 on at

    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.

  • CDamy Profile Picture
    170 on at

    Hi Wahaj,

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

    Thanks for all.

    Kind regards

  • CDamy Profile Picture
    170 on at

    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Pallavi Phade Profile Picture

Pallavi Phade 98

#2
Tom_Gioielli Profile Picture

Tom_Gioielli 60 Super User 2025 Season 2

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 43 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans