Use the API to Include a Logo and Custom Summary on Reports

Coverity on Polaris

Version
latest
An Organization Administrator can use the API to upload a logo and summary text to be placed on the cover of every PDF report. The method varies slightly, depending on whether you are uploading for the first time or making a change to an existing record.

These requirements apply:

  • The logo image must be at least 202 KB and no more than 500 KB.
  • Acceptable file formats include JPG and PNG.
  • The image data must be Base64 encoded (many operating systems offer a utility that does this)
  • The summary text must consist of 500 characters or less.

To Upload Custom Information for the First Time

This method only works if a custom logo and text have not been uploaded before.
  1. Request organization information
    Why:
    • To get the customization id, which is required in subsequent steps.
    • To verify that a custom logo and text have not been uploaded by someone else.

    Request

    
    curl --location --request GET "https://{domain}.cop.blackduck.com/reporting/rs/v1/api/rs/organization/information" \
    --header "accept: application/vnd.api+json" \
    --header 'Authorization: Bearer {JWT}' \
                        
    About this request:
    • Replace {domain} with your own organization domain in the URL.
    • Replace {JWT} with your long-lasting web token.

    Response

    {
        "data": {
            "id": "8b29d4ee-4c83-4246-97f6-feb3cb8ee1c2",
            "type": "organization-information",
            "attributes": {
                "text": {
                    "enabled": false,
                    "value": "null"
                },
                "image": {
                    "enabled": false,
                    "value": null
                }
            }
        }
    }
                   
    About this response object:
    • If organization information has never been set before, the value parameter should be set to null, both for image and for text. If it has already been set and you want to change it, skip the next step, and instead use the instructions for updating company data (you need to use a PATCH request instead of a POST).
    • The id number required for the next step is in line 3 of the response above.
  2. Add the new record, including text and a logo.

    Request

    curl --location --request POST 'https://{domain}.cop.blackduck.com/reporting/rs/v1/api/rs/organization/information' \
    --header 'Content-Type: application/vnd.api+json' \
    --header 'Accept: application/vnd.api+json' \
    --header 'Authorization: Bearer {JWT}' \
    --data-raw '{
        "data": {
            "id": "8b29d4ee-4c83-4246-97f6-feb3cb8ee1c2",
            "type": "organization-information",
            "attributes": {
                "text": {
                    "enabled": true,
                    "value": "This report was created by Black Duck Docs"
                },
                "image": {
                    "enabled": true,
                    "value": "<insert_base_64_image_data_here>"
      }
                }
            }
        }
    }'
                            
                        
    About this request:
    • Replace {domain} with your own organization domain in the URL.
    • Replace {JWT} with your long-lasting web token.
    • This request uses a placeholder where the image data would go. (Encoded image data is extensive.)

    Response

    
    {
      "data":{
        "id":"8b29d4ee-4c83-4246-97f6-feb3cb8ee1c2",
        "type":"organization-information",
        "attributes":{
          "text":{
            "enabled":true,
            "value":"This report was created by the security group."
            },
            "image":{
              "enabled":true,
              "value":"data:image/png;base64,<base_64_image_data_here>"
            }
         }
       }
    }
                            
                        

    A successful response contains the information you uploaded.

To Update Custom Report Information

Use this procedure to change your custom information and text, except for the first time they are uploaded.
In this example, we only change the text.
  1. Request organization record
    Why:
    • To get the customization id, which is required in the next step.
    • To get the current text and image data, which you can update with your changes in order to make the request in the next step.

    Request

    
                                curl --location --request GET "https://{domain}.cop.blackduck.com/reporting/rs/v1/api/rs/organization/information" \
     -H "accept: application/vnd.api+json" \
    --header 'Authorization: Bearer {JWT}' 
                         
    About this request:
    • Replace {domain} with your own organization domain in the URL.
    • Replace {JWT} with your long-lasting web token.

    Response

    {
      "data":{
        "id":"8b29d4ee-4c83-4246-97f6-feb3cb8ee1c2",
        "type":"organization-information",
        "attributes":{
          "text":{
            "enabled":true,
            "value":"This report was created by the security group."
            },
            "image":{
              "enabled":true,
              "value":"data:image/png;base64,<base_64_image_data_here>"
            }
         }
       }
    }
    
    About this response:
    • The image data returned is slightly different from the request format. When you reuse the object in your request, include only the encoding you received when converting the image to Base64 and enclose it in quotation marks. Remove the string of metadata appended at the beginning of the image data ("data:image/png:base64").
  2. Update the record

    Request:

    curl --location --request PATCH "https://{domain}.cop.blackduck.com/reporting/rs/v1/api/rs/organization/information/8b29d4ee-4c83-4246-97f6-feb3cb8ee1c2" \
    --header 'Content-Type: application/vnd.api+json' \
    --header 'Accept: application/vnd.api+json' \
    --header 'Authorization: Bearer {JWT}' \
    --data-raw '{
        "data": {
            "id": "8b29d4ee-4c83-4246-97f6-feb3cb8ee1c2",
            "type": "organization-information",
            "attributes": {
                "text":{
                   "enabled":true,
                   "value": "This report was created by Black Duck."
                    },
                "image":{
                   "enabled":true,
                   "value":"<base_64_image_data_here>"
                }
            }
        }
    }'                            
                            
    About the request:
    • Replace {domain} with your own organization domain in the URL.
    • Replace {JWT} with your long-lasting web token.
    • The only change made is in the custom text. Now it says, "This report was created by Black Duck."
    • It's necessary to remove the metadata from data.attributes.image.value. That key is in the last line containing text in this request object. Compare to the response in the previous step.

    Response

    {
      "data":{
        "id":"8b29d4ee-4c83-4246-97f6-feb3cb8ee1c2",
        "type":"organization-information",
        "attributes":{
          "text":{
            "enabled":true,
            "value": "This report was created by Black Duck."
            },
            "image":{
              "enabled":true,
              "value":"data:image/png;base64,<base_64_image_data_here>"
            }
         }
       }
    }
    
                            

    A successful response returns the data you uploaded.