Need a break from the barriers of CRUD APIs on resources? Explore this new feature that’s available in the API flows of IBM App Connect.
When you create a flow for an API, you can now define custom operations on a resource (model) that are suitable for your business needs. There are various options for you to create multiple custom operations.
- You can choose from six different verbs for your custom API: GET, PUT, POST, PATCH, DELETE, and HEAD.
- By selecting the Use model_name ID check box, you can create instance APIs on the resource.
- You can customize the request and response model for your API by selecting from the predefined model on the API.
- You can set a unique operation name (relative path) for your API.
- There are optional query parameters that are part of the URL parameters.
- You can provide a description for your custom operation, which can be viewed in the Swagger definition.
Let’s work through a simple use case, which demonstrates how you can use the custom API features.
We want to provision an API that allows the API consumer to declare an opportunity in Salesforce as closed and add the name of the ‘closer’ as a comment. Note that this use case interacts with Salesforce only.
We first create an API with two models – Opportunity and Account – then define the properties that make up the model.
We then define a custom operation on the Opportunity model. For this example, the operation is to close an opportunity if the ID of the opportunity is known. We set the following properties:
- Set HTTP Verb to
- Set Operation name to
/close(the complete path would be
- Select Unique Opportunity ID
- Body Parameters:
- Specify the name and contact details of the person who’s authorizing the closure (Account model)
- Specify the full details of the closed opportunity (Opportunity model)
The next step is to implement the flow and do any necessary mapping, where we add any necessary actions or logic to achieve the expected behaviour. For example, a simple flow might use the Salesforce Replace or create opportunity action to update the opportunity that’s identified by the ID, and include the account and name of the closer from the incoming payload in comments.
The final step is to download the Swagger from the Manage tab and invoke the API.
Some additional points to consider:
- You can now define up to 10 models in an API.
- Any one of the models that have a complete implementation of an operation will allow a user to start the API.
To learn more, see Creating flows for an API