How to run the Hello World API with X-Pay-Token (API Key - Shared Secret Authentication) on Postman

shameem
Visa Employee

How to run the Hello World API with X-Pay-Token (API Key - Shared Secret Authentication) on Postman

Note: Postman cannot run X-Pay-Token at the same time as Mutual-SSL

Make sure you remove certificate before you run X-Pay-Token Or download Postman and Postman Canary and use one for Mutual-SSL and second for X-Pay-Token

 

 

In this "How-to" guide we will show you how to run the “Hello World” project using Visa Hello World API and and API Key - Shared Secret Authentication. The Hello World API is a simple API for testing the connectivity with the Visa Network.

 

Important Links:

 

How to Create a Visa Developer Project

 

Before you are able to run the “Hello World” Project, you must create a Visa Developer Portal (VDP) project and get credentials. If you haven't registered yet just click on register here, fill out the account information, agree to the terms and conditions and click on receive emails. Once you have successfully activated your account, you will see your dashboard and you are ready to go.

 

 

java1.png

 

 

Once you are there, click on create your first project if this is your first project.  On the next page, you will be asked for details, such as project name, description and a list of APIs to choose from.

 

 

Java2.png

 

For this tutorial, we're going to select CyberSource Payments and click create project.

 

 

CyberSourcePaymentMethod.png

 

 

 

How to get Credentials

 

After creating your project, you will be redirected to the project summary page. You can obtain your project credentials by browsing the left side navigation menu of your project and click on “Credentials”.

 

 

Java4.png

 

What is required for the X-Pay-Token Authentication?

 

To be able to make an API call with X-Pay-Token Authentication, you need to have the following:

  1. Api Key
  2. Secret Key

CredentialsForXPayToken.png

 

How to run the Hello World API with X-Pay-Token (API Key - Shared Secret Authentication) on Postman

 

Next, we'll show you how to run the “Hello World API” with X-Pay-Token on Postman.  Postman is a free and open source API development and testing solution, and can be can be downloaded using below link:

 

https://www.getpostman.com/

 

Step 1 - Launch Postman

 

  • Create a collection and named it "VISA" (or any other name)

2020-11-16_20-21-46.png

 

 

  • Create a new request by click on the "New" buttion and click "Request"

 

2020-11-16_20-23-15.png

 

  • Name the request "helloworld" and choose the collection name "VISA" or what the name you have provided.

 

2020-11-16_20-55-04.png

 

 

2020-11-16_20-57-14.png

 

Step 2 - Add "apiKey" query parameter

 

  • Click on the "Params" tab to add a new parameter

 

2020-11-17_10-17-40.png

 

 

KEY: apiKey

VALUE:  Please make sure to set your API Key

 

Step 3 - Add the "X-Pay-Token" header

 

  • Click on the "Headers" tab to add a new header

 

2020-11-17_10-28-52.png

 

KEY: x-pay-token

VALUE: {{x-pay-token}}

 

Step 4 - Add the "Pre-request" Script"

 

  • Click on the Pre-request Script Tab.
  • Copy and paste the below script. The script will generate the x-pay-token value and set it to the header "x-pay-token"

 

2020-11-17_10-20-44.png

 

 

var resourcePath = 'helloworld';
var queryParams = 'apiKey=<YOUR API KEY>';
var sharedSecret = '<YOUR SHARED SECRET>';
var postBody = '';

var timestamp = Math.floor(Date.now() / 1000);  
var preHashString = timestamp + resourcePath + queryParams + postBody;  
var hashString = CryptoJS.enc.Hex.stringify(CryptoJS.HmacSHA256(preHashString, sharedSecret));
var xPayToken = 'xv2:' + timestamp + ':' + hashString;

postman.setEnvironmentVariable('x-pay-token', xPayToken); 

 

 

  • Make sure to set your API Key and Shared Secret before running the test.

var queryParams = 'apiKey=<YOUR API KEY>';

var sharedSecret = '<YOUR SHARED SECRET>';

 

Step 4 - Make API Call

 

  • Click Send button to make the API Call. You should see the response in JSON

 

2020-11-17_10-30-03.png

 

 

 

Want more? Join the Visa Developer Community to get alerts on the latest tutorials, guides and new developer resources. Stay tuned for more in the series. 

 

Written by: @shameem@jmedlen, & @mprsic