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 5 - Call the country date format API endpoint

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

Now you're familiar with the Date and Time API, you are in a position to try out one of the endpoints.

Background

For many APIs on the SAP Business Accelerator Hub there are options to "try out" the endpoints. You can define your own environment that you can then use to connect to from the hub:

add-new-environment.png

There's also a sandbox environment that's available for some of the API packages too, and this Date and Time API is one that is available in this sandbox environment.

Your task

Your task is to make a call to a specific endpoint in this API.

That endpoint is one of those that you might have seen in the previous task, but not one that met the criteria of that task. It's this one:

/getCountryDateFormat

The reason it doesn't meet the criteria is because a response to a request to this endpoint is returned in a text representation, i.e. MIME type text/plain, and not JSON.

You must specify the value DE for the country parameter.

But rather than just use the Try Out facility on the hub, you should instead make the call using an HTTP client of your choice. There's some examples given in the Hints and tips section of Task 0.

In order to "persuade" you to make the HTTP call yourself, you need not only the response to such a call, but you'll need also a specific header from the HTTP response. That header is a custom header, i.e. is prefixed with x- and relates to a traditional programming language in the SAP world.

So you need to take two values:

  • the content of the response payload (remember, it is in a text/plain representation)
  • the x- prefixed SAP language related header name, as it appears in the HTTP response

The header name should already appear in lower case, but please make sure it is, i.e. before you use it (see the next paragraph), ensure that it is all-lowercase.

You must join these two values together into a single string, concatenated with a comma.

It's this single string that you must send to be hashed and shared in a reply to this discussion thread as described in Task 0.

So for example, if the response payload was:

"banana"

and the response headers looked like this:

Date: Thu, 27 Jul 2023 12:05:40 GMT
Content-Type: application/json
Content-Length: 12
Connection: keep-alive
vary: Accept-Encoding
x-abap-hidden-header: 123.456ms
x-request-id: 54dcdcb3-cf10-4d2b-6a2d-64ad846bd1e5
x-response-time: 417.10979ms
x-vcap-request-id: 54dcdcb3-cf10-4d2b-6a2d-64ad846bd1e5
strict-transport-security: max-age=31536000; includeSubDomains; preload;
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: false

then the string to hash would be:

"banana",x-abap-hidden-header

Hints and tips

You'll need to find out how to authenticate the HTTP request, and provide the appropriate authentication details. If you don't, your request will be refused, with an HTTP 401 status code. Here's an example, where you see the headers of the request (identified with > characters at the start of the line) and of the response (identified with < characters at the start of the line):

