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

Announcements

No record found.

News and Announcements icon
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;


}

  • Suggested answer
    Wahaj Rashid Profile Picture
    11,323 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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Syed Aqib Raza Profile Picture

Syed Aqib Raza 103

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 83 Most Valuable Professional

#3
11manish Profile Picture

11manish 54 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans