How to use Reputation Review Export API?
This is an example of how to consume the Review Export API bundle all together. Explaining how to use all the APIs to import data from PressGaney’s Reputation.
Introduction
The following are the steps which describe how to consume the Review Export API bundle all together.
For more information about how endpoints are used & their use cases, please refer to the Details of Reputation External Api
In order to export the Export Reviews or Export Deleted Reviews records, the API requires accessToken to be passed in headers while calling the endpoint.
AccessToken is a token which is used to fetch client related details based on the role provided.
For each role, the unique AppId and AppSecret will be generated, based on appId and appSecret, the accessToken
will be generated.
To know how to generate accessToken, please refer Endpoint to generate AccessToken from AppId & AppSecret
1.Generate Access Token
Refer the below code, which describes how to fetch accessToken in response by calling the create token endpoint.
//1.Generate Access Token
//Java Code Snippet to generate accessToken (from create token api) which is used to make all the api calls.
OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "appId={app_id}&appSecret={app_secret}");
Request request = new Request.Builder()
.url("https://api1.consumerism.pressganey.com/api/service/v1/token/create")
.method("POST", body)
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.build();
Response response = client.newCall(request).execute();
2.Fetch All Source Ids from Source Endpoint
Get the accessToken from Step 1, pass the accessToken in headers & call the endpoint. Refer block 2 form the java code snippet to call the Endpoint & consumes the sourceIds in the response. To know how the request & response behaves, please refer Source Export Details.|
//2.Fetch All Source Ids from Source Endpoint
//Java Code Snippet to fetch all possible sources which can be used as lookup values for source names to integer id and the same can be passed as filter in Fetch data api calls.
OkHttpClient client = new OkHttpClient().newBuilder().build();
Request request = new Request.Builder()
.url("https://api1.consumerism.pressganey.com/api/reputation/v1/sources")
.method("GET", null)
.addHeader("accessToken", "{accessToken}")
.build();
Response response = client.newCall(request).execute();
JSONArray array = new JSONArray(sourceResponse);
//Variable created to store the sourceIds
List<Integer> sourceIDList = new ArrayList<>();
//Iterating the source endpoint response
for(Object object : array){
if(object instanceof JSONObject){
//storing the sourceIds in List
sourceIDList.add((Integer) ((JSONObject) object).get("id"));
}
}
return sourceIDList;
3.Fetch all the feedback document details based on the sources
Get the accessToken from Step 1, pass the accessToken in headers. Get all the sourceIds from Step 2, and store the sourceIds in the List (Please note, sourceIds are Integers in the request). Refer block 3 from the java code snippet which is used to consume feedback documents along with documents details. To know how the request & response behaves, please refer Review Export Api
//3.Fetch all the review details based on the sources and dateRange passed.
//Java Code Snippet used to make api call to fetch list of all feedback details from review export api based on the filter inputs
OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\r\n \"sources\": [{sourceIds}],\r\n \"modifiedTimeFrom\": \"2011-01-03T23:59:59.345Z\",\r\n \"mentionTimeAfter\": \"2012-03-03T23:59:59.000Z\",\r\n \"offset\": 0,\r\n \"limit\": 1000\r\n}");
Request request = new Request.Builder()
.url("https://api1.consumerism.pressganey.com/api/reputation/v1/reviews")
.method("POST", body)
.addHeader("accessToken", "{accessToken}").addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
4. Fetch all the feedback deleted document details based on the sources
Get the accessToken from Step 1, pass the accessToken in headers. Get all the sourceIds from Step 2, and store the sourceIds in List (Please note, sourceIds are Integers in the request. Refer block 4 from the java code snippet which is used to consume deleted feedback details. For more info on how request & response behaves, please refer Export Deleted Documents
//4.Fetch all the feedback deleted document details based on the sources
//Java Code Snippet used to make api call to fetch list of all deleted document details based on the filter inputs
OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\r\n \"sources\": [{sourceIds}],\r\n \"modifiedTimeFrom\": \"2011-01-03T23:59:59.345Z\",\r\n \"offset\": 0,\r\n \"limit\": 1000\r\n}");
Request request = new Request.Builder()
.url("https://api1.consumerism.pressganey.com/api/reputation/v1/deleted-reviews")
.method("POST", body)
.addHeader("accessToken", "{accessToken}")
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
Run the process
Refer block 5 from the java code snippet,which shows an scenario on how to consume the review export api response and perform same operation by increasing the offset value, until we get the empty response.
/**
// Block used to fetch the feedback review details from the system
// By increasing the 'offSet' value until we receive all the records.
// Once all records being fetched, then updating 'modifiedTimeFrom' field with current time in order to perform same operation.
**/
//1: Perform Step1 'Generate Access Token' by passing 'appId' & 'appSecret' in request
//Here 'fetchAccessTokenByAppIdAndAppSecret' is java code method which contains Step1 code
String accessToken = fetchAccessTokenByAppIdAndAppSecret({app_Id}, "{app_Secret}");
//2: Perform Step2 'Get List of Source Ids'
// Here 'fetchSourceIdsByAccessToken' is a java code method which contains Step2 code
List<Integer> sourceIds = fetchSourceIdsByAccessToken("{access_Token}");
//Variable used to fetch feedback documents based on the 'modified_time' date of the documents
String modifiedTimeFrom = "yyyy-MM-dd’T'HH:mm:ss.SSS'Z’";
int limit = 1000;
int offset = 0;
Response response;
JSONArray reviewExportList = null;
do {
// 3: Perform Step 3 to fetch feedback details by passing sourceIds, modifiedTimeFrom, offSet, limit, accessToken
//Here 'fetchFeedbackExportDetails' is a java code method which contains Step3 code
reviewExportList = fetchFeedbackExportDetails(sourceIds, modifiedTimeFrom, offset, limit, accessToken);
offset = offSet + limit;
}
while(response.isEmpty() || response.size() < limit);
// Updating 'modifiedTimeFrom' with current date, as we have fetched the value from old one.
modifiedTimeFrom = new Date(); //Fetching the current date