> GET /dateandtime/getTimezoneFromLocation?country=DE HTTP/1.1
> Host: sandbox.api.sap.com
> User-Agent: curl/7.74.0
> Accept: */*
> 
< HTTP/1.1 401 Unauthorized
< Date: Thu, 27 Jul 2023 11:59:48 GMT
< Content-Type: application/json
< Content-Length: 146
< Connection: keep-alive
< 

You'll also receive some JSON in the response body telling you what's missing.

In order to get the authentication details you need, you'll need to be logged on to the hub.

You'll need to get your HTTP client or client library to emit the details of the HTTP response, so you can see the headers and find the one required. For example with curl, you could use the --include option, or even the --verbose option.

For discussion

Have you seen x- prefixed headers before? What does this prefix signify? Is this still common practice these days?

107 REPLIES 107

qmacro
Developer Advocate
Developer Advocate
0 Kudos

Yep. Also, as @UweFetzer_se38 mentioned (and as I was hinting at in the "For discussion" questions), the `x-` prefix is becoming less common as the practice is being phased out. 

bztoy
Participant
0 Kudos

de893753de5825967e8ba784a941c8f28c1da75fa7a96b68cbf49b4dd5ff6416

I have seen x- prefixed headers before. In the early stage of my current project, I developed an ABAP program to intergrade with a software package designed in mid 2000 via REST API. There are quite a lot of x- prefixed header used to transfer data in the HTTP response.

 

I am happy that it seems we don't need them nowadays. 😃

qmacro
Developer Advocate
Developer Advocate

Yep. 

I'm thinking that whether or not the `x-` prefixed headers are relevant (or best practice) any more, the great thing is that we're all now aware of, and more comfortable finding and staring at HTTP headers in requests and responses, because of the great work you're all doing in this challenge 🚀

PriyankaChak
Active Contributor
0 Kudos

474fa03f0dc1be1dfd748494ab4009e66c4f3036ca2b7120672b58766da1acf9

ceedee666
Active Contributor
0 Kudos
acd059a218f91ba8e269dab25b11146a4b0b1c201a5030bc7e3e33ec13c974a9

yassine
Explorer
0 Kudos

6bfb1cf75cabccddbf559e636c6ab916f0386f216c695a4a840776db1c11c196

stickman_0x00
Explorer
0 Kudos

04773dc182fc1478b6cc7699bef1411b567a1a70f21634593eb0b8ce57e1ab2c

nicoschoenteich
Developer Advocate
Developer Advocate
0 Kudos

52d69656dc25daaeb1ff0cb32ca71ac58eb75841a6356cd41995f90f8e9ca31d

shotokka
Explorer
0 Kudos

964d5f6443a1317b7ceedf51abd104eeb94f4cc616dae2b1a817ddb807b40789

jens_borau
Explorer
0 Kudos

00d755363dada399bd766c8216994549adc76d529cafa3a012b846cf95bec1a7

ajos
Explorer
0 Kudos

158fe6356501cefed2662cf109a2c6b8ac114d4755493ddd1e3ac426b19f7174

szeteng00
Explorer
0 Kudos

bd4f5f19b7932934dbf0bb0881c72eb18fa07f15846a08f8c8c243ff0ea1fd66

imancour
Explorer
0 Kudos

60de631ee9191e4383229fc6e224f69d28360589bd23731208ca1321d16482d5

MarcelloUrbani
Active Contributor
0 Kudos

a35a2d9f2e1e452b1a22bf9f07144966a8c3d4d272b765c260d3b408b03aab15

DenisGaland
Participant
0 Kudos

cd743591b46c49eae9dd5c3b4e1f18150eb194fc08cc2f65524b9d1a62f9a886

tly
Explorer
0 Kudos

5149e68409bc89cdf29571bde8e592a38f2bae2690bd23f53c6aaba465376b6d

Ruthiel
Product and Topic Expert
Product and Topic Expert
0 Kudos

c7c7124a311246ed4d6a58f0b470c05b18ca9c50c0d7f6fdbc5ef9e6b3d687cb

MioYasutake
Active Contributor
0 Kudos

b8cd761a783b57c514d0de79ea0f394aca8fedfcbe5917a6e9f1224baf657173

Ashok459
Participant
0 Kudos

1d0c2597967369d843c5cb7a3b5bf37a7857b5830c75c7d39881668d78c7aa0f

Ritik
Participant
0 Kudos

32b7152c530b5f7dd232a85603ed8c1409176c318fa44020adf2db662784febf

IsmailFatih
Explorer
0 Kudos

412321676d9c7cad366de9475379e5463b00c1268168e63bcac47b26cc74d8ed

cguttikonda24
Participant
0 Kudos

5446693833d6ec6e29442c40c3ae85e2dabee03034afbc00da855dba95fb9035

geek
Participant
0 Kudos

695157f5e07488870725ee5a5f214bd693f0ca7479e9b860aca8b5cfaa1970e6

garyzuo
Explorer
0 Kudos

743363e334398133155b97477e74329b339b07be0be10ea712650048f7f427ef

nmkarthikeya
Active Participant
0 Kudos

3ff873f0a3878f167d89dc1b075368338deb200ee6f315dede6f5e3d605b4181

vinaychowdary
Explorer
0 Kudos

f6575909bb447d2a0b97d67cdd2daf1fc259d75b089882d111046e0d926fbffe

emiliocampo
Explorer
0 Kudos

41bc6f86c0f87efa7478f4bed84925e3f805c2c7d8d30db2892498b2ddcf8348

dhegde
Participant
0 Kudos

1585da47d1de54e6d64197181dde9e1e78470f69a223089932721545a6db933d

turanaydin
Explorer
0 Kudos

87afdb419ad75182c2a78b64de5afabddc6c5821f5b14f7c1c354e5980227bad

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos

In Postman, I copied the URL from the Business Accelerator Hub, and it seems to have added a line feed and therefore did not adjust for the country parameter.

dan_wroblewski_0-1692509360843.png

And you can see, therefore, it did not return German date format:

dan_wroblewski_1-1692509415702.png

FacepalmPicardGIF.gif

 




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

0 Kudos

Awesome, thanks for sharing (and for the GIF) @Dan_Wroblewski  🙂 

Whitespace is important. Whether to use it, or to remove it. Always.

Talking of (white)space, I'm minded to share one of my favourite quotes from the creator of one of my all time favourite languages, Perl. 

"And don't tell me there isn't one bit of difference between null and space, because that's exactly how much difference there is." -- Larry Wall

You have to think about this quote a bit, but when you get it, you get it 🙂

Who here can suggest to what this quote is referring, i.e. how it makes sense?

govardhansahil
Explorer
0 Kudos

725f7ea931f13651bd2042d3c3c52a700e04251263c591e904cce24ecb482f40

geek
Participant
0 Kudos

f60bcc380a47ebe620568fd914fc3a26f74ccb33188ab42f537f019e2c2b2e4c

flo_conrad
Explorer
0 Kudos

625bc7b57754ee4495d759a7d5dfc50646e6265f6a5a9fe402645b0dd9acf6f5

sandeepmalhotra
Participant
0 Kudos

679c4a4ccc33b57968a8375fcb7c1977f3eee5bfd66f5a28d6e89760ba8bcb32

salilmehta01
Associate
Associate
0 Kudos

a9045aac0ac8cf6b506d2eaeaebd8763398f1a7d396785c8d155f73a89b6b8c4

GRABLERE
Product and Topic Expert
Product and Topic Expert
0 Kudos

be21b352731aae28e03b5af3908c2cfc161b3175bdc63a4c1a39e7e67511d996

jmuiruri
Product and Topic Expert
Product and Topic Expert
0 Kudos

ac552560b3dca4a2c568d4ffeb16532e1baf8ae7bb0674506f1fe176976213c0

cdias
Product and Topic Expert
Product and Topic Expert
0 Kudos

d697254a489fda4277e08d83095d535220825f371c3006576092c333f4505166