Flow Designer Experience API

(0 reviews)

Usage Examples

Flow Designer Experience API Use Cases:

  1. Create an Mule Application project

  2. List projects

  3. Add an Flow, a trigger and a processor to the project

  4. Run the application

  5. Delete Project


1. Create an Mule Application project
To create an Mule Application project we need to perform a POST operation to the resource /projects sending the following data in the request body:

curl -H 'Authorization: Bearer <token>' -d '{"name": <Application name>,"type": "Mule Application","environmentId": <environment Id>}' -X POST https://anypoint.mulesoft.com/designcenter/api/v1/organizations/<org id>/projects/

The response should be a 201 status returning an object which wraps the project and the worker created. It's important to notice that the project's id and the worker's id are the same.

2. List projects
After creating the project we will perform a GET operation to the /projects resource, to retrieve all the projects the user has permission.
The response should be a 200 status with a list of projects in the response body. The project created in the previous step should be in the list.

curl -H 'Authorization: Bearer <token>' POST https://anypoint.mulesoft.com/designcenter/api/v1/organizations/<org id>/projects/

3. Add an Flow, a trigger and a processor to the project
To add content to the project we will need to edit the json response we received in the project creation. An example project is the following json:

{
    "id": "95612c00-7fff-4cb7-a09b-90ce24819bfc",
    "name": "Mozart test",
    "type": "Mule Application",
    "environmentId": "deafcb9b-4c8d-4ff7-a118-3cd914ea1c4f",
    "organizationId": "2bacbe78-ab6d-4300-965a-39fce81ee15d",
    "globalConfigurations": [

    ],
    "flows": [],
    "dependencies": [],
    "enrichers": {},
    "catalogs": {},
    "topLevelElements": [],
    "metadata": {
      "runtimeVersion": "4.0.0",
      "elements": [],
      "cacheAssetId": null,
      "resources": [],
      "externalLibraries": [],
      "nodesMetadata": {},
      "projectModelVersion": "1.3.0-SNAPSHOT"
    },
    "deleted": false,
    "revision": 0,
    "version": "1.0",
    "description": null,
    "createdBy": "Mozart",
    "createdDate": "2018-01-10T19:03:32",
    "lastUpdatedDate": "2018-01-10T19:03:32"
  }

To add the content we need to perform a PUT operation to projects/{projectId} and send the new content in the body. In this case we will add a trigger (Http Listener), it's required configuration, a processor (Http request) and it's required configuration. The body will look like this:

