Create Solution Article with Inline attachment

Can you create a solution with inline attachments via API? The img src is pointing to the attachment.freshservice.com, but it’s not listed as an attachments for the solution. Nothing in the documentation discusses inline images, just attachments to the solutions.

PS C:\Build\FreshservicePS> Get-FreshServiceSolutionArticle -folder_id 21000069691 -id 21001388799
                                                                                                                        
description                      : <p>Here is the error message:</p>
                                   <p><br></p>
                                   <p><img src="https://attachment.freshservice.com/inline/attachment?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MjEwMTc4NzA3OTIsImRvbWFpbiI6Iml0cy1maW5lLmZyZXNoc2VydmljZS5jb20iLCJ0eXBlIjoxfQ.ItmvlHLWrpXXPRYTRvAH0FPM5etY2Z429Oz6wWVGq4g"  
                                   style="width: auto;" class="fr-fil fr-dib" data-id="21017870792"></p>
                                   <p><br></p>
                                   <p><br></p>
group_folder_group_ids           : {}
folder_department_ids            : {}
group_folder_requester_group_ids : {}
group_folder_department_ids      : {}
attachments                      : {}
folder_visibility                : 1
id                               : 21001388799
created_at                       : 8/10/2023 6:14:38 PM
updated_at                       : 8/10/2023 6:14:38 PM
title                            : How to Fix Stuff
status                           : 1
user_id                          : 21000418005
source                           : agent_portal
approval_status                  : 
position                         : 5
folder_id                        : 21000069691
category_id                      : 21000045562
thumbs_up                        : 0
thumbs_down                      : 0
modified_by                      : 
modified_at                      : 8/10/2023 6:14:38 PM
inserted_into_tickets            : 0
url                              : 
workspace_id                     : 2
article_type                     : 1
views                            : 0
description_text                 :  Here is the error message:




keywords                         : {}
review_date                      : 
tags                             : {}
approvals                        : {}
cloud_files                      : {}

The goal is to programmatically migrate knowledge articles, which normally contain inline images:

No comments or suggestions?

Hello @rasimm ,
if I get it right, you want the inline attachment in the solution description to become also attachments of the solution object.
Is this the case?

Hi @Michele,

Yes, typically attachments are referenced inline and don’t see a way to do in the API. The workaround that I can see at this point is to leverage the email creation method here where a HTML email is transformed into a knowledge with attachment.

Email to kbase articles | Freshservice Knowledge Management : Freshservice

Hi @rasimm ,
I found myself in a similar situation, but it involved tickets and replies.
To send attachments I used Nodejs and the package Axios like described here

To get inline attachments you could also use cheerio to do some sort of web scraping of the description if there is a “img” tag, but I didn’t find a way to get the names of the images if it isn’t defined in the “img” tag, so you’ll have to use a dummy name.

In this example I needed to send the image as base64 string to another application, but you can skip the converstion from arraybuffer to string.

async function getInlineAttachment(description) {
    let urls = [];
    let inlineAttachmentsList = [];
    const $ = cheerio.load(description);
    $("div > img").each((i, element) => {
        const image = $(element).attr("src");
        urls.push(image);
    });

    for (const url of urls) {
        let count = 1;
        let res = null;
        try {
            res = await axios.get(url, { responseType: 'arraybuffer' });
        } catch (error) {
            console.log(error);
            //return error;
        }
        let content = res.headers['content-type'];
        let file = {
            data: Buffer.from(res.data, 'binary').toString('base64'),
            name: `image${count}.${content.slice(content.indexOf("/") + 1)}`
        };
        inlineAttachmentsList.push(file);
        count++;
    }

    return inlineAttachmentsList;

}

There are some tutorials (<-this isn’t a link to cheerio stuff, it’s something automatic that this forum does, I didn’t put a link in there) on how to use cheerio for webscraping in the web (even something on youtube).

I hope this helps.