Reading input from the command line

If a developer toolkit command takes a file as an input parameter, you can direct the command to read the input directly from the command line rather than supplying a separate file; this can be useful when writing scripts to automate command line operations, for example.

Reading input from a file

Many developer toolkit commands that create or update new objects in API Connect take a file as an input parameter. For example:
  • Register a new gateway service:
    apic gateway-services:create [flags] GATEWAY_SERVICE_FILE
  • Update a provider organization:
    apic orgs:update [flags] ORG_FILE
  • Create a new Catalog:
    apic catalogs:create [flags] CATALOG_FILE
  • Create a new consumer organization:
    apic consumer-orgs:create [flags] CONSUMER_ORG_FILE
  • Register a new developer application:
    apic apps:create [flags] APP_FILE
  • Create a new email server:
    apic mail-servers:create [flags] MAIL_SERVER_FILE
  • Update the list of applications that subscribe to a Product:
    apic subscriptions:update [flags] SUBSCRIPTION_FILE

You can format the input file as a YAML file (the default) or as a JSON file. To use a JSON file as input, include the --format json parameter.

Reading input from the command line

As an alternative to supplying an explicit file name to the command, you can supply a hyphen (-) in place of the file name parameter; the command will then read the file content directly from the command line as shown in the following examples.

  • Register a new DataPower® Gateway (v5 compatible) gateway service:
    apic gateway-services:create --server platform-api.myserver.com --org admin --availability-zone availability-zone-default -
    Reading GATEWAY_SERVICE_FILE arg from stdin
    name: dpgw-service
    title: DataPower gateway service, compatible with v5
    gateway_service_type: datapower-gateway
    endpoint: 'https://mygwhost.com:3000'
    api_endpoint_base: 'https://mygwhost.com:9443'
    sni:
      - host: '*'
        tls_server_profile_url: https://platform-api.myserver.com/api/orgs/75203636-f038-4287-a732-24af4bf7059d/tls-server-profiles/3c0a0e93-6aa4-4288-b09c-eccf4901b104
    visibility:
      type: public
    Note: You can obtain the tls_server_profile_url property value for a TLS server profile by using the following command, which lists the URLs for all TLS server profiles:
    apic tls-server-profiles --org organization_name --server mgmt_endpoint_url
  • Create a new provider organization:
    apic orgs:create --server platform-api.myserver.com -
    Reading ORG_FILE arg from stdin
    name: development
    title: Development organization
    owner_url: https://platform-api.myserver.com/api/user-registries/1bbbd414-22f1-47cf-8eac-2050530d29a7/c082d755-866e-4394-959f-fbb264c6c3a1/users/2db491c7-2d0f-4f60-a8ae-f38d07481f21
    Note: You can obtain the owner_url property value by using the following command, which returns the url property for a specific user:
    apic users:get username --user-registry user_registry_name --server mgmt_endpoint_url --org organization_name --fields url --output -
  • Create a new Catalog:
    apic catalogs:create --server platform-api.myserver.com --org myorg -
    Reading CATALOG_FILE arg from stdin
    name: production
    title: Production Catalog
    summary: Catalog containing APIs in production use
  • Create a new consumer organization:
    apic consumer-orgs:create --server platform-api.myserver.com --catalog sandbox --org myorg -
    Reading CONSUMER_ORG_FILE arg from stdin
    name: finance-apps
    title: Developers of finance applications
    owner_url: https://platform-api.myserver.com/api/user-registries/a1fb8159-fda1-410f-93ab-a0ea5fd04535/70ce7ec3-e83f-4c87-9f3c-4662ad108bbc/users/fddd5df5-c178-4a34-ab92-0a48344d5c9b
    Note: You can obtain the owner_url property value by using the following command, which returns the url property for a specific user:
    apic users:get username --user-registry user_registry_name --server mgmt_endpoint_url --org organization_name --fields url --output -
  • Register a new developer application:
    apic apps:create --server consumer-api.myserver.com --org my-consumer-org --mode consumer -
    Reading APP_FILE arg from stdin
    name: finance
    title: Finance application
    summary: Mobile app for personal finance management
  • Create a new email server:
    apic mail-servers:create --org admin --server platform-api.myserver.com  -
    Reading MAIL_SERVER_FILE arg from stdin
    title: My email server
    name: my-email-server
    host: smtp.myemail.com
    port: 20
    credentials:
      username: me@myemail.com
      password: password
  • Create a new subscription to subscribe an application to a Product:
    apic subscriptions:create --app myapp --catalog sandbox --org myorg --server platform-api.myserver.com --consumer-org my-consumer-org -
    Reading SUBSCRIPTION_FILE arg from stdin
    product_url: https://platform-api.myserver.com/api/catalogs/960733c1-d7f7-4b90-9bc7-69dbfbe4ce31/ca34537d-adf4-4320-8495-a7feaa62d679/products/638015c6-a8b0-452e-841f-2ac441ab6962
    plan: default-plan
    Note: You can obtain the product_url property value for a Product by using the following command, which lists the URLs for all versions of a Product given the Product name:
    apic products:list product_name --scope catalog --catalog catalog_name --org provider_org_name --server mgmt_endpoint_url