hi, Sai Kiran
Recommend "apic --help" which yields a long list of apic commands. "login" is one such. Next: "apic login --help". See Non Interactive login -- bold text at bottom.
$ apic login --help
Usage: apic login [flags]
Log in to an IBM API Connect cloud
Flags:
--apiKey string apiKey
--context string context
-h, --help Help for login
-p, --password string password
-r, --realm string realm
-s, --server string management server endpoint
--sso sso
-u, --username string user name
Examples:
Interactive login
$ apic login
Enter your API Connect credentials
? Server: mgmnthost.com
? Realm: company/realm
? Username: tommy
? Password: password
Logged into mgmnthost.com successfully
Non-interactive login
$ apic login --username tommy --password password --server mgmnthost.com --realm company/realm
Logged into mgmnthost.com successfully
------------------------------
Ravi Ramnarayan
Technical Account Manager - Expertise Connect
IBM
------------------------------
Original Message:
Sent: Sun January 15, 2023 01:33 PM
From: Sai Kiran
Subject: CLI tools for Apic v10
Hi Ravi,
While am trying to write a script - i need below login part to be done via script- using shell/python.
May i know how can be this achieved. Please help.
$ ./apic login Enter your API Connect credentials Server? apim.mgmt.dev.apic.xxxxx.test Realm? admin/default-idp-1 Username? admin Password?
------------------------------
Sai Kiran
------------------------------
Original Message:
Sent: Mon January 24, 2022 07:04 AM
From: Ravi Ramnarayan
Subject: CLI tools for Apic v10
hi, Suraj
I assume you can log into the CMC as "admin". Do you see the tile "Download toolkit"? For starters, I recommend downloading the "CLI Only" for your platform along with the "client-creds". I usually create a symbolic link (on Linux) "apic-slim" to "apic" -- however, that is a personal preference. Getting started can be tricky. I recommend you start with the following. NOTE: The endpoints in your installation are likely to differ.
Get started with command line
Each user belongs to a realm and authenticates with an identity-provider. To log in, even the admin needs to provide the name of the identity-provider. How can I find the name of the identity-provider if I cannot login? There is a way out. CMC objects belong to the admin scope. This command works without login:
$ ./apic identity-providers:list --scope admin --server platform.mgmt.dev.apic.xxxxx.test --fields name,title total_results: 1 results: - name: default-idp-1 title: Cloud Manager User Registry
Log in as admin:
$ ./apic login Enter your API Connect credentials Server? apim.mgmt.dev.apic.xxxxx.test Realm? admin/default-idp-1 Username? admin Password?
At this stage there is only one Organization:
$ ./apic orgs:list -s apim.mgmt.dev.apic.xxxxx.test --format yamltotal_results: 1results: - type: org api_version: 2.0.0 id: 790cbfc3-fafc-489e-a2fe-d7e827cea731 name: admin title: Cloud Admin summary: Cloud Admin organization state: enabled org_type: admin owner_url: >- https://apim.mgmt.dev.apic.xxxxx.test/api/user-registries/790cbfc3-fafc-489e-a2fe-d7e827cea731/7218cc7f-4ac9-4f0a-992c-53ec31eb032e/users/6037d730-4218-4ed2-8e03-1aa596d34671 created_at: '2020-07-21T14:15:19.160Z' updated_at: '2020-07-21T14:15:19.160Z' url: >- https://apim.mgmt.dev.apic.xxxxx.test/api/orgs/790cbfc3-fafc-489e-a2fe-d7e827cea731
The output for just one org is voluminous. Other objects emit far more data. You can generate JSON with --format json, pipe it through jq and extract desired elements to feed your automated scripts.
$ ./apic orgs:list -s apim.mgmt.dev.apic.xxxxx.test --format json | jq '.results[0] | {name: .name, org_type: .org_type, summary: .summary, id: .id}'{ "name": "admin", "org_type": "admin", "summary": "Cloud Admin organization", "id": "790cbfc3-fafc-489e-a2fe-d7e827cea731"}
JQ Tutorial is an excellent reference. For further material please consult ibm-apiconnect/apic-hybrid-cloud-enablement in particular Publish API Product Version to a Consumer Organization -- a complex script to implement a specific use case.
------------------------------
Ravi Ramnarayan
Technical Account Manager - Expertise Connect
IBM