Contact Us 1-800-596-4880

Create an API Using a CRD

After you provision the adapter, you must create an API to bind to the service. You can create an API using Anypoint Platform or Anypoint Service Mesh:

  • Create an API using Anypoint Platform

    Create APIs using Anypoint Platform when your API specification files are larger than 550 KB. If you want to upload a REST API or an OAS asset type, use a .json, .raml, .zip or .yaml file. If you want to upload a SOAP API or WSDL asset type, use a .wsdl or .xml file.

  • Create an API using the Anypoint Service Mesh autocreate feature

    You can configure Anypoint Service Mesh to automatically create an API in Anypoint Platform (no manual logging required). When creating APIs that require specification files, such as REST and SOAP APIs, ensure that the specification file is not larger than 550 KB and is available in your file system for the CLI to upload.

Create an API by Using Anypoint Platform

To create an API using Anypoint Platform, perform the following steps:

  1. Go to Anypoint Platform > API Manager and select the Manage API drop-down list.

  2. Select Create new API.

    The Creating an asset page is displayed.

  3. Specify the Name, and Asset types details for the API.

    Your Asset is now created in Exchange for reuse. After you create the Asset, you are now ready to perform Endpoint configuration.

    The Endpoint Configuration window is displayed.

  4. In the Managing type field, select the Basic Endpoint radio button.

  5. In the Application type field, select the Non-Mule application radio button.

  6. Optionally, specify the Implementation URI, and click Save.

    Your API is now created.

Create an API Using the Anypoint Service Mesh Autocreate Feature

Since October 29th of 2022, the user credentials option for API autocreate feature is no longer supported. Migration to the Connected Apps approach is required. For more information, read the section below and the Obtain Connected Apps credentials page.

You can use Connected Apps credentials for authentication when creating an API using the Anypoint Service Mesh autocreate feature. This option supports users:

  • Managed by Anypoint Platform or an external IdP

  • Whether or not they have enabled multi-factor authentication

Autocreate APIs by Using Your Connected Apps Credentials

Before you configure the Anypoint Service Mesh autocreate feature, ensure that:

  • You obtain the:

  • Verify that these client credentials include:

    • Exchange Contributor permission for publishing the API to Exchange

    • Manage API Configuration permission for managing the API in API Manager

To autocreate APIs using Connected Apps, perform the following steps:

  1. Create your API definition file and save it with a '.yaml' file extension, for example test-api.yaml:

    apiVersion: servicecatalog.k8s.io/v1beta1
    kind: ServiceInstance
    metadata:
      name: _Kubernetes API resource name_ # example: orders-api
      namespace: _namespace name_ # example: default
      labels:
        service-mesh.mulesoft.com/kind: api
    spec:
      clusterServiceClassExternalName: anypoint-platform-api-instance
      clusterServicePlanExternalName: service-mesh
      parameters:
        environmentId: _environment ID_ # example: 7cea45c6-3237-464d-bd34-3122c4abde29
        groupId: _group ID_ # Optional - example: 350b8164-e809-4091-91f5-079fb30e5a1e
        assetId: _asset ID_ # example: orders-api
        version: _version_ # example: 0.0.1
        instanceLabel: _instance label_ # example: public
        tags:
          apiSpec:
          - _tag in Exchange asset_ # example: orders
          apiInstance:
          - _tag in API Manager instance_ # example: orders
        clientId: _ID of the Anypoint Platform connected app_
        clientSecret: _Secret of the Anypoint Platform connected app_
  2. Apply the CRD file: kubectl apply -f test-api.yaml

  3. Verify that the API was successfully created: asmctl api list

  4. Optionally, verify that an Exchange asset is created on Exchange and an API is created on API Manager.

Reference Kubernetes Secrets

Anypoint Service Mesh supports the use of Kubernetes secrets to store and manage sensitive information, such as your Connected App credentials. With Kubernetes secrets, you do not have to specify the username and password credentials every time you create an API.

Before you configure your Kubernetes secrets, ensure that you have the required permissions.

To store your client credentials in Kubernetes secrets:

  1. In a YAML file, create a secret in which to store the sensitive information, for example, orders-api-config.yaml:

    apiVersion: v1
    kind: Secret
    metadata:
      name: _secret name_ # example: orders-api-config
      namespace: _namespace name_ # example: default
    type: Opaque
    stringData:
      config: |
        {
          "clientId": "_replace-with-connected-app-id_",
          "clientSecret": "_replace-with-connected-app-secret_"
        }
  2. Apply the secret:

    kubectl apply -f orders-api-config.yaml

    If the secret is correctly applied, a 'secret/orders-api-config created' message is displayed.

  3. Reference the secrets in your API CRD, as illustrated in the following example:

    apiVersion: servicecatalog.k8s.io/v1beta1
    kind: ServiceInstance
    metadata:
      name: _Kubernetes API resource name_ # example: orders-api
      namespace: _namespace name_ # example: default
      labels:
        service-mesh.mulesoft.com/kind: api
    spec:
      clusterServiceClassExternalName: anypoint-platform-api-instance
      clusterServicePlanExternalName: service-mesh
      parameters:
        environmentId: _environment ID_ # example: 7cea45c6-3237-464d-bd34-3122c4abde29
        groupId: _group ID_ # Optional - example: 350b8164-e809-4091-91f5-079fb30e5a1e
        assetId: _asset ID_ # example: orders-api
        version: _version_ # example: 0.0.1
        instanceLabel: _instance label_ # example: public
        tags:
          apiSpec:
          - _tag in Exchange asset_ # example: orders
          apiInstance:
          - _tag in API Manager instance_ # example: orders
      parametersFrom: # The element specifies the secret name and configuration required for retrieving the parameters.
      - secretKeyRef:
          name: _secret name_ # example: orders-api-config
          key: config