Java Spring Boot Framework Provides an easy way to interact with the API. It can call any application Base API and process the Response according to our needs. This article explains how we can invoke Anaplan Rest API using Java Spring Boot Framework.
To start with, we must install the below software and SDE to run the application: STS: Spring Tool Suite Java: Java 1.8 would be the preferred version. Postman: This is a tool to test APIs.
Since we are using Spring framework, we need to install Spring Tool Suite as an IDE to develop Spring applications. It is an Eclipse-based development environment. It provides a ready-to-use environment to implement, run, deploy, and debug the application. It validates our application and provides quick fixes for the applications.
In a similar way, you can download Java 8 and Postman to test the API we have created.
Spring Boot is built on the top of the Spring Framework. It provides an easier and faster way to set up, configure, and run both simple and web-based applications
It is a Spring module that provides the Rapid Application Development (RAD) feature to the Spring Framework. It is used to create a stand-alone, Spring-based application that you can just run because it needs minimal Spring configuration. All the dependencies required for the project can be mentioned in the pom.xml file.
Spring provides a quick way to generate your project with the required configuration and dependencies and download as a zip file at start.spring.io.
Once the project has download, import the project as existing maven projects in STS.
Select file and import the project.
Import as existing maven projects.
Select the folder path where we have downloaded the project.
Spring web dependency helps to develop a custom API. In our project, we are creating each custom API to perform the below operations and test them using Postman.
Run an import action.
Run a process.
Run an export action.
Run a delete action.
For all the system API calls, Spring web dependency provides Rest Template Package. We can use this to make the HTTP call.
Unlike Anaplan 1.3 API, 2.0 works based on token authentication. For each system API call, we must provide a token that expires after 30 minutes. We can generate the refresh token using the previous token which will again expire after 30 min. We can also expire the current token once we no longer need the token.
To get the token for the first time, we have to make an authenticate HTTP call by providing a username and password.
We can save our username, password workspace id, and model id in the properties file.
Below is the code snippet to fetch the token and expire the token.
Set the username and password as HTTP Headers and make HTTP call using Rest Template. We will get the token as a response and mapped to Authentication Response Object & Return the token value.
To successfully log out, pass the current token as header and make a Post call.
We are making a token API call before calling Anaplan Operation System API (Upload, Import,…) and logout API call after that.
Now, we will define our custom API for most of the Anaplan operations.
AnaplanOperationsController class will be defining our custom API definition with the required parameters and call the service method.
AnaplanOperationsService class will have different methods to call Anaplan System API.
Below is the code explanation on how we can upload the file using our Custom API.
Create a method in the controller class which will have the field as the URL parameter and request body as the data we want to upload the file.
In the service layer class, provide your logic implementation.
Get the token value by calling the user token method where we are performing an HTTP call to get the user token. Once we get the token, add it to the HTTP headers along with content-type.
Then, perform the Anaplan System Upload HTTP call by passing upload URL, HTTP Method, File data to the RestTemplate as parameters.
We can get to know whether the upload operation is successful or failure by status code.
Once we get the status, invalidate the token that we have used, using the logout user.
Now we can test the code implementation by calling our custom API.
File Upload needs a file ID and the data we need to upload as an input. Make sure the delimiter we have chosen in Anaplan is the same for the data we are uploading, separated by comma or tab, depending on what we have chosen in Anaplan.
In a similar way, we can invoke other Anaplan System APIs. Code implementation is in the demo project file.
Run an import action.
Once we have uploaded the file, the data needs to be reflected in the module. To achieve this, we need to run an Import Action. To run an Import Action, we need the Import Id. Get the Import ID using the below API and use it in our custom API. In response, we will get the Success Message after the import action has completed.
We can run a process adding Import Action to the process. To run a process, we require a Process ID. Get Process ID by using the below API and use it in our Custom API. In response, we will get the Success Message once the process action has completed.
To run an Export Action, we need an Export ID which we will get from Anaplan Export API. Once the Export Action has completed, it will send the success message. We can customize the code in a way to check whether Export has completed or not, by calling Action Status API.
Here we have used Postman to test out custom API implementation. In a similar way that we have created for Anaplan, we can create endpoints and method logic for the source application (Salesforce, Any Database, NetSuite) and call those methods and transform the data to our needs, and we can send data into Anaplan using the above approach. We can use the above implementation as an alternative approach for an integration solution, instead of using an integration tool.
Note: All the above implementations are to show how to call the Anaplan Rest API using java Spring Boot Framework. We can make it more customized for every action, depending on our needs of the application.
The content in this article has not been evaluated for all Anaplan implementations and may not be recommended for your specific situation.
Please consult your internal administrators prior to applying any of the ideas or steps in this article.