2023 Aug 18 7:04 AM - edited 2023 Aug 22 5:26 PM
(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.
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:
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 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:
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.
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.
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:
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:
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:
# 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.
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?
2023 Aug 18 7:23 AM
2023 Aug 18 7:35 AM
2023 Aug 18 7:41 AM
2023 Aug 18 7:48 AM
2023 Aug 18 7:49 AM
2023 Aug 18 10:45 AM
2023 Aug 18 7:50 AM
2023 Aug 18 8:24 AM
2023 Aug 18 9:15 AM
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).
2023 Aug 18 10:45 AM
2023 Aug 18 8:51 AM
2023 Aug 18 8:56 AM
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?
2023 Aug 18 9:12 AM
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.
2023 Aug 18 10:47 AM
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
2023 Aug 18 8:52 AM
2023 Aug 18 8:54 AM - edited 2023 Sep 01 4:08 PM
2023 Aug 18 8:58 AM
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.
2023 Aug 18 10:50 AM
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...
2023 Aug 18 11:12 AM
2023 Aug 18 11:29 AM
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 🙂
2023 Aug 18 11:31 AM
2023 Aug 18 1:26 PM - edited 2023 Aug 18 1:27 PM
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.
2023 Aug 18 9:26 AM
2023 Aug 18 9:26 AM
2023 Aug 18 10:52 AM
2023 Aug 18 10:52 AM - edited 2023 Aug 25 8:04 AM
2023 Aug 18 10:58 AM
2023 Aug 18 11:02 AM
2023 Aug 18 1:26 PM
2023 Aug 18 12:27 PM
2023 Aug 18 1:27 PM - edited 2023 Aug 31 9:05 AM
2023 Aug 18 1:54 PM
2023 Aug 18 1:56 PM
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.
2023 Aug 18 2:13 PM
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 👍
2023 Aug 18 2:52 PM
2023 Aug 18 4:05 PM
2023 Aug 18 4:30 PM
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. 👍👏
2023 Aug 22 5:27 PM
2023 Aug 18 4:42 PM