Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Getting "The remote server returned an error: (403) Forbidden." exception while accessing the CRM 365 Online Custom Entity from Web ApI in Third Party Application.

Posted on by Microsoft Employee

Hi Team,

Have installed custom solution which will create a custom entity "XXX" in the CRM 365 online-- solution installed successfully.

Have tried to access the custom entity in third party application using WebApi method. but getting below error. "

The remote server returned an error: (403) Forbidden.  at System.Net.HttpWebRequest.GetResponse()"

Able to access standard entities but unable to access custom entities 

Able to fetch desired response with "api/data/v9.0/WhoAmI" , but below URL is throwing exception "api/data/v9.0/XXX".

code Sample:

string token = string.Empty;
string InboundData = "https://crmOrg.api.crm8.dynamics.com/api/data/v9.0/XXX";
try
{
AuthenticationContext authContext =
new AuthenticationContext(Authority);
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ClientCredential credentials = new ClientCredential(ClientId, ClientSecret);
AuthenticationResult _authResult = await authContext.AcquireTokenAsync(Resource, credentials);
token = _authResult.AccessToken;
WebRequest request1 = WebRequest.Create(InboundData);
request1.ContentType = @"application/json; charset=utf-8";
request1.Method = "GET";
request1.Headers.Add("Authorization", "Bearer " + token);
HttpWebResponse response1 = request1.GetResponse() as HttpWebResponse;
string jsonResponse1 = string.Empty;
using (StreamReader sr = new StreamReader(response1.GetResponseStream()))
{
jsonResponse1 = sr.ReadToEnd();
}
}

Thanks.

*This post is locked for comments

  • Suggested answer
    bac26 Profile Picture
    bac26 2,268 on at
    RE: Getting "The remote server returned an error: (403) Forbidden." exception while accessing the CRM 365 Online Custom Entity from Web ApI in Third Party Application.

    Are their routers or firewalls installed in between?  Could be locked down so that you cannot access from outside the network?  

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans