Application Development and Automation 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: 
Read only

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

qmacro
Developer Advocate
Developer Advocate
43,243

(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?

226 REPLIES 226
Read only

vladimirs_semikins
SAP Champion
SAP Champion
0 Kudos
5,021

f3fbce750818b84d9595a2eef535bf017ccface0aa38ef370ccae98055f7382e

Read only

jmalappil
Discoverer
0 Kudos
5,238

1afde706c8f90d56c8ff5ae72af8794236886533441d8df2ffbbac99e2e3953d

Read only

FooThePolarBear
Explorer
0 Kudos
5,240

b12bad433d632b543bcb14e3697ecab0db1f8203c4a61cf9477528f3923ef69e

Read only

govardhansahil
Explorer
0 Kudos
5,242

a2df1dae156cdc73578119ab62e2064b5441a12b21ee35b2832ace98a0408dd8

Read only

nicoschoenteich
Developer Advocate
Developer Advocate
0 Kudos
5,236

4a2d585a87a797f36e2b503b42079a9472a5a0822196e1652724dd0436422ec4

Read only

Frank_Haschick
Explorer
0 Kudos
5,244

b800d136853441539994a030546a6c7593e969b62707b1f6c0f7aea5f7ff8a1f

Read only

5,242

done with ABAP and nearly forgot the sorting ... glad there are people already posting their hashes so I could check mine 😄

In ABAP, you can use if_http_client to make the actual call and /ui2/cl_json=>deserialize to get the odata-call result (with ?$format=json) from JSON to a nice abap structure.

Read only

5,218

Using ABAP with IF_HTTP_CLIENT? Excellent! The Internet Communication Framework is still one of my all time favourite technical accomplishments in the SAP tech area. So much so that I used to give a two-day course on it.

The slide content, in case folks are interested, is freely available (this link goes to the specific slide where I start to cover IF_HTTP_CLIENT). 

Web Programming with the SAP Internet Communication Framework

Of course, some of the content may be a bit out of date (I created the course in 2012) but the principles and certainly a lot of the details remain.

Share & enjoy!

screenshot 2023-08-07 at 12.28.46.png

Read only

5,220

Also, I was wondering if anyone would check their replies against others, via hash comparison. Nice one 😉

Read only

5,210

Did the same. That's why I asked whether to insert just the number or something else, because the one or other hash here doesn't fit to my answer.

Read only

qmacro
Developer Advocate
Developer Advocate
5,239

🚨 Greetings! We're currently running at just over half of you getting the correct result. Which means quite a few of you may want to check the details in the "Your task" section, and double check the mechanisms you employed. Good luck, have fun, and keep going! 🚀

Read only

Monni
Discoverer
0 Kudos
5,205

48bca549136e7aefdf33cbefb2c79ff1500f3e9ebbc0114f61fd959ea90cfa97

Read only

stephancalmindo
Explorer
0 Kudos
5,186

3396cec8e94c6fcab6a9d5d3392030e99d7f1e18b5241265ef2e28b5d5534ae7

Read only

thomas_jung
Developer Advocate
Developer Advocate
5,182

7cbbece7d74413b8223f53b798e390c25ccb986034f9fefed1513c299d7cbe33

Read only

huseyindereli
Active Contributor
0 Kudos
5,181

6290a6dd396979188586591c5f29401497482f008517ee13d50ea7fe130c1138

Read only

JohnPaulLiberal
Explorer
0 Kudos
5,180

46afe1f04d1abe3e1ad37044c81a871843cce068de9400b82ca21b024bb1fba3

Read only

raulguti
Discoverer
0 Kudos
5,174

3498399522212e94a84a85d95207dc251101018ce3b02d77ba83e5ddc9340a5e

Read only

dvontress
Explorer
0 Kudos
5,170

929c96040d5672fd8f47e3d97417d0e112fa2785a0adb3ed38caab775ab9b654

Read only

erickgrilo
Explorer
0 Kudos
5,171

d725b35810e82774e2e5b2a1397837cf093c4442ce7cf1661baa8a10de4cd661

BTW, i'm really liking these challenges as I am forcing myself to use some tools i haven't used for some years (e.g., Task 0 and 1 i used Java to make the call to the hash and process the JSON received from the entities), as in the last years i've been using mainly Python, JS and ABAP. This is good to refresh many things apart from API itself! thanks a lot.

Read only

qmacro
Developer Advocate
Developer Advocate
0 Kudos
4,834

Great stuff @erickgrilo ... But double check the hash reply posting instructions - your current hash reply is invalid 😉

Read only

Gus-Alvarez
Explorer
0 Kudos
5,173

0c254c7e3399e5cdf528b8568ff75313dd2f825c2dbface8f17d95e610d4b076

Read only

Petchimuthu_M
Associate
Associate
0 Kudos
5,176

c2ac76a5b4c18a095a50827a2a7a158cf11868f46160062657b21aa42ac30a55

Read only

nilsb
Explorer
0 Kudos
5,174

41c2be0238c91f5e9f42295db430b97b370655ff05ae1893fbc52e01c726e576

Read only

ecem_yalim
Explorer
0 Kudos
5,152

d07aedc5da1799677d561ed50f7181ef5b513b0aa226d2960baf6b4a19c5ebdd

Read only

IsmailFatih
Explorer
0 Kudos
5,151

ba22ea182c2e0a82a3dd005036bbf0f171d2396d92c588709815e5fe1836b679

Read only

Cylia_Oulebsir
Participant
0 Kudos
5,086

66e2ecef202af3289453556dc093c43f45fba6e6f058700d6c50a3548f6c07c0

Read only

abdullahgunes
Participant
0 Kudos
5,081

0a1e212f1d1a6b34a4896cfe0bb782d3b639e48f94d917bd2233af1bb2030396

Read only

dianab
Explorer
0 Kudos
5,079

62086f6a2d23ea791c946a59b768fb04b443e96143a6e1adc6aa59c0bccd8211

Read only

ajay_soreng
Developer Advocate
Developer Advocate
0 Kudos
5,076

234d94f61fd06f6368227b28dc78bf59c43381a9a9c0d08cc63d18df57fb7797

Read only

geek61
Participant
0 Kudos
5,073

ff03701c64c1b23e2aa4443dd32655933ed96696001bf1bfd32bf331a21415f6

Read only

ADR
Participant
0 Kudos
5,074

54dfd9f8b8129bae6c9c9efc7a5ec069be77affb1dd516a5a49610764642102f

Read only

mts2605_orsted
Explorer
0 Kudos
5,077

b2233e159f2464ea7f1b2cf73f587daa12a9960e7f62e262b95f7619d3749a93

Read only

geek61
Participant
0 Kudos
5,079

8f31280afb68bce263fd8c8ef1679d2807dbccee3a46b34c3658214f3e3ae38b

Read only

0 Kudos
4,885

Is this wrong or is there a bot that should be marking our homework and is broken?

Read only

qmacro
Developer Advocate
Developer Advocate
0 Kudos
4,833

Hey @geek61 I think you probably know the answer to this now already, but yes - there are scripts we have behind the scenes, and we'll reveal how you've all done towards the end of the month 👍

Read only

Sharadha1
Active Contributor
0 Kudos
5,081

cad3105868df73160a1aa94df2305a3035f12a99accc8a0414fd51d318d51fe9

Read only

Ritik
Product and Topic Expert
Product and Topic Expert
0 Kudos
5,080

7c3ccbdfc960e38987335c0b6b838227df93aeddad69f0cb1d05967e31683b1d

Read only

barisguler
Participant
0 Kudos
5,064
2c11dc4d222cbdc7238cd529689c9d1a73932183b64d05bc5015af45c630477b
Read only

SebastianSchuck
Active Participant
0 Kudos
5,059

660519438a522ce03a17bc646af7f27a8580c9c525a0ea9e009429e1117e8518

Read only

R4BB1T
Participant
0 Kudos
5,055

bea3daeb43e38f104ba43073d5b8d9d768df70b0a60b793094b674e581d243e3