API: Analysts
The following article will cover how to use the API to configure Analysts.
Creating an analyst and adding them to a report
To create an analyst, you should POST to ~/api/v2/analysts. You can also edit the analyst with PUT ~/api/v2/analysts/{id}.
If the analyst already exists, you can look them up with GET ~/api/v2/analysts.
Please note that analysts aren’t required to be unique, so you should check for any existing similar analysts for the best possible search experience for users.
You can then update the analysts who are associated with a product by calling PUT ~/api/v1/libraries/reports/products/{productCode}/analysts.
Beware that this disassociates all other analysts from the product - you must include all analysts in all new requests.
See examples below:
Bash
!/bin/bash baseUrl=$1
authHeader=$2
forenames=$3
surname=$4
productCode=$5
# Create the analyst and extract the created id
body=$(jo forenames=$forenames surname=$surname)
id=$(curl -s -X POST "${baseUrl}api/v2/analysts" -H "accept: application/json" -H "Content-Type: application/json" -H "Authorization: Basic $authHeader" -d $body | jq -r '.id')
# And add it to a report
body=$(jo analysts=$(jo -a $id))
curl -s -X PUT "${baseUrl}api/v1/libraries/reports/products/${productCode}/analysts" -H "accept: application/json" -H "Content-Type: application/json" -H "Authorization: Basic $authHeader" -d $body
C#
using System.Collections.Generic;
using AnalystForm = IO.Swagger.v2.Model.AnalystForm;
public void AddAnalystToReport(string forename, string surname, string productCode)
{
// Create the analyst
var v2ProductsClient = new v2.Api.ProductsApi(_v2Configuration);
var analyst = v2ProductsClient.AnalystsPost(new AnalystForm(forename, surname));
// And add it to a report
var v1ProductsClient = new v1.Api.ProductsApi(_v1Configuration);
var form = new v1.Model.ProductAnalystsForm(new List<string> {analyst.Id});
v1ProductsClient.LibrariesReportsProductsProductCodeAnalystsPut(productCode, form);
}
Uploading a Cover Photo
For speed and reliability, we require cover photos to be uploaded to a dedicated storage domain. You can get the location of this by calling GET at ~/api/v1/analyst-cover-photo-upload-url.
You can then upload your photo to the provided location (it’s a different location for each request) by making a PUT request, where the Content-Type header is the mimetype of the file (e.g. image/png for .png files) and the body contains the raw bytes of the file.
Finally, you need to tell iContent Catalyst the file is ready by calling PUT at ~/api/v1/analyst-cover-photo-upload-finalize/{name}.
We will return an ID which can be used when adding or updating an analyst.
(The newCoverPhoto property is deprecated and can be safely ignored.)
See examples below:
Bash
#!/bin/bash
baseUrl=$1
authHeader=$2
analystId=$3
filePath=$4
fileMimeType=$5
# Get the location to upload the file
response=$(curl -s -X GET "${baseUrl}api/v1/analyst-cover-photo-upload-url" -H "accept: application/json" -H "Authorization: Basic $authHeader")
coverName=$(echo -n $response | jq -r '.name')
coverUploadUrl=$(echo -n $response | jq -r '.url')
# Upload the file to the provided location (Note the @ makes --data-binary read the file specifed in $filePath)
curl -s -X PUT $coverUploadUrl -H "Content-Type: $fileMimeType" --data-binary "@$filePath"
# Notify the site the upload is complete
coverId=$(curl -s -X PUT "${baseUrl}api/v1/analyst-cover-photo-upload-finalize/$coverName" -H "accept: application/json" -H "Authorization: Basic $authHeader" -d {} | jq -r '.id')
# Get the existing analysts metadata, merge in the cover photo id and PUT it
analyst=$(curl -s -X GET "${baseUrl}api/v2/analysts/$analystId" -H "accept: application/json" -H "Authorization: Basic $authHeader" | jq --arg coverPhoto $coverId '. + {coverPhoto: $coverPhoto}')
curl -s -X PUT "${baseUrl}api/v2/analysts/$analystId" -H "accept: application/json" -H "Content-Type: application/json" -H "Authorization: Basic $authHeader" -d $analyst
C#
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using AnalystForm = IO.Swagger.v2.Model.AnalystForm;
public async Task UploadAnalystPhotoAsync(string analystId, string filePath, string fileMimeType)
{
// Get the location to upload the file
var v1ProductsClient = new v1.Api.ProductsApi(_v1Configuration);
var uploadLocation = v1ProductsClient.AnalystCoverPhotoUploadUrlGet();
// Upload the file to the provided location
using (var httpClient = new HttpClient())
{
var content = new ByteArrayContent(File.ReadAllBytes(filePath))
{
Headers = {ContentType = MediaTypeHeaderValue.Parse(fileMimeType)}
};
await httpClient.PutAsync(uploadLocation.Url, content).ConfigureAwait(false);
}
// Notify the site the upload is complete
var coverPhoto = v1ProductsClient.AnalystCoverPhotoUploadFinalizeNamePut(uploadLocation.Name);
// Get the existing analysts metadata, merge in the cover photo id and PUT it
var v2ProductsClient = new v2.Api.ProductsApi(_v2Configuration);
var analystModel = v2ProductsClient.AnalystsIdGet(analystId);
var analystForm = new AnalystForm(analystModel.Forenames, analystModel.Surname, analystModel.JobTitle, analystModel.Sector, analystModel.Biography, coverPhoto.Id);
v2ProductsClient.AnalystsIdPut(analystId, analystForm);
}