How to extract an app icon

This REST API extracts raw icon from a file containing icon data. The file can be an exe, ico, png, bmp or any other format containing icon data. The base64 string returned by this API needs to be passed to the API when publishing a catalog application.

Add apps to a catalog documentation.

Steps

REST Example

This example illustrates how to get icon data in base64 string format from a file using REST API.

Request

GET https://api-us.cloud.com/catalogservice/{customerId}/{siteId}/icons HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: CwsAuth bearer=<token-from-prerequisites>

{
  "FileName": "string",
  "IconFileBytes": "string"
}

Interpreting the request

Property name Description
FileName [Optional] This is used for logging purpose only. This can be set to any string.
IconFileBytes [Required] The data of the file containing icon data represented as a JSON string.

Response

HTTP/1.1 200 OK
Content-Length: 63254
Content-Type: application/json; charset=utf-8
Date: "Tue, 26 September 2017 21:24:11 GMT"

"AAABAAcAAAAAAAEAIABnYQAAdgAAADAwAAABAAgAqA4AAN1hAAAwMAAAAQA..."

Interpreting the response

The response is a string in base64 format containing raw icon data. This is the icon string that needs to be passed to the API when publishing a custom (publish by path) application or updating a published application.

PowerShell Example

This example illustrates how to get icon data in base64 string format from a file using PowerShell.

function ExtractIcon {
  param (
    [Parameter(Mandatory=$true)]
    [string] $customerId,
    [Parameter(Mandatory=$true)]
    [string] $siteId,
    [Parameter(Mandatory=$true)]
    [string] $bearerToken,
    [Parameter(Mandatory=$true)]
    [string] $jsonBody
  )
  $requestUri = [string]::Format("https://api-us.cloud.com/catalogservice/{0}/{1}/icons", $customerId, $siteId)
  $headers = @{"Accept"="application/json";
               "Content-Type"="application/json"
               "Authorization"="CwsAuth bearer=$bearerToken"}

  $response = Invoke-RestMethod -Uri $requestUri -Method POST -Headers $headers -Body $jsonBody
  return $response
}

$customerId = "customer1" #Replace with your customerId
$siteId = "61603f15-cdf9-4c7f-99ff-91636601a795" #Replace with your site ID
$bearerToken = "ey1.." #See Prerequisites for all API calls section for a sample of how to get your bearer token

$bytes = [System.IO.File]::ReadAllBytes("C:\temp\chrome.exe") #Replace with your file path

$body = @{
  "FileName" = "Google Chrome";  #This is used for logging purpose only. This can be any string
  "IconFileBytes" = $bytes;
}

$response = ExtractIcon $CustomerId $siteId $bearerToken (ConvertTo-Json $body)
<!--NeedCopy-->

C# Example

This example illustrates how to get icon data in base64 string format from a file using C#.

public class ExtractIconModel
{
    /// <summary>
    /// The name of the file that contains the image. This is only used for logging purpose. This can be set to any string.
    /// </summary>
    public string FileName { get; set; }

    /// <summary>
    /// The bytes of the file that contains the icon to be extracted
    /// </summary>
    public byte[] IconFileBytes { get; set; }
}

public static async Task<string> ExtractIcon(
    string customerId,
    string siteId,
    string bearerToken,
    ExtractIconModel model)
{
    var requestUri = string.Format("https://api-us.cloud.com/catalogservice/{0}/{1}/icons", customerId, siteId);
    using (var client = new HttpClient())
    {
        client.DefaultRequestHeaders.Accept.ParseAdd("application/json");
        client.DefaultRequestHeaders.Authorization =
                   new AuthenticationHeaderValue("CwsAuth", "Bearer=" + bearerToken);

        var jsonBody = JsonConvert.SerializeObject(model, new JsonSerializerSettings
        {
            Converters = new JsonConverter[] { new StringEnumConverter() }
        });

        var response = await client.PostAsync(requestUri, new StringContent(jsonBody, Encoding.UTF8, "application/json"));

        if (response != null)
        {
            var content = await response.Content.ReadAsStringAsync();
            return content;
        }

        return null;
    }
}
<!--NeedCopy-->
Resources
Citrix Virtual Apps Essentials OpenAPI Specification
Copy Download
How to extract an app icon