Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Developer Challenge - APIs - Task 1 - List the Northwind entity sets

qmacro
Developer Advocate
Developer Advocate

(Check out the SAP Developer Challenge - APIs blog post for everything you need to know about the challenge to which this task relates!)

In this task you'll become acquainted with entity sets in the classic Northwind service.

Background

You may have heard of, or even interacted with an instance of, the Northwind model and service, originally and properly called "Northwind Traders". It has a classic and well-known set of related entities and is often a first introduction for many to database schemas, OData services and more. It was originally shipped with the Microsoft Access database application.

The entities and their relationships are easy to understand and it's partly for this reason that it's so popular. In this task, you will briefly explore the Northwind service offered by OASIS Open, the non-profit standards body, where there's a working group that looks after the Open Data Protocol (OData) standard.

There are various services available at the simple landing page at https://services.odata.org and the one we will use is the OData V4 version, which is available directly at this address:

https://services.odata.org/V4/Northwind/Northwind.svc/

Your task

Your task specifically is to list the entity sets available in this service. They should be presented as a single string, following these rules:

  • the entity set names should be exactly as specified in the service
  • you should keep whatever case the entity set names are written in
  • the entity sets should be listed in alphabetical order
  • they should be comma-separated, with no spaces

Here's a short example of what a list should look like:

Categories,Customers,Suppliers

There are more entity sets than just these three, this is just an example.

Once you have constructed the list, you should hash it and post the hash as a new reply to this discussion thread, as described in Task 0 - Learn to share your task results. This means that to get the hash, you would need to make a call to the hash service like this (based again on the above short example), supplying your SAP Community ID in the appropriate header too:

https://developer-challenge.cfapps.eu10.hana.ondemand.com/v1/hash(value='Categories,Customers,Suppliers')

Hints and tips

What is an entity set? It is essentially a collection (a set) of entities. There are two places where an OData service typically details the entity sets on offer. One is the service document, available at the root of the service's base URL. And the other is the metadata document, available at the service's base URL with $metadata appended. Metadata documents contain a wealth of information for an OData service; the entity set details are included, but there's a lot of other information that is included too, information that you must exclude or otherwise ignore. Simpler perhaps would be to take the service document, which has a set of collections (this harks back to the origins of OData, incidentally) which more or less equate to entity sets.

