API Manager API

(4 reviews)

Deploy an API from scratch

The following guide shows two different use cases:

  1. Deploying a new API instance to a Flex Gateway target
  2. Deploying a new API instance to a Mule 4 Hybrid target

Deploying a new API instance to a Flex Gateway target

Flex Gateway API creation

The following request creates an API instance that will be deployed on a Flex Gateway proxy:

curl -X POST \
  https://anypoint.mulesoft.com/apimanager/api/v1/organizations/:organizationId/environments/:environmentId/apis \
  -H 'authorization: Bearer <token>' \
  -H 'content-type: application/json' \
  -d '{
    "spec": {
      "groupId": "<organizationId>",
      "assetId": "<assetId>",
      "version": "<assetVersion>"
    },
    "endpoint": {
      "deploymentType": "HY",
      "uri": "<upstreamUri>",
      "proxyUri": "http://0.0.0.0:8081/",
      "isCloudHub": null
    },
    "technology": "flexGateway",
    "instanceLabel": "example-label"
}'

Change the port of the proxyUri parameter to the best one for your use.

This is a response example for a Flex Gateway instance creation. Keep the instance "id" in order to use it in the deployment request:

{
    "environmentId": "<environmentId>",
    "instanceLabel": "example-label",
    "providerId": null,
    "technology": "flexGateway",
    "assetVersion": "<assetVersion>",
    "productVersion": "v1",
    "order": 1,
    "stage": "release",
    "audit": {
        "created": {
            "date": "2022-09-30T17:13:13.079Z"
        },
        "updated": {}
    },
    "masterOrganizationId": "<organizationId>",
    "organizationId": "<organizationId>",
    "id": 1234567,
    "groupId": "<organizationId>",
    "assetId": "<assetId>",
    "tags": [],
    "endpoint": {
        "deploymentType": "HY",
        "isCloudHub": null,
        "muleVersion4OrAbove": null,
        "referencesUserDomain": null,
        "responseTimeout": *null*,
        "uri": "<upstreamUri>",
        "proxyUri": "http://0.0.0.0:8081/",
        "type": "http",
        "validation": "NOT_APPLICABLE",
        "audit": {
            "created": {
                "date": "2022-09-30T17:13:13.079Z"
            },
            "updated": {}
        },
        "masterOrganizationId": "<organizationId>",
        "organizationId": "<organizationId>",
        "id": 9876543,
        "apiId": 1234567
    },
    "autodiscoveryInstanceName": "v1:1234567"
}

From this response, the instance "id" is 1234567.

Flex Gateway API deployment

Now we can deploy the created API instance by making a request to Proxies XAPI:

curl --location --request POST 'https://anypoint.mulesoft.com/proxies/xapi/v1/organizations/:organizationId/environments/:environmentId/apis/1234567/deployments' \
--header 'Content-Type: application/json' \
--header 'Authorization: bearer <token>' \
--data-raw '{
  "type": "HY",
  "gatewayVersion": "1.3.0",
  "targetId": "22855abb-f6e9-4046-ab08-ead5eb531c0e",
  "targetName": "<flex-target-name>",
  "environmentId": "<environmentId>"
}'

Where 22855abb-f6e9-4046-ab08-ead5eb531c0e and <flex-target-name> are the id and name of the Flex Gateway target displayed in Runtime Manager.

A successful request returns a response like the following:

{
    "type": "HY",
    "gatewayVersion": "1.3.0",
    "targetId": "22855abb-f6e9-4046-ab08-ead5eb531c0e",
    "environmentId": "<environmentId>",
    "environmentApiId": 1234567,
    "audit": {
        "created": {
            "date": "2022-09-30T17:11:54.989Z"
        },
        "updated": {}
    },
    "masterOrganizationId": "<organizationId>",
    "organizationId": "<organizationId>",
    "id": 11223344,
    "expectedStatus": "deployed",
    "apiId": 1234567
}

Upon receiving this request, the API instance has been deployed to your Flex Gateway target.

Deploying a new API instance to a Mule 4 Hybrid target

Mule 4 Hybrid API creation

This example shows how to create an API instance for a Mule 4 Hybrid target:

curl --location --request POST 'https://anypoint.mulesoft.com/apimanager/api/v1/organizations/:organizationId/environments/environmentId/apis' \
--header 'Authorization: bearer <token>' \
--header 'Content-Type: application/json' \
--data-raw '{
  "spec": {
    "groupId": "<organizationId>",
    "assetId": "<assetId>",
    "version": "<assetVersion>"
  },
  "deploymentType": "HY",
  "technology": "mule4",
  "endpoint": {
    "uri": "<upstreamUri>",
    "proxyUri": "http://0.0.0.0:8081/",
    "isCloudHub": false
  }
}'

This is a response example for a Mule 4 Hybrid instance creation. Keep the instance "id" in order to use it in the deployment request::

{
    "environmentId": "<environmentId>",
    "providerId": null,
    "technology": "mule4",
    "assetVersion": "<assetVersion>",
    "productVersion": "v1",
    "order": 1,
    "stage": "release",
    "audit": {
        "created": {
            "date": "2023-02-14T12:20:05.976Z"
        },
        "updated": {}
    },
    "masterOrganizationId": "<organizationId>",
    "organizationId": "<organizationId>",
    "id": 1234567,
    "groupId": "<orgamizationId>",
    "assetId": "<assetId>",
    "tags": [],
    "endpoint": {
        "deploymentType": "HY",
        "isCloudHub": false,
        "muleVersion4OrAbove": true,
        "uri": "<upstreamUri>",
        "proxyUri": "http://0.0.0.0:8081/",
        "type": "http",
        "validation": "NOT_APPLICABLE",
        "audit": {
            "created": {
                "date": "2023-02-14T12:20:05.976Z"
            },
            "updated": {}
        },
        "masterOrganizationId": "<organizationId>",
        "organizationId": "<organizationId>",
        "id": 987654,
        "proxyTemplate": {
            "assetId": "api-gateway-sample-http-proxy",
            "assetVersion": "2.0.5",
            "groupId": "org.mule.examples"
        },
        "console": null,
        "apiId": 1234567
    },
    "autodiscoveryInstanceName": "v1:1234567"
}

From this response, the instance "id" is 1234567.

Mule 4 Hybrid API deployment

Now we can deploy the created API instance by making a request to Proxies XAPI:

curl --location --request POST 'https://anypoint.mulesoft.com/proxies/xapi/v1/organizations/:organizationId/environments/:environmentId/apis/1234567/deployments' \
--header 'Content-Type: application/json' \
--header 'Authorization: bearer <token>' \
--data-raw '{
  "gatewayVersion": "4.4.0",
  "targetId": 99887766,
  "targetName": "<hybridServerName>",
  "targetType": "server",
  "type": "HY",
  "environmentId": "<environmentId>",
  "environmentName": "<environmentName>"
}'

Where 99887766, and <hybridServerName> are the id and name of the Mule Hybrid target displayed in Runtime Manager.

This request returns a response like the following:

{
    "gatewayVersion": "4.4.0",
    "targetId": 99887766,
    "targetName": "<hybridServerName>",
    "targetType": "server",
    "type": "HY",
    "environmentId": "<environmentId>",
    "environmentName": "<environmentName>",
    "environmentApiId": 1234567,
    "audit": {
        "created": {
            "date": "2023-02-14T12:33:43.206Z"
        },
        "updated": {}
    },
    "masterOrganizationId": "<organizationId>",
    "organizationId": "<organizationId>",
    "id": 111111,
    "expectedStatus": "deployed",
    "apiId": 1234567
}

Upon receiving this request, the API instance has been deployed to your Mule 4 Hybrid target.


Reviews