This article discusses how to write and execute your program on Infosys Equinox using APIs and Java SDK.
Overview
The Infosys Equinox Commerce platform provides a rich set of e-commerce capabilities. Built using modern REST APIs it is both powerful and easy to use. This article will walk you through the basic steps necessary to login in and call a simple function of the platform. A “Hello, world” for e-commerce.
Prerequisites
Business and Store
Before you can complete this exercise, you will need access to a Infosys Equinox Business and Store, the basic building blocks of the Commerce platform. For a private Infosys Equinox Business, Store, and Login for yourself and your team, send an email, including your name, company, and email address to devportal@infosysequinox.com. Once you have access to your Business, you need to login to the Business’ Admin User Console (for example, https://cloud.skavacommerce.com/admin/foundation/login) and collect the following information for your Business.
- The Business ID for your Store.
- The Business Secret Keys for your Business.
- The API Gateway Key for your Business.
- The Store ID for your Store.
- A valid Customer for your Store.
You need to perform these steps:
- Login to the instance for the Business and Store that you will use for testing using for testing. Login will take you to the page of Businesses for which you have access.
- Click the Business that you will use for testing, InfosysEquinoxEnablement, for example:
Note the Business ID for the Business (for example, 75) you will use for testing.
- Click the Keys & Credentials tab:
- Click the Show buttons for the Business Secret Keys and API Gateway Keys for the Business.
- Select, copy, and save both sets of keys:
- Create a Customer on your Store (using your name and email address):
- Navigate back to Businesses using the top left menu.
- Click the Stores tab. Note the Store ID of the Store that you will use for testing (for example, 206).
- Click the > at the right of the line for the testing Store that you will use for testing, InfosysEquinoxEnablement Store, for example:
- Click the Store Ops button:
- Click the Customers microservice option:
- Click the Add Customer button at the top right hand side of the screen:
- Complete the fields on the Add Customer modal.
- Click the Send Invite button:
Your customer account will be listed as “Pending”:
- Activate your Account. See slide 31 in the Customers (User) MS Presentation for instructions for Manually Activating a Customer Account.
Simple Maven Project
You can either create a simple Maven project, or load the full one from Infosys Equinox’s BitBucket repository at https://bitbucket.org/skava-admin/sfologinsample/src/master/. For access to the repository, please send an email, including your name, company, and email address to devportal@infosysequinox.com. Note: The Storefront Orchestration (SFO) login sample on the BitBucket repository includes a POM file. If you create your own Maven project, you will need:
<dependencies> <dependency> <groupId>com.skava.orchestration</groupId> <artifactId>orchestration</artifactId> <version>8.14.5.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>4.3.9.RELEASE</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>${jackson-version}</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>${jackson-version}</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>${jackson-version}</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.jaxrs</groupId> <artifactId>jackson-jaxrs-json-provider</artifactId> <version>${jackson-version}</version> </dependency> <dependency> <groupId>com.github.joschi.jackson</groupId> <artifactId>jackson-datatype-threetenbp</artifactId> <version>${jackson-threetenbp-version}</version> </dependency> <dependency> <groupId>org.unbescape</groupId> <artifactId>unbescape</artifactId> <version>1.1.6.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson --> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.5</version> </dependency> <!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt --> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt</artifactId> <version>0.9.0</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-core</artifactId> <version>5.1.5.RELEASE</version> </dependency> <dependency> <groupId>com.skava</groupId> <artifactId>catalogservices</artifactId> <version>8.14.5.RELEASE</version> </dependency> </dependencies>
You will probably need to update your Maven install to properly access the skava.sdk. Find instructions here: Setting Up for Development.
Hello World!
Logging In
The following code (in the sample project) allows you to login in on behalf of a user and get a session key you can use to make calls for that user. This code uses Infosys Equinox’s Java SDK to call the storefront orchestration endpoint and login in a user.
// This block sets up the SDK to call our instance. // We need a Resttemplate to connect to the instance // We need an api-key to penetrate the firewall. You should update it to match your instance, it is found on the admin business page. // These are ignored in the base call
Map<String, String> myMap = new HashMap<String, String>(); myMap.put(“identity”, Identity); myMap.put(“password”, Password); JSONObject jsonObject = new JSONObject(myMap); HttpHeaders headers = new HttpHeaders(); headers.setAccept(java.util.Arrays.asList(MediaType.APPLICATION_JSON)); HttpEntity<String> entity = new HttpEntity<>(jsonObject.toString(), headers); ResponseEntity<String> result = resttemplate.postForEntity(OrchestrationUrl + Storeid, entity, String.class); JSONObject obj = new JSONObject(result.getBody()); String sessionid = obj.getString(“sessionId”); System.out.println(“Valide Login,SessionId : ” + sessionid); return result; }
Passwords and Hashing
You will notice a routine that hashes the password you enter. Infosys Equinox’s Customers (User) microservice handles passwords as strings, and, at the API level, does not enforce a specific hash or salt. Passwords should not be sent over the internet nor managed in plaintext whenever possible. The Infosys Equinox front end hashes passwords before sending them over the wire, so we hash the password the Customer presents in the same fashion. The code for hashing passwords is included in the sample project.
Running the Login Code
Insert the API key, storeId, userid, and password to your code. When you run it, your output should look like this:
Enter your Username; <email address> Enter your Password; <password> Enter your Storeid; <store ID> log4j:WARN No appenders could be found for logger (org.springframework.web.client.RestTemplate). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. Valide Login,SessionId : 42aa70a6f7f1dbba461a4e1639b8e285
Using the Session Key
Once we have the session key, we can use it to call any Customer function in the storefront orchestration (SFO). For example, we can retrieve information about the Customer we logged in.
public void getCustomer(ResponseEntity<String> result, String storeid) { try { HttpHeaders respHeaders = new HttpHeaders(); respHeaders.put("Cookie", result.getHeaders().getValuesAsList("set-cookie")); String customerdetails = "https://cloudapi.skavacommerce.com/orchestrationservices/storefront/customers?storeId="; HttpEntity<String> entity1 = new HttpEntity<>("parametres", respHeaders); ResponseEntity<String> result1 = resttemplate.exchange(customerdetails + storeid, HttpMethod.GET, entity1, String.class); System.out.println("Customer Details: " + result1); } catch (Exception e) { e.printStackTrace(); } }
This code, when run, should yield a result similar to:
Customer Details: <200 OK,{"id":668540,"firstName":"<firstname>","lastName":"<lastname>","email":"<email address>","phoneNumber":"<phone number>","userName":null,"dateOfBirth":null,"gender":"<gender>","photo":null,"userrole":null,"customProperties":{},"address":null,"payments":null,"accounts":null}
Congratulations! You have successfully authenticated a Customer (User), and called the Infosys Equinox system on their behalf.
Common problems
If you don’t properly set up the API Key, Business, or Store, you will get errors when running the code samples. Here are some common errors:
Invalid or missing api-key
If you fail to provide a valid API Key, your request will be rejected by the Web Application Firewall (WAF) at the entry point to the Infosys Equinox implementation, with a response similar to:
Starting customer driver Error 403 when calling login {"message":"Forbidden"}
Invalid or missing storeId
If you fail to provide a valid Store ID, but do have a valid API Key, your request will be rejected with a response similar to:
Starting customer driver Error 404 when calling login {"code":"EO0001","message":"Invalid Store Id","timeStamp":1560184839703}
Revision History
2023-07-06 | JP – Updated the content for SDK.
2022-06-15 | JP – Updated the content.
2022-04-10 | JP – Fixed link and http issues.
2020-11-26 | JP – Updated for Release 8.9.3
2020-06-17 | JP – Updated for Release 8.8.1
2020-03-27 | JP – Minor edits.
2020-02-25 | JP – Content updated for Release 8.6.0.
2019-06-10 | PLK – Content uploaded.
2019-06-03 | PLK – Page added.