cancel
Showing results for 
Search instead for 
Did you mean: 

[SAP MDK] Displaying Sub-Properties in Object Table Fields from a REST API Call/Response

Khaled_Elghali
Participant
0 Kudos

Hello MDK SAP Community,

I am seeking assistance with displaying the sub-properties of a REST API response within the fields of an Object Table, within e.g. the "Title" and "Subhead" fields.

I am working with the following API endpoint: https://dummyjson.com/products
The JSON response I am receiving is structured as follows:

 

{ "products": [ { "id": 7, "title": "Samsung Galaxy Book", "description": "Samsung Galaxy Book S (2020) Laptop With Intel Lakefield Chip, 8GB of RAM Launched", "price": 1499, "discountPercentage": 4.15, "rating": 4.25 }, { "id": 8, "title": "Microsoft Surface Laptop 4", "description": "Style and speed. Stand out on HD video calls backed by Studio Mics. Capture ideas on the vibrant touchscreen.", "price": 1499, "discountPercentage": 10.23, "rating": 4.43 }, // Additional product objects... ] }

 

My goal is to extract e.g. the "id" and "title" properties from each product and display them in the "Title" and "Subhead" fields (just as example), respectively, of an Object Table.

I have attempted the following bindings, but none have worked:

  • "Title": {id}, "Subhead": {title}
  • "Title": {products.id}, "Subhead": {products.title}
  • "Title": {products[].id}, "Subhead": {products[].title}
  • "Title": {products/id}, "Subhead": {products/title}

I can confirm that the API call is successful, as I am receiving a 200 OK status along with the expected response data.
For single product calls such as "https://dummyjson.com/products/1", the mapping of "Title": {id} and "Subhead": {title} works well. However, the issue presents itself when attempting to list multiple products.

Could someone please guide me on the correct way to bind these (sub)properties within an Object Table for a list of products?

Thank you for your time and assistance.
Khaled El Ghali

Accepted Solutions (1)

Accepted Solutions (1)

bill_froelich
Product and Topic Expert
Product and Topic Expert

The binding is based on the structure of the return JSON.  In the example you gave, the properties are all just top level properties on the product object so you can just bind to the property name.

"ObjectCell": {
	"Title": "{title}",
	"Subhead": "{category}",
	"Footnote": "{brand}",
	"DisplayDescriptionInMobile": true,
	"StatusText": "{price}",
	"PreserveIconStackSpacing": false,
	"AccessoryType": "None"
}

When using a REST service, it is important to understand both the path for the service endpoint as well as the output path.  Depending on how you defined the URL for the destination you may or may not need a path.  For the output path, in this case for an Object Table it is expecting an array of objects.  For the products call the response includes the array under the products property so the output path needs to be set to /products.

Here is how I defined my target for the object table to display the products list.  Note: I use a path as well because my destination in Mobile Services is set to just the root https://dummyjson.com

"Target": {
	"Service": "/SCN_00027/Services/DummyJSON.service",
	"Path": "/products",
	"OutputPath": "/products",
	"RequestProperties": {
		"Method": "GET"
	}
}

My guess is your Target does not include the output path so the object table does not know where the array is to render.

Khaled_Elghali
Participant
0 Kudos

Hi @bill_froelich ,
your solution worked perfectly for the issue I was facing.
Thank you so much for your support and for being part of the SAP Community! Best regards,
Khaled

Answers (0)