3

We are using cloud Dynamics 365 Business Central and trying to get items with all attributes via OData.

In Microsoft documentation we found this endpoint:

api.businesscentral.dynamics.com/v1.0[our tenant id]/Sandbox/ODataV4/Company('CRONUS%20DE')/items

But unfortunately, the response does not contain item attributes and values, such as Farbe, Tiefe, etc.

Next, we tried to add new Web Services. But some of this endpoints return empty values and some of them (7506, 7507, 7508, 7510) don't work and return:

No HTTP resource was found that matches the request URI

Web Services

Objects 7500, 7501, 7503 contain information about attributes. But non of them (7500 - 7510) does not contain a relation between Item, Attributes, and Values.

Maybe there is another way to get items with their attribute values? We also tried to research microsoft graph but not successful.

Nikolaev
  • 96
  • 7

2 Answers2

3

i am having similar troubles with this. i find the dynamics api to be exceptionally unintuitive and difficult to use. the furthest i have been able to get has been to go into the api settings for dynamics and uncover the tables for a few item attributes (i believe that the table numbers are as those below:

  • 7500 - Item Attribute
  • 7501 - Item Attribute Value
  • 7502 - Item Attribute Translation
  • 7504 - Item Attribute Value Selection
  • 7505 - Item Attribute Value Mapping

i cannot comment on why 7503 is missing.

using 7500 as an example, when you uncover the table, the system provides a resulting endpoint (unfortunately, they always promote OData, and the outdated SOAP resource; i can't figure out why they have such a vendetta against the simple and easy-to-use REST endpoint).

https://api.businesscentral.dynamics.com/v2.0/<TENANT_ID>/<ENVIRONMENT_NAME>/ODataV4/Company('COMPANY_IDENTIFIER')/ItemAttributes

using this endpoint, you can get a listing of the attribute types themselves (e.g. let's say you've defined an attribute called 'BaseColor', you should get a result here for the name of the attribute 'BaseColor', its ID, its type, etc.),

with the ItemAttributeValues endpoint, you should get the actual attribute values that are in existence (e.g. for some item, you happened to set its 'BaseColor' attribute to 'Blue', you should get a response for this attribute value with a attribute type of 'BaseColor', a value, as 'Blue' along with the entity's ID, etc).

yet, when it comes to any instantiated attribute values for items, i can't figure out how to get the association of the attributes with those items. i expect that the "item attribute value mapping" option would be something along the lines of a item_id - attribute_id pair so that for any item in question, one could query the attributes list with something like a filter. but as you said, upon uncovering some of these elements, their respective endpoints return nothing. you get to the point where you say 'OH...AWSOME! there is a value-item mapping. that makes sense, and i can definitely use that'. a few moments later, the API spits in your face with an error, or craps on you by returning something you don't expect like an empty data set.

this api is a constant uphill battle, and totally riddled with landmines. a complete blow-me-up-pain-in-the-arse.

EDIT: 2021-06-09

i've looked into this some more. i was able to set up an export package for the various tables in question, specifically 7500, 7501, and 7505. the magical table was 7505 as it is the relationship between an attribute value and the item with which it is associated. exporting the package to excel results in good data. yet, when trying to expose this information in the OData resource, something strange happens:

  1. in web services, i try to open up page 7505 which populates the object name as ItemAttributeValueMapping and i set the service name to 'ItemAttributeValueMapping'. This is normal.

Item Attribute Value Mapping

  1. the system complains when i fail to specify that the object type is a page. so, i go back in the line and set the selection to "Page"

  2. when i tab through to publish the change, the object name automatically changes to 'ItemAttributeValueTranslations'.

Item Attribute Value Translations

EDIT: 2021-06-15

After a lot of fiddling about, i finally reached a point where i decided that the only way to address this was to write an al query which would expose the appropriate value-item mapping information. there is a page which provides some source code for doing this:

github AL-Code-Samples

to get something out of the API, i had to use microsoft visual studio code. there are a few good videos on how to get this up and running to get a test app working for your business central instance (i used eric hougaar's videos: Getting started with Business Central AL Development).

when you have set up your app to connect to your instance by inserting your tenant and entering your credentials, you can modify the source code as below to create a query in your system.

query 50102 "<YOUR_QUERY_NAME>"
{

    QueryType = API;
    APIPublisher = '<YOUR_NAME>';
    APIGroup = '<YOUR_APP_GROUP>';
    APIVersion = 'v1.0';
    Caption = '<YOUR CAPTION>';
    EntityName = '<YOUR_QUERY_NAME>';
    EntitySetName = '<YOUR_API_ENDPOINT_NAME>';
    elements
    {
        dataitem(Item; Item)
        {
            column(No_; "No.")
            {
            }
            column(Description; Description)
            {
            }

            column(Unit_Cost; "Unit Cost")
            {
            }

            dataitem(Item_Attribute_Value_Mapping; "Item Attribute Value Mapping")
            {
                DataItemLink = "No." = Item."No.";

                column(Item_Attribute_ID; "Item Attribute ID")
                {
                }

                column(Item_Attribute_Value_ID; "Item Attribute Value ID")
                {
                }
                dataitem(QueryElement6; "Item Attribute")
                {
                    DataItemLink = ID = Item_Attribute_Value_Mapping."Item Attribute ID";
                    column(Name; Name)
                    {
                    }
                    dataItem(Queryelement10; "Item Attribute Value")
                    {
                        DataItemLink = "Attribute ID" = Item_Attribute_Value_Mapping."Item Attribute ID",
                        ID = Item_Attribute_Value_Mapping."Item Attribute Value ID";
                        column(Value; Value)
                        {
                        }
                        column(Numeric_Value; "Numeric Value")
                        {
                        }
                    }
                }
            }

        }
    }
}

once this code gets successfully uploaded to your server and returning a page (you have to wait for it), you can then use specified query number to expose the data in the API by going to business central's "web services" and adding a 'Query' to item 50102 (or whatever number you use). the endpoint will automatically be populated and you can use it to send you back the necessary JSON which will show a product, with its attribute values.

hope that helps.

panagioti
  • 426
  • 4
  • 14
  • **Note to reviewers:** From [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer): “Still no answer to the question, and you have the same problem? Help us find a solution by researching the problem, then contribute the results of your research and anything additional you’ve tried as a partial answer. That way, even if we can’t figure it out, the next person has more to go on.” – Jeremy Caney Jun 08 '21 at 16:08
-2

You should try with below endpoint:

/v2.0/tenant_id/enviornment_name/ODataV4/Company(company_id)/Items
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Sonal
  • 7
  • 1
  • Citing the fact that the word "items" needs to be capitalized in no way helps resolve the problem at hand, namely, how to extract item attributes. – panagioti Jun 08 '21 at 15:22