{
    "id": "95612c00-7fff-4cb7-a09b-90ce24819bfc",
    "name": "Mozart test",
    "type": "Mule Application",
    "environmentId": "deafcb9b-4c8d-4ff7-a118-3cd914ea1c4f",
    "organizationId": "2bacbe78-ab6d-4300-965a-39fce81ee15d",
    "globalConfigurations": [
      {
        "id": "4e42ad99-137a-4818-b41b-8df1f8f2dc98",
        "name": "cloudhub_http",
        "description": "HTTP Listener",
        "extensionId": "org.mule.connectors:mule-http-connector:1.0.0",
        "configuration": {
          "parameterGroups": {

          },
          "name": "listenerConfig",
          "subtype": null
        },
        "connectionProvider": {
          "id": "56b82fca-a0c6-4c7f-b77b-b5236362e090"
        },
        "lastUpdated": 1515611099863
      },
      {
        "id": "b89da2de-82f8-41c8-a7f5-7c8b52748653",
        "name": "http_request",
        "description": "HTTP Request",
        "extensionId": "org.mule.connectors:mule-http-connector:1.0.0",
        "configuration": {
          "parameterGroups": {

          },
          "name": "requestConfig",
          "subtype": null
        },
        "connectionProvider": {
          "id": "d67cffc1-89fb-48a2-bb42-979fa83a350e"
        },
        "lastUpdated": 1515611135252
      }
    ],
    "flows": [
      {
        "id": "c019cac6-dcd5-4a9f-b2ef-2dadd8590dd1",
        "name": "new_flow",
        "description": "New Flow",
        "content": {
          "parameterGroups": {

          },
          "id": "a4cfe856-91fd-4ed8-9246-7db5e0b1ab07",
          "name": "Flow",
          "detail": "Default",
          "extensionId": "mulesoft:flow:4.0-SNAPSHOT",
          "configurationId": null,
          "elementId": "mulesoft:flow:4.0-SNAPSHOT:~:default",
          "operation": "default",
          "children": [
            {
              "parameterGroups": {
                "General": {
                  "path": {
                    "id": null,
                    "value": "\/",
                    "expression": false,
                    "typeId": ""
                  }
                }
              },
              "id": "4e0762e7-9f0f-4a94-8c4d-214df109bbf3",
              "name": "Listener",
              "detail": "Listener",
              "extensionId": "org.mule.connectors:mule-http-connector:1.0.0",
              "configurationId": "4e42ad99-137a-4818-b41b-8df1f8f2dc98",
              "elementId": "org.mule.connectors:mule-http-connector:1.0.0:listenerConfig:listener",
              "operation": "listener",
              "children": [

              ],
              "kind": "source",
              "trigger": false,
              "lastUpdated": 1515611102711
            },
            {
              "parameterGroups": {
                "URI Settings": {
                  "url": {
                    "id": null,
                    "value": "http:\/\/google.com",
                    "expression": false,
                    "typeId": ""
                  }
                }
              },
              "id": "573c2ebe-66d0-4df1-a38a-69a70253feee",
              "name": "Request",
              "detail": "Request",
              "extensionId": "org.mule.connectors:mule-http-connector:1.0.0",
              "configurationId": "b89da2de-82f8-41c8-a7f5-7c8b52748653",
              "elementId": "org.mule.connectors:mule-http-connector:1.0.0:requestConfig:request",
              "operation": "request",
              "children": [

              ],
              "kind": "operation",
              "trigger": false,
              "lastUpdated": 1515611143050
            }
          ],
          "kind": "scope",
          "trigger": false,
          "lastUpdated": 1515611015255
        }
      }
    ],
    "dependencies": [
      {
        "groupId": "org.mule.connectors",
        "artifactId": "mule-http-connector",
        "version": "1.0.0",
        "classifier": "mule-plugin"
      }
    ],
    "enrichers": {},
    "catalogs": {},
    "topLevelElements": [],
    "metadata": {
      "runtimeVersion": "4.0.0",
      "elements": [
        "org.mule.connectors:mule-http-connector:1.0.0:listenerConfig:listener",
        "org.mule.connectors:mule-http-connector:1.0.0:requestConfig:request"
      ],
      "cacheAssetId": null,
      "resources": [ ],
      "externalLibraries": [],
      "nodesMetadata": {},
      "projectModelVersion": "1.3.0-SNAPSHOT"
    },
    "deleted": false,
    "revision": 0,
    "version": "1.0",
    "description": null,
    "createdBy": "Mozart",
    "createdDate": "2018-01-10T19:03:32",
    "lastUpdatedDate": "2018-01-10T19:05:43"
  }

The curl statement will look like:

curl -H 'Authorization: Bearer <token>' -H 'x-session-id: <token>' -d '{json payload}' -X PUT https://anypoint.mulesoft.com/designcenter/api/v1/organizations/{orgId}/projects/{projectId}

The response should be a 200 status, returning in the project wrapper, in the result the will be the updated project.

4. Run the application
To run the application, it needs to be deployed, this is achieved by performing a
POST operation to projects/{projectId}/worker/start. The response will have the status of the worker. Once the application is deployed you can start listening to the logs and the messages that go through the processors.

curl -H 'Authorization: Bearer <token>' -H 'x-session-id: <token>' -X POST https://anypoint.mulesoft.com/designcenter/api/v1/organizations/{orgId}/projects/{projectId}/worker/start

Once the application is deployed, the worker status will be like the following:

{
  "id": <deployId>,
  "status": "STARTED",
  "reason": null,
  "projectId": <projectId>,
  "organizationId": <orgId>,
  "environmentId": <envId>,
  "workerName": <workerName>,
  "workerHostName": "<workerHostName>,
  "createdOn": <date>,
  "runtime": "4.0.0",
  "lastUpdatedTime": <date>
}

When the worker is deployed, you can view the logs and the messages that go through the application.

To view the logs:

curl -H 'Authorization: Bearer <token>' -H 'x-session-id: <token>' https://anypoint.mulesoft.com/designcenter/api/v1/organizations/{orgId}/projects/{projectId}/worker/logs

To view the messages:

curl -H 'Authorization: Bearer <token>' -H 'x-session-id: <token>' -X POST https://anypoint.mulesoft.com/designcenter/api/v1/organizations/{orgId}/projects/{projectId}/worker/try-it/consume

5. Delete Project
We will delete the project once we have finished working with it.

curl -H 'Authorization: Bearer <token>' -X DELETE https://anypoint.mulesoft.com/designcenter/api/v1/organizations/{orgId}/projects/{projectId}

The response should be a 200 status.


Reviews