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 7 - Create a new directory in an SAP BTP account

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

This task is the first in a group that belong together, and in it you will prepare the ground for the subsequent tasks in that group.

Background

The SAP Business Accelerator Hub contains API and related resources not only for SAP products such as SAP S/4HANA Cloud, SAP SuccessFactors, SAP Ariba, SAP Concur and so on, but also for the SAP Business Technology Platform, as you can see:

The Explore menu

Selecting this entry brings you to an overview page with links to APIs, events, integrations, business processes, workflow management resources and more. You'll see that one of the API packages available is Core Services for SAP BTP which contains multiple REST APIs, including:

  • Accounts Service
  • Entitlements Service
  • Events Service

and more.

These APIs afford you programmatic access to information on SAP BTP, specifically about your global accounts, subaccounts, directories, entitlements, services and lots more.

In the next few tasks you will take a small journey of discovery, one that will lead you to be able to make calls to these APIs, and in fact you will end up making a specific call to get a feel for how things operate and what you need to make such calls.

In order for everyone to have something consistent to work with, i.e. so that you all end up making essentially the same call, and will get the same results, this task will get you to create a directory in an SAP BTP account, with a custom label. In a subsequent task in this group you'll use the appropriate API in this Core Services for SAP BTP package to retrieve that information.

Your task

Your task here is to create a new directory within an SAP BTP global account accessible to you. If you don't have one, you can set up a trial account for free - see the "Hints and tips" section below for details.

Here are the task requirements:

  • The directory should be created at the top level of the account
  • It should be given the name developer-challenge
  • It should have one label named task with the value 7

You can do this any way you wish. You may want to use the SAP BTP Cockpit. You may wish to use the btp CLI. See the "Hints and tips" section below for both these approaches.

The value you need to get, to send to be hashed and shared in a reply to this discussion thread (as described, as always, in Task 0), is the length of the new directory's GUID. Not the GUID itself. The GUID consists of groups of hexadecimal digits interspersed with dashes. In calculating the length required, note that you should measure the length of the entire GUID, including the dashes.

Hints and tips

If you don't have a global account with which to work (for example, if you only have access to productive accounts at work and can't use them for learning), you can get a trial account on SAP BTP, and it won't cost you anything. You don't even need a credit card to sign up for one. Just follow the instructions in the tutorial Get a Free Account on SAP BTP Trial.

Creating the directory in the cockpit

You can create the directory from the Account Explorer section of the SAP BTP Cockpit.

Use the "Create -> Directory" menu from the button and specify the details appropriately, like this:

directory-creation.png

Once you've created the directory, it should look like this (you may have to adjust the display settings from the "tree view" to the "table view"). Note that the label information is available too in this display:

directory-created.png

Creating the directory with the btp CLI

Of course, as #TheFutureIsTerminal, you may prefer to go for maximum efficiency and use the command line. Luckily for us there's a great command line tool for accessing and manipulating resources on SAP BTP, and that's the btp CLI, available from the SAP Development Tools website. There are plenty of resources on the btp CLI, here are just a few:

Here's a sample session where I use the btp CLI to create the directory, in that I:

  • log on
  • choose an account (my trial global account)
  • use the create action for the appropriate group and object (accounts/directory)
# developer-challenge-apis/tasks/7-create-assets-in-an-sap-btp-account (main %=)
; btp login
SAP BTP command line interface (client v2.38.0)

CLI server URL [https://cpcli.cf.eu10.hana.ondemand.com]>
Connecting to CLI server at https://cpcli.cf.eu10.hana.ondemand.com...

User> dj.adams@sap.com
Password>

Authentication successful

Choose a global account:
  [1] c2d7b67atrial
  [2] ...
  [3] ...
Choose option> 1

Current target:
 c2d7b67atrial (global account, subdomain: c2d7b67atrial-ga)

We stored your configuration file at: /home/user/.config/btp/config.json

Tips:
    Commands are executed in the target, unless specified otherwise using a parameter. To change the target, use 'btp target'.
    To provide feedback about the btp CLI, use 'btp feedback' to open our survey.

OK

# developer-challenge-apis/tasks/7-create-assets-in-an-sap-btp-account (main %=)
; btp create accounts/directory \
  --display-name "developer-challenge" \
  --labels '{"task":[7]}'
Creating directory in global account 7da58aab-6c60-4492-a95b-b1ed3139e242...

directory id:         57675710-7b16-43ec-b64a-ab14660c1b24
display name:         developer-challenge
description:
directory features:   DEFAULT
created by:           dj.adams@sap.com
custom properties:    name:   value:
                      task    7
labels:               name:   value:
                      task    [7]
parent id:            7da58aab-6c60-4492-a95b-b1ed3139e242
parent type:          global account
state:                OK
state message:        Directory created.

Command runs in the background.
Use 'btp get accounts/directory' to verify status.

OK

Although the value 7 for the task label is scalar, it must be specified in the JSON value for the --labels parameter inside an array, i.e. [7] rather than just 7.

For discussion

Did you use the cockpit or the CLI tool? Which would or do you prefer? If you used the btp CLI, how did the installation go? Did you install it "natively" or did you use the script described in the SAP Tech Bytes: btp CLI – installation blog post?

What are some of your other power command line tools, inside the SAP ecosphere and also beyond?

99 REPLIES 99

ajmaradiaga
Developer Advocate
Developer Advocate
0 Kudos

6894b670c2b1d9effe360d9263c5a551027217db47e074a3e3eafaf3ad159931

abdullahgunes
Participant
0 Kudos
2664a2065b2ff35ba59faf6050325ca6ae1c611258d263c50818526c95d6d574

ADR
Participant
0 Kudos

9b7f173b65e798b175507f24164c8f9ee1c8f7ac966a8fd0a1b02cb98199cad1

kasch-code
Participant
0 Kudos

c07375534f481320e171d193db89ceb7e962fbcdc7ecd70239c2c22b6f820c92

ADR
Participant

Hi DJ, @qmacro , I used CLI to create it. I got my inspiration to use CLI from your Youtube videos and blogs. 🙂

I have created multiple scripts to automate role collection creations, user management in BTP. 

- Anupam

qmacro
Developer Advocate
Developer Advocate

Excellent, great to hear! 🚀

FooThePolarBear
Explorer

11169b1f0973473cf910d4859662e2f71c60a471ddca9943468fee5510adf601

harsh_itaverma
Participant

f00bef0e3c26513480bb3289f1de77df63f0431f5cc9da838d860e7187ab5326

I tried using the BTP cockpit and the cli too. Went ahead with the installation of the BTP CLI using the script file and it was pretty quick to install. This was a good learning (would definitely follow the complete blog series).

ceedee666
Active Contributor
0 Kudos
e3a9d78fdd1e0ecf80c4f6c338860d93c021f236a6693a32916e1928b8fc2c1b

ceedee666
Active Contributor
0 Kudos

I used the CLI to create the directory.

I then tried to read the directory again using the API. However, I was not able to find a service to list all directories in an subaccount. The same is true for the CLI. I allways need the GUID of the directory in order to get the details. Or am I missing someting?

ceedee666
Active Contributor

OK. Found it. The possibility to get directories is well hidden 😉. It is possible to list the directories of a global account using: 

 

 btp get accounts/global-account --show-hierarchy 

 

The same is true for the API. The /accounts/v1/globalAccount operation has a parameter expand.

 

qmacro
Developer Advocate
Developer Advocate

Nice find 🙂 In fact, that command, with the --show-hierarchy parameter, is one I use the most often, so often in fact that I have an alias `btphier` 🙂

https://github.com/qmacro/dotfiles/blob/main/bashrc.d/84-sap-btp.sh#L57 

AAncos
Explorer
0 Kudos

c58bcd48fe2e72b06626e681fbae2df7b4aa338d0c96a0210cc16e5e21c09e48

seVladimirs
Active Contributor
0 Kudos

04948d4d766ac04f63d20120d6ce07525f3bc5b0575fa8a141880a37f8726d58

To learn new stuff I've used the BTP CLI, as normally I'm doing the same via BTP Cockpit UI 

Also, I had trouble logging into BTP because I was using an outdated version of btp cli. It took me a while to realize this, so I want to remind anyone experiencing the same issue to update their BTP CLI to the latest version.

qmacro
Developer Advocate
Developer Advocate

Yep. In fact, if you can use the download script (see SAP Tech Bytes: btp CLI – installation) it will retrieve and install the most current version for you. I think @harsh_itaverma used this script...

Yes @qmacro, that was awesome.

When the blog was written the version was 2.8.0.
Using the script, I was able to install the latest 2.49.

seVladimirs
Active Contributor
0 Kudos

I've tried to use your script @qmacro but I got an error message and didn't have time to explore:

./getbtpcli --test 

./getbtpcli: line 19: ${PLATFORM,,}-amd64: bad substitution

Would be much easier if it would be available via homebrew 🙂 

qmacro
Developer Advocate
Developer Advocate
0 Kudos

Hehe. See this comment from me on the blog post referenced earlier. I'm guessing with your reference to Homebrew that you're running macOS, in which case, out of the box, you have a very very old version of Bash which they have stopped updating, unfortunately.

What's more is that they are thereby almost forcing folks to adopt zsh, which has been the default for a while now.

UweFetzer_se38
Active Contributor
0 Kudos

81d27aac83f8da433cddb9be0b3a0f94a68debcb4fce611f9a79bf211d5a6460

Tomas_Buryanek
Active Contributor
0 Kudos

dd7caaf2525d4234f09df1e188f4f0d4bcc376ce065cfaeec9ed4b39fd6e254c

shotokka
Explorer
0 Kudos

4250a32a733a23605ccd9c97eda660f1a513499f35fa67e741465238b7cb60bc

prachetas
Participant
0 Kudos

9a5eae907454e7b6d956d74017709f7beaf1c8f2d8163a2f9beb2a62321cca0b

choujiacheng
Explorer
0 Kudos

b9cadb0e8e65120c003979df256e3c6e543ab0260f1bdce608079e09567d9c3a

0 Kudos

Admittedly, I used the GUI for time and convenience. I did use the Git CLI instead of the GUI in Business Application Studio, but for the most part I find the GUI more convenient to work with.

qmacro
Developer Advocate
Developer Advocate
0 Kudos

Do you mean the btp CLI (rather than the Git CLI) here? In any case, sure, you should use whichever tool you prefer, of course! 

stickman_0x00
Explorer
0 Kudos

49ad9c4be5d940ecd459dded2ef3fbbe2f5b35fab27ab4d9a52ccbe8e0cbc1a5

berserk
Explorer
0 Kudos

f9613bb814223b717810b363aec28ec34cc23cd9df0f65cc6c67d484aa556c71

SandipAgarwalla
Active Contributor
0 Kudos

692a165cb6b96052dc55eca088fe8d8c0164a43a40993ee4ee767c5219580e8d

SandipAgarwalla
Active Contributor
0 Kudos

I had to use the cockpit to create the directly. Can't install the btp cli on this work laptop for security reasons. But Cli looks neat and clean. 

I will try to use the REST APIs to create the directory. Have created the Service Instance and the key, next is to call the API from  POSTMAN. 

You can always use a Dev Space in the SAP Business Application Studio (to get a proper command line, UNIX (Linux) style!) and install it there, if you want to try it out 👍

PriyankaChak
Active Contributor
0 Kudos

402bc7b6a86ea4d84d1b029b8e63f8ae3a463c85342355849c83157a981d36c5

bztoy
Participant
0 Kudos

35cd705dd8fb9676d44ef3194ee16e79fb2a88fa5ea4f968038eb65508bf141f

0 Kudos

 

Did you use the cockpit or the CLI tool? Which would or do you prefer?

I used the CLI tool and of course, I prefer the CLI tool. 😎

 

If you used the btp CLI, how did the installation go? Did you install it "natively" or did you use the script described in the SAP Tech Bytes: btp CLI – installation blog post?

I used both. I found that the getbtpcli helper script is awesome but lately, I like to visit the SAP Development Tools landing page then if I found the newer version is released, I just update the BTP CLI to the latest version natively by myself.

 

What are some of your other power command line tools, inside the SAP ecosphere and also beyond?

Inside SAP ecosphere I am using cf, cds and (yo) easy-ui5 from generator-easy-ui5.

Outside SAP, I am using npm, npx, yarn, pip, cargo, go, git, psql, docker, kubectl and a bit more.

I am not sure that I should include curl and jq in the list since we are using them a lot in the previous tasks. 😁😁

 

One thing that I want to mention here, the help document of those btp commands are written very well. Thanks to the team, you have done a great job. 👍👏

qmacro
Developer Advocate
Developer Advocate

Thanks for sharing your answers to the discussion questions, @bztoy ! And of course, I do think you *should* include curl and jq, as they are essentials and should not be forgotten! 🙂

Thanks for the thoughts on the btp help docu, I'll definitely pass them on to the team!

martinstenzig
Contributor
0 Kudos

763fa41eeba967aa7f03ac5513702fa786fbfd084457cea8ea5c7102333120de