Skip to main content

Actions

The ballerinax/wso2.apim.catalog package exposes the following clients:

ClientPurpose
ClientManage WSO2 APIM Service Catalog entries: CRUD, definition retrieval, usage lookup, import/export, and settings.

Client

Manage WSO2 APIM Service Catalog entries: CRUD, definition retrieval, usage lookup, import/export, and settings.

Configuration

FieldTypeDefaultDescription
serviceUrlstring"https://apis.wso2.com/api/service-catalog/v1"WSO2 APIM Service Catalog REST endpoint URL. Passed as the second argument to init, not part of ConnectionConfig.
authOAuth2PasswordGrantConfigRequiredOAuth 2.0 Password Grant configuration containing tokenUrl, username, password, and optionally clientId, clientSecret, and scopes.
auth.tokenUrlstring"https://localhost:9443/oauth2/token"WSO2 APIM OAuth2 token endpoint URL.
auth.usernamestringRequiredWSO2 APIM admin username.
auth.passwordstringRequiredWSO2 APIM admin password.
auth.clientIdstring()OAuth2 client ID obtained from Dynamic Client Registration.
auth.clientSecretstring()OAuth2 client secret obtained from Dynamic Client Registration.
httpVersionhttp:HttpVersionHTTP_2_0HTTP protocol version for requests.
timeoutdecimal60Request timeout in seconds.
retryConfighttp:RetryConfig()Retry configuration for failed requests.
secureSockethttp:ClientSecureSocket()SSL/TLS configuration for mutual TLS or custom server certificates.
proxyhttp:ProxyConfig()Proxy server configuration.
validationbooleantrueEnable or disable constraint validation on request and response payloads.

Initializing the client

import ballerinax/wso2.apim.catalog;

configurable string serviceUrl = "https://localhost:9443/api/service-catalog/v1";
configurable string tokenUrl = "https://localhost:9443/oauth2/token";
configurable string username = ?;
configurable string password = ?;
configurable string clientId = ?;
configurable string clientSecret = ?;

catalog:Client catalogClient = check new ({
auth: {
tokenUrl: tokenUrl,
username: username,
password: password,
clientId: clientId,
clientSecret: clientSecret
}
}, serviceUrl);

Operations

Service management

List services

Retrieves a paginated list of services registered in the Service Catalog, with optional filtering by name, version, definition type, or service key.

Parameters:

NameTypeRequiredDescription
namestringNoFilter services by name (partial or exact match).
versionstringNoFilter services by version.
definitionType"OAS"|"WSDL1"|"WSDL2"|"GRAPHQL_SDL"|"ASYNC_API"NoFilter by API definition type.
'keystringNoFilter by service key (unique identifier string).
shrinkbooleanNoIf true, returns a condensed response with minimal fields. Default: false.
sortBy"name"|"definitionType"NoField to sort results by.
sortOrder"asc"|"desc"NoSort direction.
'limitintNoMaximum number of results to return. Default: 25.
offsetintNoNumber of results to skip for pagination. Default: 0.

Returns: ServiceList|error

Sample code:

catalog:ServiceList services = check catalogClient->/services(
definitionType = "OAS",
sortBy = "name",
sortOrder = "asc",
'limit = 10,
offset = 0
);

Sample response:

{
"list": [
{
"id": "01234567-0123-0123-0123-012345678901",
"name": "PizzaShackAPI",
"version": "v1",
"serviceKey": "PizzaShackAPI_v1",
"serviceUrl": "https://pizzashack-service.abc.com/v1",
"definitionType": "OAS3",
"securityType": "NONE",
"mutualSSLEnabled": false,
"usage": 2,
"createdTime": "2024-01-15T08:30:00.000Z",
"lastUpdatedTime": "2024-02-01T10:00:00.000Z"
}
],
"pagination": {
"offset": 0,
"limit": 10,
"total": 1,
"next": "",
"previous": ""
}
}
Create a service

Registers a new backend service in the Service Catalog with its metadata and optional API definition content.

Parameters:

NameTypeRequiredDescription
payloadcatalog:ServiceSchemaYesService metadata (serviceMetadata) and optionally a definition file (definitionFile) or inline definition string (inlineContent).

Returns: Service|error

Sample code:

catalog:ServiceSchema payload = {
serviceMetadata: {
name: "PizzaShackAPI",
version: "v1",
serviceUrl: "https://pizzashack-service.abc.com/v1",
definitionType: "OAS3",
securityType: "NONE"
},
inlineContent: "openapi: 3.0.0\ninfo:\n title: Pizza Shack API\n version: v1\n"
};
catalog:Service createdService = check catalogClient->/services.post(payload);

Sample response:

{
"id": "01234567-0123-0123-0123-012345678901",
"name": "PizzaShackAPI",
"version": "v1",
"serviceKey": "PizzaShackAPI_v1",
"serviceUrl": "https://pizzashack-service.abc.com/v1",
"definitionType": "OAS3",
"securityType": "NONE",
"mutualSSLEnabled": false,
"createdTime": "2024-01-15T08:30:00.000Z",
"lastUpdatedTime": "2024-01-15T08:30:00.000Z"
}
Get a service by ID

Retrieves the full metadata of a specific service from the Service Catalog using its unique identifier.

Parameters:

NameTypeRequiredDescription
serviceIdstringYesThe unique UUID of the service.

Returns: Service|error

Sample code:

catalog:Service svc = check catalogClient->/services/["01234567-0123-0123-0123-012345678901"]();

Sample response:

