Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

403 forbidden for "msdyn_productinventories" Rest API

(0) ShareShare
ReportReport
Posted on by

Hi friends,

I'm trying to get the inventory of a particular product by using Postman tool. My authentication process is: 

URL: https://XXX.dynamics.com/api/data/v9.0/msdyn_productinventories

Authorization: Bearer {token}

Output :

{
"error": {
"code": "0x80040220",
"message": "Principal user (Id=7b463d39-3b03-e811-a958-000d3af28edd, type=8) is missing prvReadmsdyn_productinventory privilege (Id=0e2c9a93-1725-4009-b591-e51e43e849ba)",
"innererror": {
"message": "Principal user (Id=7b463d39-3b03-e811-a958-000d3af28edd, type=8) is missing prvReadmsdyn_productinventory privilege (Id=0e2c9a93-1725-4009-b591-e51e43e849ba)",
"type": "System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]",
"stacktrace": " at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.RetrieveMultiple(QueryBase query, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode, Guid appModuleId)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataExecutionContext.RetrieveMultiple(QueryBase query)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.RetrieveEdmEntityCollection(CrmODataExecutionContext context, String entityCollectionName, String castedEntityName, ODataQueryOptions queryOptions)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.<>c__DisplayClass35_0.<GetEntitySetInternal>b__1()\r\n at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute(ILogger logger, EventId eventId, ActivityType activityType, Action action)\r\n at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute(ILogger logger, XrmTelemetryActivityType activityType, Action action)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySetInternal(String entitySetName, String castedEntityName, CrmODataExecutionContext context, CrmEdmEntityObjectCollection crmEdmEntityObjectCollection, ODataQueryOptions queryOptions)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySetImplementation(String entitySetName)\r\n at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute[TResult](ILogger logger, EventId eventId, ActivityType activityType, Func`1 func)\r\n at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute[TResult](ILogger logger, XrmTelemetryActivityType activityType, Func`1 func)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
}
}

It is showing "403 forbidden error". How to give full permission to inventory such that I can get the inventory details of products.

I am able to Read, Create, Update the product, contacts, sales order but, for inventory I am unable to do that.

Please help me on this.

Thanks

Hiba

*This post is locked for comments

  • RE: 403 forbidden for "msdyn_productinventories" Rest API

    Hello Nithiya,

    I am getting 403: Access is forbidden error from Postman. I'm attaching the screenshot of the same for your reference.

    2234.Capture2.PNG

      I'm also sending you the sample code for "GET" web request.

    private static string AuthorizationCRM()    {

               try

               {

                   string guid = Guid.NewGuid().ToString();

                   string apiUrl = @"xxx.api.crm8.dynamics.com/.../v9.0";

                   AuthenticationParameters ap = AuthenticationParameters.CreateFromResourceUrlAsync(new Uri(apiUrl)).Result;

                   var creds = new ClientCredential("d67484c5-bf85-445e-90ed-252bfd667f3b", "cd63O7u0E4lRTrSwQK0zTufDLZBl5up2iGY/G2DviJY=");

                   AuthenticationContext authContext2 = new AuthenticationContext(ap.Authority);

                   string token2 = authContext2.AcquireTokenAsync(ap.Resource, creds).Result.AccessToken;

                   string path = "contacts?fetchXml=<fetch distinct=\"false\" mapping=\"logical\" output-format=\"xml-platform\" version=\"1.0\" ><entity name=\"contact\" ><attribute name=\"fullname\" /></entity></fetch>";

                   path = "msdyn_productinventories";

                   var combine = apiUrl + path;

                   var httpClient = HttpWebRequest.CreateHttp(combine);

                   httpClient.Headers.Add(HttpRequestHeader.Authorization, "Bearer:" + token2);

                   httpClient.Headers.Add("OData-MaxVersion", "4.0");

                   httpClient.Headers.Add("OData-Version", "4.0");

                   httpClient.Accept = "application/xml";

                   httpClient.ContentType = "application/xml;charset=utf-8";

                   using (var sr = new StreamReader(httpClient.GetResponse().GetResponseStream()))

                   {

                       Console.WriteLine(sr.ReadToEnd());

                       return Console.ReadLine();

                   }

               }

               catch (WebException webEx)

               {

                   StreamReader reader = new StreamReader(webEx.Response.GetResponseStream());

                   var actualError = reader.ReadToEnd();

                   return actualError;

               }

           }

    Please suggest me where am I wrong and how to proceed.

    Regards

    Hiba

  • Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: 403 forbidden for "msdyn_productinventories" Rest API

    Hi Hiba,

    The above response shows that the user will be able to retrieve the record via Web API.

    Now, what is the error you get on Postman while accessing the API?

  • RE: 403 forbidden for "msdyn_productinventories" Rest API

    Hi Nithiya,

    This is the response which i got.

    {"@odata.context":"xxx.api.crm8.dynamics.com/.../v9.0$metadata#msdyn_productinventories","value":[{"@odata.etag":"W/\"2605362\"","_organizationid_value":"ca8b144b-f2f1-42e5-a9ac-8a40857c0368","_msdyn_unit_value":"aebb4b24-e20a-4720-b69d-4f1db5e48bec","msdyn_qtyonhand":0.0,"msdyn_qtyallocated":0.0,"statecode":0,"statuscode":1,"_createdby_value":"dfa1495d-9f01-e811-a958-000d3af289b8","msdyn_qtyonorder":0.0,"_msdyn_warehouse_value":"5b743789-c329-41ee-89e5-f81b83570131","msdyn_productinventoryid":"61dd9109-4a7f-e811-a95b-000d3af28740","_msdyn_product_value":"26d69ac3-b9c4-432a-89ff-cfdf0a350c89","_modifiedby_value":"dfa1495d-9f01-e811-a958-000d3af289b8","createdon":"2018-07-04T05:21:05Z","msdyn_qtyavailable":0.0,"versionnumber":2605362,"modifiedon":"2018-07-04T05:21:05Z","_createdonbehalfby_value":null,"msdyn_row":null,"msdyn_name":null,"overriddencreatedon":null,"msdyn_internalflags":null,"msdyn_reorderpoint":null,"utcconversiontimezonecode":null,"msdyn_bin":null,"timezoneruleversionnumber":null,"importsequencenumber":null,"_modifiedonbehalfby_value":null},{"@odata.etag":"W/\"2605381\"","_organizationid_value":"ca8b144b-f2f1-42e5-a9ac-8a40857c0368","_msdyn_unit_value":"056f8e2c-9005-e811-a958-000d3af28edd","msdyn_qtyonhand":0.0,"msdyn_qtyallocated":0.0,"statecode":0,"statuscode":1,"_createdby_value":"dfa1495d-9f01-e811-a958-000d3af289b8","msdyn_qtyonorder":0.0,"_msdyn_warehouse_value":"5b743789-c329-41ee-89e5-f81b83570131","msdyn_productinventoryid":"166c88f9-4a7f-e811-a95b-000d3af28740","_msdyn_product_value":"6d4f5b03-6133-4565-aa7f-01790597d80b","_modifiedby_value":"dfa1495d-9f01-e811-a958-000d3af289b8","createdon":"2018-07-04T05:27:50Z","msdyn_qtyavailable":0.0,"versionnumber":2605381,"modifiedon":"2018-07-04T05:27:50Z","_createdonbehalfby_value":null,"msdyn_row":null,"msdyn_name":null,"overriddencreatedon":null,"msdyn_internalflags":null,"msdyn_reorderpoint":null,"utcconversiontimezonecode":null,"msdyn_bin":null,"timezoneruleversionnumber":null,"importsequencenumber":null,"_modifiedonbehalfby_value":null},{"@odata.etag":"W/\"2605382\"","_organizationid_value":"ca8b144b-f2f1-42e5-a9ac-8a40857c0368","_msdyn_unit_value":"056f8e2c-9005-e811-a958-000d3af28edd","msdyn_qtyonhand":0.0,"msdyn_qtyallocated":0.0,"statecode":0,"statuscode":1,"_createdby_value":"dfa1495d-9f01-e811-a958-000d3af289b8","msdyn_qtyonorder":0.0,"_msdyn_warehouse_value":"5b743789-c329-41ee-89e5-

    Regards

    Hiba

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: 403 forbidden for "msdyn_productinventories" Rest API

    Hi Hiba,

    Can you login to the CRM with the user credentials and see if he is able to open the link below in a new tab in the browser?

    xxx.dynamics.com/.../msdyn_productinventories

  • RE: 403 forbidden for "msdyn_productinventories" Rest API

    Hi Nithiya,

    I've given the permission as per your direction. Please go through the image below.

    Capture_2E00__2E00__2E00__2E00_.PNG

    Capture_2E00__2E00__2E00__2E00_.PNG

    Regards

    Hiba

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: 403 forbidden for "msdyn_productinventories" Rest API

    Hi Hiba,

    Go to Settings --> Security --> Security Roles.

    Select Field Service - Resource and navigate to Tab Custom Entities.

    Give this role to the user with whose credentials you are logging in the code.

    In order to give the role, go to  Settings --> Security --> Users.

    Select the user and Click on Manage Roles in the command bar. Choose Field Service - Resource role and click OK.

    Hope this helps.

  • RE: 403 forbidden for "msdyn_productinventories" Rest API

    I'm getting this from custom code as well.

  • RE: 403 forbidden for "msdyn_productinventories" Rest API

    Hi Nithya.

    Thanks for your kind reply. But, my problem is not resolved yet.

    From where are you getting the screen shot? Give the path. It will be grateful.

  • PranavShroti Profile Picture
    PranavShroti 4,510 on at
    RE: 403 forbidden for "msdyn_productinventories" Rest API

    are you facing this issue only using postman tool or from custom code as well ?

    Regards,

    Pranav

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: 403 forbidden for "msdyn_productinventories" Rest API

    Hi Hiba,

    Please give the user read privilege to access the msdyn_productinventory.

    Go to Settings --> Security --> Users.

    Select the user and click on Manage Roles.

    Give Field Service - Resource role to the user which gives read privilege on Product Inventory entity.

    See the screenshot below.

    721680.Capture.PNG

    Hope this helps.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,403 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans