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 6 - Create a new Northbreeze category

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!)

You've made various read-only requests so far; now it's time to create some data.

Background

For this task we return briefly to the Northbreeze service from Task 2. Until now, mostly due to the nature of the deliberate simplicity of the tasks in this Developer Challenge, the actions you've been performing from an HTTP perspective have been read-only.

This time you'll write some data, albeit data that won't last long (the Northbreeze service runs in-memory and has been set up not to use a permanent persistence layer). Then you'll read it back, with a minor difference, to examine what the response looks like. It's that response, compressed, that you'll need for the hash.

The Northwind service traditionally has products, which you've encountered already. Those products are organized into categories, of which there are just a few. A category (taking the first one) looks like this:

{
  "CategoryID": 1,
  "CategoryName": "Beverages",
  "Description": "Soft drinks, coffees, teas, beers, and ales"
}

You can get a feel for the distribution of products across categories by asking for the count of products by category ID which is expressed like this (showing the path, with whitespace, for easier reading):

/odata/v4/northbreeze/Products
  ?$apply=groupby(
    (Category_CategoryID),
    aggregate($count as productcount)
  )

This returns a response that looks like this:

{
  "@odata.context": "$metadata#Products(Category_CategoryID,productcount)",
  "value": [
    {
      "productcount@odata.type": "#Decimal",
      "productcount": 12,
      "Category_CategoryID": 1,
      "@odata.id": null
    },
    {
      "productcount@odata.type": "#Decimal",
      "productcount": 12,
      "Category_CategoryID": 2,
      "@odata.id": null
    },
    {
      "productcount@odata.type": "#Decimal",
      "productcount": 13,
      "Category_CategoryID": 3,
      "@odata.id": null
    },
    {
      "productcount@odata.type": "#Decimal",
      "productcount": 10,
      "Category_CategoryID": 4,
      "@odata.id": null
    },
    {
      "productcount@odata.type": "#Decimal",
      "productcount": 7,
      "Category_CategoryID": 5,
      "@odata.id": null
    },
    {
      "productcount@odata.type": "#Decimal",
      "productcount": 6,
      "Category_CategoryID": 6,
      "@odata.id": null
    },
    {
      "productcount@odata.type": "#Decimal",
      "productcount": 5,
      "Category_CategoryID": 7,
      "@odata.id": null
    },
    {
      "productcount@odata.type": "#Decimal",
      "productcount": 12,
      "Category_CategoryID": 8,
      "@odata.id": null
    }
  ]}

As you can see, the OData V4 aggregate facilities, and CAP's support for them, is pretty neat!

Your task

Your task is to create a new category, and then request it. In other words, you must contruct an appropriate HTTP request to form an OData CREATE operation, to add a new category entity into the entity set. You can see from above that a category has just three properties:

  • CategoryID - this is the key and must be an integer value
  • CategoryName - a short name for the category
  • Description - a brief summary of what the category is

You must supply the following values for these properties when creating your new category:

  • CategoryID - your SAP Community ID number (see the Hints and tips section)
  • CategoryName - your SAP Community ID in lower case
  • Description - the static text August Developer Challenge

You can tell that the CategoryID property must be a number, because of how it's defined in the OData service's metadata document.

Once you've created your new category, you must then construct an appropriate HTTP request to form an OData READ operation to request a representation of your category. There are some important points here:

  • you must use an OData READ operation and not an OData QUERY operation
  • you must exclude the Description property, i.e. you should request (and expect) only the category properties CategoryID and CategoryName
  • the representation of the response must be in JSON

The representation of the response is the value you need to hash and share as a new reply to this discussion thread, as always, and as described in Task 0. Note that you'll have to URL encode the entire value, as you will be sending it within the value=('...') part of the hash service URL.

You should ensure that the order of the properties in the JSON object structure returned is sorted (it should already be, but double check or just add that processing to whatever mechanism you build to do this) and that there is no extraneous whitespace in the structure at all.

Here's an example of what a response representation will look like - note the single line and no whitespace, and that the CategoryName value is all lower case:

{"@odata.context":"some-context-specification","CategoryID":53,"CategoryName":"qmacro"}

Hints and tips

You already know about your SAP Community ID. For example, qmacro is the SAP Community ID for DJ Adams. To get your SAP Community ID number, which is unique, just go to your profile page, and get the number from your profile page's URL. For example, the profile page for DJ Adams is at https://groups.community.sap.com/t5/user/viewprofilepage/user-id/53 and looks like this:

qmacro-profile-page.png

You can see the SAP Community ID number in the URL - it's 53. Go to your profile page and get the number from the resulting URL for your profile.

What about the OData READ vs OData QUERY operation question? Both use the same HTTP method (GET) but the structure of the data returned is different. Given that the data and its structure is what you need to ensure is correct before hashing it, it's important you think about how you would request that single new category.

For discussion

What is the definition of the CategoryID property, according to the metadata document?

What is the difference between the result of an OData QUERY operation and the result of an OData READ operation? How does this relate to OData's origins? What is the significant difference in data structure returned?

Did you try to request a different representation of your category, such as XML? What happened?

96 REPLIES 96

AAncos
Explorer
0 Kudos

c5f5504c0d1c8b3282b71be70afe4a4d43637f146e82e2ef92280f13d77fc648

abdullahgunes
Participant
0 Kudos
4a882bb5995fecb7c4b6528fabe88cc1d7e03827eeb368533a955eea02b23b1a

SyambabuAllu
Contributor
0 Kudos

e9bc07b54baae3512d8c6100d10819886cbe77407d18d4450e7f2492e9fe123f

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos

e4401804523f281da3ca44e6bc82ce3bddb879ccbdf385b42722244de2235a23




--------------
See all my blogs and connect with me on Twitter / LinkedIn

Ruthiel
Product and Topic Expert
Product and Topic Expert
0 Kudos

698275aba46394a0bf9ec5823227c9fde1dcb8a462ff6f3c6d29d84fb6f89e97

MioYasuatke
Active Contributor
0 Kudos

876ec7b4967a84398c8038e042da481bf73e183d9845d6ad1183fceecdc83426

martinstenzig
Contributor
0 Kudos

8fc2227832fe0a826ed7af64635b7c33f0ea5baec41adc8dea38732068a923dd

ecem_yalim
Explorer
0 Kudos

71bc643451f8980991d0a138577b54e94ebb0249396e552461357b664ce916d4

IsmailFatih
Explorer
0 Kudos

069159b9c4fc5856266e3cd3cfe601cb79414baefe8442fd31ba4734bda25922

UweFetzer_se38
Active Contributor
0 Kudos

23de644c6b2c8e81c3e276449ca39cf52cd37656d23e90668b227cef42920cd3

Ritik
Participant
0 Kudos

c18ba4524c51db082295e8c4490427fdcdb8d1ca4f6bb7541c0885170e77f6da

ajos
Explorer
0 Kudos

a3da15d8f827fa5610aa6f2d14d98eb68318b14c85754a120368346123db969d

vinaychowdary
Explorer
0 Kudos

973207150d4f3ebb941efb5e07e4b05a02d6a23242020c651a20b1fb5d3ad393

emiliocampo
Explorer
0 Kudos

86906ff650ffcb00208a0e240d0595b74e7591eba97c2ffbaeb5d0839fe791c9

dhegde
Participant
0 Kudos

17f206f1a4d1b5fd9a136fbb7debd026672d202cfaaccc1ef75f9d24a8474809

nmkarthikeya
Active Participant
0 Kudos

59a87be3e6159e1a9526a5b486dbf6ef63ab4b2e75d41803d527928dfd63f4fe

tly
Explorer
0 Kudos

cf213bd55b585509148b02f4979369142e4144a1a8cfb20c915f2cd1bac6adfd

Dan_Wroblewski
Developer Advocate
Developer Advocate

Again, foiled by a space here, a line feed there. When URL encoding (manually) I didn't realize I was adding line feeds 🤦‍♂️

What's great about the challenge, is all the small things you learn not directly related to the core of the challenge (which already teaches a lot)




--------------
See all my blogs and connect with me on Twitter / LinkedIn

0 Kudos

The minutiae of any task are just as, if not more interesting than the task itself. Delight in them, and enjoy them!

govardhansahil
Explorer
0 Kudos

1e49e24dd48cd349c11b7ba7eec537ffee3d4631bc6681222f3b80c421db49de

MarcelloUrbani
Active Contributor
0 Kudos

03ae6533023e6f4fe983eeb2e19219af4369615cda7edb51baf260e5455aa5c1

flo_conrad
Explorer
0 Kudos

eeb2c593609307065bbd39d0a24474c16f9ecc7959f443ec18a2fbedf119161f

geek
Explorer
0 Kudos

5febee14dda72255f5b2b077055b279c7150b845d842d9817b604ea6b5b730cb

turanaydin
Explorer
0 Kudos

559dfd73ef1f97afcda16d110506e40803b207ca908f9af9962fa3c1f496c9ed

cguttikonda24
Participant
0 Kudos

b7489c931ec5a8aa8c248a5e8c88e15cc7229b8b046004504d04d93a9330632e

cdias
Product and Topic Expert
Product and Topic Expert
0 Kudos

2bdff96f5fb7ead2df373dba9fd027b39b593d888b48a26083547f802ed90dde

Ashok459
Participant
0 Kudos

ce3e2e15516d28dbed570b031dd6847ab1565d0cc4c1e4814a8cbc1d95225522

salilmehta01
Associate
Associate
0 Kudos

66c2fe3127e4b485075a8c3e1fe215f670cab2a7348f71a3673d6de12a5fcf2f

Nicolas
Active Contributor
0 Kudos

22056edad72d415b2f0e6a4f3ffbba0ec73bb090fbde6a1daba99a737ea8db5e

encarrero
Participant
0 Kudos

bb686a80f644518017066dcc7e74ee73e754c4441b3c0b0dc5f07d71baf020d7

garyzuo
Explorer
0 Kudos

f58aee61b87b4f2f2efb68e6ba62884e18adad9279f3dba87335e65762759a93

sabarna17
Contributor
0 Kudos

bbf061be061590fcc3a897227f8acba486198f54e9aadbf4985be1e23d2cdf16

tobiasz_h
Active Participant
0 Kudos

47009ed6248a68d8f23f9d5482c857b39c440296366fd5d203f8cea6533d47e6

hunamm
Explorer
0 Kudos

0b0d0e180c238c35d91bcd890fda3563eef79cc4ffa5fcb391f03ead8a06fc6b

Frank_Haschick
Explorer
0 Kudos

a93f12972fbd8278e9dc5da87ec2b8ab05df9f502f2acf331e41401d662e49bb

Cmdd
Participant
0 Kudos

b6bc5bf329238ee7eb0f18515d63862eaa89549129bac2c0e97ec8c48cb8f35d

yassine
Explorer
0 Kudos

cd05f20ce1b55ee505153ba253703ff44b6227c9b34f13c587bc434daea233b6

former_member136915
Product and Topic Expert
Product and Topic Expert
0 Kudos
14198844b45cfc7850946e273e278dbe3b7d368ea6e9ce646db6b9f7423cee57

bugsanderrrors
Participant
0 Kudos

ea87ef57c1260fd0949fe2a91d27fa2fe0a43e2708dc622a32bf2eea00e44c5b

satya-dev
Participant
0 Kudos

d09c459fc098b2d86c22c2c89a36465de0a19107a551b70810382919fea0cdc4