{
"id": "01234567-0123-0123-0123-012345678901",
"name": "PizzaShackAPI",
"version": "v1",
"serviceKey": "PizzaShackAPI_v1",
"serviceUrl": "https://pizzashack-service.abc.com/v1",
"definitionType": "OAS3",
"securityType": "NONE",
"mutualSSLEnabled": false,
"usage": 2,
"createdTime": "2024-01-15T08:30:00.000Z",
"lastUpdatedTime": "2024-02-01T10:00:00.000Z",
"md5": "d41d8cd98f00b204e9800998ecf8427e",
"definitionUrl": "https://localhost:9443/api/service-catalog/v1/services/01234567-0123-0123-0123-012345678901/definition"
}
Update a service

Replaces the metadata and/or definition of an existing service in the Service Catalog.

Parameters:

NameTypeRequiredDescription
serviceIdstringYesThe unique UUID of the service to update.
payloadcatalog:ServiceSchemaYesUpdated service metadata and optional definition file or inline content.

Returns: Service|error

Sample code:

catalog:ServiceSchema updatePayload = {
serviceMetadata: {
name: "PizzaShackAPI",
version: "v2",
serviceUrl: "https://pizzashack-service.abc.com/v2",
definitionType: "OAS3",
securityType: "OAUTH2"
},
inlineContent: "openapi: 3.0.0\ninfo:\n title: Pizza Shack API\n version: v2\n"
};
catalog:Service updated = check catalogClient->/services/["01234567-0123-0123-0123-012345678901"].put(updatePayload);

Sample response:

{
"id": "01234567-0123-0123-0123-012345678901",
"name": "PizzaShackAPI",
"version": "v2",
"serviceKey": "PizzaShackAPI_v2",
"serviceUrl": "https://pizzashack-service.abc.com/v2",
"definitionType": "OAS3",
"securityType": "OAUTH2",
"mutualSSLEnabled": false,
"createdTime": "2024-01-15T08:30:00.000Z",
"lastUpdatedTime": "2024-03-10T14:00:00.000Z"
}
Delete a service

Removes a service from the Service Catalog. The operation succeeds only if the service is not referenced by any existing APIs.

Parameters:

NameTypeRequiredDescription
serviceIdstringYesThe unique UUID of the service to delete.

Returns: http:Response|error

Sample code:

http:Response response = check catalogClient->/services/["01234567-0123-0123-0123-012345678901"].delete();

Service definition & usage

Get service definition

Retrieves the raw API definition content (e.g., OpenAPI YAML, WSDL XML) stored for the service.

Parameters:

NameTypeRequiredDescription
serviceIdstringYesThe unique UUID of the service.

Returns: string|error

Sample code:

string definition = check catalogClient->/services/["01234567-0123-0123-0123-012345678901"]/definition();

Sample response:

"openapi: 3.0.0\ninfo:\n  title: Pizza Shack API\n  version: v1\npaths:\n  /menu:\n    get:\n      summary: List menu items\n      responses:\n        '200':\n          description: OK\n"
Get service usage

Returns the list of APIs that reference this service in the Service Catalog, allowing you to assess service dependencies before making changes.

Parameters:

NameTypeRequiredDescription
serviceIdstringYesThe unique UUID of the service.

Returns: APIList|error

Sample code:

catalog:APIList usageList = check catalogClient->/services/["01234567-0123-0123-0123-012345678901"]/usage();

Sample response:

{
"count": 1,
"list": [
{
"id": "api-abcdef-1234-5678-abcd-ef0123456789",
"name": "PizzaShackAPI",
"context": "/pizzashack",
"version": "1.0.0",
"provider": "admin"
}
]
}

Import & export

Import services

Bulk-imports one or more services into the Service Catalog from a ZIP archive containing service definition files and metadata.

Parameters:

NameTypeRequiredDescription
payloadcatalog:Services_import_bodyYesMultipart form payload with a file field containing the ZIP archive (fileContent as byte[] and fileName as string), and an optional verifier string.
overwritebooleanNoIf true, existing services with matching keys are overwritten. Default: false.

Returns: ServiceInfoList|error

Sample code:

byte[] zipContent = check io:fileReadBytes("services-bundle.zip");
catalog:Services_import_body importBody = {
file: {fileContent: zipContent, fileName: "services-bundle.zip"}
};
catalog:ServiceInfoList result = check catalogClient->/services/'import.post(importBody, overwrite = true);

Sample response:

{
"count": 2,
"list": [
{
"id": "01234567-0123-0123-0123-012345678901",
"name": "PizzaShackAPI",
"key": "PizzaShackAPI_v1",
"version": "v1",
"md5": "d41d8cd98f00b204e9800998ecf8427e"
},
{
"id": "09876543-0987-0987-0987-098765432109",
"name": "PaymentService",
"key": "PaymentService_v2",
"version": "v2",
"md5": "a87ff679a2f3e71d9181a67b7542122c"
}
]
}
Export a service

Exports a service and its API definition as a ZIP archive, identified by service name and version.

Parameters:

NameTypeRequiredDescription
namestringYesThe exact name of the service to export.
versionstringYesThe exact version of the service to export.

Returns: byte[]|error

Sample code:

byte[] exportedZip = check catalogClient->/services/export(name = "PizzaShackAPI", version = "v1");

Sample response:

[80, 75, 3, 4, 20, 0, 0, 0, 8, 0]

Settings

Get settings

Retrieves Service Catalog configuration settings, including the list of OAuth2 scopes available for the current user.

Returns: Settings|error

Sample code:

catalog:Settings settings = check catalogClient->/settings();

Sample response:

{
"scopes": [
"service_catalog:service_view",
"service_catalog:service_write",
"apim:api_view"
]
}