If you request the service document (https://services.odata.org/V4/Northwind/Northwind.svc/) in your browser, you get an XML based representation in response. You can parse this XML with any XML library, or command line tool (such as xmlstarlet or xmllint.

While the service document's XML structure is much simpler than the metadata document, it's still XML, and it's arguably easier these days to avoid XML altogether when doing ad-hoc parsing activities. With OData V2 services, the service document is only available in an XML representation. It's also available in a JSON representation with OData V4 services.

Using a command line HTTP client, for example, to request the service document, we get an entirely different representation.

For example, this invocation of curl:

curl \
  --url "https://services.odata.org/V4/Northwind/Northwind.svc/"

returns a JSON representation, that looks like this (redacted for brevity):

{
  "@odata.context": "https://services.odata.org/V4/Northwind/Northwind.svc/$metadata",
  "value": [
    {
      "name": "Categories",
      "kind": "EntitySet",
      "url": "Categories"
    },
    {
      "name": "CustomerDemographics",
      "kind": "EntitySet",
      "url": "CustomerDemographics"
    },
    {
      "name": "Customers",
      "kind": "EntitySet",
      "url": "Customers"
    },
    {
      "name": "Employees",
      "kind": "EntitySet",
      "url": "Employees"
    },
    {
      "name": "Order_Details",
      "kind": "EntitySet",
      "url": "Order_Details"
    }
  ]
}

In case you're interested, the shell pipeline to produce this redacted representation was:

curl \
  --silent \
  --url "https://services.odata.org/V4/Northwind/Northwind.svc/" \
  | jq '.value|=.[:5]'

Once you have a JSON representation of the service document, you can use your favorite language (JavaScript, TypeScript, Python, ABAP, or perhaps jq) to parse out the entity set names, and form them, in alphabetical order, into the comma-separated list that you need.

Of course, if you prefer to parse the XML representation of the service document, then by all means do that.

For discussion

We get different representations of the service document resource, depending on where we make the request. In the browser, the representation comes back in XML form. Using curl on the command line, the representation is in JSON form. Why do you think that is?

225 REPLIES 225

kjyothiraditya
Participant
0 Kudos
019dbc76fb09f1e397d68b9cbd5f882469e58e5e9878e709671a5f23c6acb11e

 

spassaro
Participant
0 Kudos

355d88680602db8392c8eaf0e97504617c66c735f64d04e52d281dafafbf6ba2

 

qmacro
Developer Advocate
Developer Advocate

Excellent work, thanks @spassaro . But double check the hash reply posting instructions - your current hash reply is invalid 😉

0 Kudos

In my case, I used Postman API test capabilities to chain the 2 requests. If you're interested in the script I used in the "Test" tab:

 

 

// Get the request 
const response = pm.response.json()
 
// sort in alphabetical order and save it into a string
const entities = response.value.map(value => value.name)
entities.sort((a,b) => a.localeCompare(b))
//save into a postman variable to use it in the subsequent request.
pm.environment.set("entities", entities.toString())

 

qmacro
Developer Advocate
Developer Advocate
0 Kudos

Excellent, thanks for sharing @spassaro !

yassine
Explorer
0 Kudos

492eef8cec68a5108046ca66fb0bfec91504a8243d29af9ce8d4b83026330e76

satya-dev
Participant
0 Kudos

c1289f5093947bdab9cf98b53d559da6a8cb5b1228102838006b24784a924119

ManojSutar
Explorer
0 Kudos

99b169fe2020e1121b78df9cd417eca29516ca40abfa03e2af6d0f7f1c6f812a

Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert
0 Kudos

5cb0f62cca58bd2e6b2b86ecb68ccd8c7bef26d0c59f3f6466c2ac0f5b2262a8

Regards, Jitendra

akshaychats129
Discoverer
0 Kudos

bb0da4edd74f4133f6534c370faa26a9c90bd278bd031ed6a872b5cbbc5b8c99

sabarna17
Contributor
0 Kudos

71247bbb168f2a7048e8e854539cf1804221c967d08249471a898f0c04708a5e

garyzuo
Explorer
0 Kudos

51777c55c8527c718b155cd89b1d0168a148b4557e5602c2f13ec57985d3ba6c

mustafabilen
Explorer
0 Kudos

aa20e15d204b3a823c35124fdd286cadfa2ebf36153df9160fb3b25d3ef87479

szeteng00
Explorer
0 Kudos

dbfe23b11b020efcc948f152e41613d4fd90d0d3337232362c289feaa3a5eb88

Suneeth_P
Participant
0 Kudos

390d36125547ab574e09508f9782de27f7126d0c934ac5650aeb7b9857dda92c

hunamm
Explorer
0 Kudos

cb8da124633deb9458dbd9fd7953887d7ac8a141e0f7c2bc4ea911a2758b4d37

d067595
Product and Topic Expert
Product and Topic Expert
0 Kudos

722c0d5db522fb1303fe815f96ec95338228907b7f294216f0ae3556ede54379

MarcelloUrbani
Active Contributor
0 Kudos

0d60d62ddaf1196084e22fd44ec8eef82f165150800eb6882e664096c87cd58a

arunneerolil
Contributor
0 Kudos

e4e4548658a89c3310c7a03f6aeee3191d1d6064ff69f095bd1e4b69bc3e911d

IngoS
Discoverer
0 Kudos

53f8c4b46b4afc99196bcf2f58503764a13f3af9828902c15cbe4aab242f104d

DazOwens
Explorer
0 Kudos

593ad02ddd69675ebb6cfb32f3064300dd6358eee6b03a41c3191c84a8585508

ramana_salapu
Explorer
0 Kudos

78cb358254871a75a5f87495537646f39c36c3fe187c9108ba44317eac50a18a

ofilho
Discoverer
0 Kudos

1222cc47f33ba3414a14a7431b57c4981ab29f3e5a2f82eba5654c3b71b7fe15

cinemandre
Advisor
Advisor
0 Kudos

20d16d91fd4979f0eb5f163535b96ad77e6f1a686e2b9da02acf7ff9a8467298

tly
Explorer
0 Kudos

5767e6efffecb05dc57493142b23a2b458cf2d61967e9cb389d9ef887d0bd88c

jmuiruri
Product and Topic Expert
Product and Topic Expert
0 Kudos

acfc590aa2c7c0c6290021aaa738b51c9593e205cddb6e98235c6559d0018b85

ktrkanjec
Discoverer
0 Kudos

2a710a7ff08997c80adaf0376c6bf2d07d68573c838df423a0d6b8dc7f2448e7

Nicolas
Active Contributor
0 Kudos

6dcf2a55f7b5495cefcef8c510cd5fc8dfa9c8db0b1f83c465a09e56256bde7c

lvhengel
Participant
0 Kudos

67e8ec0ae564e775837362c68181114dfd67e12b5a9e067037629fcfa665d409

VinitaSangtani
Discoverer
0 Kudos

99d007dd904ed4fc3912d8f829c4ca7d538bb85439c20990ddd1c83bd207796c

SubaR
Explorer
0 Kudos

5505705738ce3393481556b754f645210e8aca8183876077130f02c5ebb65382

ec1
Active Participant
0 Kudos

859f6f293f2f1d11d25a96e5c34af04e2e8ca4c7fb96df3de59d6301185ea8bd

Sudhakaran
Participant
0 Kudos

4ba40592de0cffdd83b8da9043f92b1ecde98c0d886b3a2a4bbbafd8c574e8aa

salilmehta01
Associate
Associate
0 Kudos
e48bfbfa3e1db18231ad7b01d69bab8d54468e61453821b0813566df74907b55

RafkeMagic
Active Contributor
0 Kudos

ff5314db455861db208894db0f307024afe7514fdf2bfdc1aa7366f7fc04d5bf

Hendrik
Active Participant
0 Kudos

0d1a5ddc44c6758100de00fa9f471dde25bce445f529c7857f8afa937afe369a

johna69
Product and Topic Expert
Product and Topic Expert
0 Kudos

8606447abd00847a15e44c01177a788547174eb1ab8f3bd96b10eab669d9d5e5

ArindamSAP
Discoverer
0 Kudos

6c6f9499c10f8a4ae0af18dbb9fb265dcc738004857f310d3a134b1ffb3062af

former_member136915
Product and Topic Expert
Product and Topic Expert
0 Kudos
330dc0818ad402bde74b838045e591829ebca9789e457c109a91e44c2a78850e

lehuynhnam
Explorer
0 Kudos

7ceb194d90971a90d29fd47c270eb771f23a82f264c5e09716f62c02b356d8a9