This document describes the ClaimShop File Service API. This API can be used to download the file data using GUID.
Main consumer of this API is insurance company.
The process of downloading file data can be divided into two steps:
You need an access_token
in order to download file data from Fileservice Endpoint. This access token can be obtained from the Authentication Endpoint. Please refer to the documentation about details of authentication process.
API caller should request files:read
scope from Authentication Endpoint.
The endpoint which allows to download file data using file GUID in the following format:`
https://fileservice.scalepoint.com/api/fs/files/{locale}/{tenant}/{GUID}
Here {GUID} is the unique file id which uniquely identifies the file.
The actual format of this will depend on the insurance company, the country in which it operates and the version of the API.
Assuming the following:
Denmark
ABC Insurance
Budget Insurance
The endpoint could look something like this:
https://fileservice.scalepoint.com/api/fs/files/dk/abcinsurance/d1a72df4-f7d5-402c-a495-cc31b8b39a59
For testing purposes, you will be given access to a project server and the hostname-part of the endpoint would change accordingly:
https://<hostname>/api/fs/files/dk/abcinsurance/d1a72df4-f7d5-402c-a495-cc31b8b39a59
Please discuss with your account manager, which project server you have been assigned in order to determine the actual endpoint.
File download data GET request contains request parameters as a part of endpoint URL (see above) and authorization.
Authorization header has name 'Authorization'. It has value built from access_token
in following format:
Bearer access_token
Note the important space character between Bearer
and access_token
value.
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
File download data GET response contains file information fields in JSON format in case of success (HTTP status code 200). Please see the response schema for details.
Simplest successful response example:
{
"fileGUID": "A3751142-D95E-471B-95B1-7266EECE760D",
"fileExtension": "jpg",
"fileContentType": "image/jpeg",
"originalSize": 78495,
"content": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAQEBAQEBAQEBAQGBgUGBggHBwcHCAwJCQkJCQwTDA4MDA4MExEUEA8QFBEeFxUVFx4iHRsdIiolJSo0MjRERFwBBAQEBAQEBAQEBAYGBQYGCAcHBwcIDAkJCQkJ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JUeytfolaaE3Da61E7Jg4Zf7dxTt5bsf6TXIz/wBTWXgELgT9usSAKlAEPPewhBBoK23w+CCB1KvwgbF5BafubwsqTq/zCaB135+iWldEA1/xBpW6GcPuABLaiLX1EynKB9qCCJOtfxVwnSHCHf4jBHsP+H/Af8CPv+BwjwnRP+kefyTmRw/Zx+o9Q/yH4/xH/Cf6Cf8ALP8Aen+j/wCf4Z0/J/vf8N4/pP8A4fuf/B9zv/AN/pk6/wAyn/f/AJ4/950j1P/Z"
}
In case of error response JSON can be ignored - instead HTTP status code should be used to determine error type.
Below you could find an example Java code on how to download the file. File service REST API returns above JSON format. The reason that you have to use unzipBytes method is to unzip the bytes you received in the content attribute. File types like JPG, PNG are not zipped but file types like xls and mp4 are zipped. So please use below code to download the files.
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.HttpClientBuilder;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Base64;
import java.util.Properties;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
public class FileServiceApiTest {
private String clientId;
private String tokenEndpointUri;
private CertificateWithPrivateKey keyPair;
private static final ObjectMapper mapper = new ObjectMapper();
private static HttpClient client = HttpClientBuilder.create().useSystemProperties().build();
private final String FILE_SERVICE_API_URI = "https://fileservice-project09.scalepoint.com/api/fs/files/dk/abcinsurance/%s";
private static final String FILES_SERVICE_API_SCOPE = "files:read";
@Test
public void downloadFile() throws IOException {
final String accessToken = "access token";
downloadFile("A3751142-D95E-471B-95B1-7266EECE760D", accessToken);
}
private HttpResponse getHttpResponse(String uri, String accessToken) throws IOException {
HttpGet request = new HttpGet(uri);
request.addHeader("Authorization", "Bearer " + accessToken);
HttpClientContext context = HttpClientContext.create();
return client.execute(request, context);
}
private void downloadFile(final String guid, final String accessToken) {
try {
final String formattedUri = String.format(FILE_SERVICE_API_URI, guid);
final HttpResponse httpResponse = getHttpResponse(formattedUri, accessToken);
JsonNode jsonResponse = mapper.readTree(httpResponse.getEntity().getContent());
final String content = jsonResponse.get("content").asText();
System.out.println("content = " + content);
byte[] contents = Base64.getDecoder().decode(content);
byte[] decompressedFile = unzipByte(contents);
System.out.println("decompressedFile = " + decompressedFile);
} catch (IOException | UnsupportedOperationException e) {
e.printStackTrace();
}
}
private static byte[] unzipByte(byte[] input) {
ByteArrayOutputStream result = new ByteArrayOutputStream(input.length);
Inflater decompresser = new Inflater();
byte[] buffer = new byte[2048];
try {
decompresser.setInput(input);
while (!decompresser.finished()) {
int length = decompresser.inflate(buffer);
if (length == 0) {
return result.toByteArray();
} else {
result.write(buffer, 0, length);
}
}
} catch (DataFormatException e) {
return input;
} finally {
decompresser.end();
}
final byte[] bytes = result.toByteArray();
return bytes;
}
}