Skip Navigation
Expand
Constructing the URL of an article attachment from the Knowledge Advanced REST API
Answer ID 11396   |   Last Review Date 04/02/2020

What is the URL to access a file attachment from an article retrieved via Content REST?

Environment:

Integrations using the Knowledge Advanced REST API v1

Resolution:

From the content object response, parse two values:

  1. The resourcePath.
  2. The filename(s) from the xml, which your application should URL encode.

Concatenate the resourcePath and desired filename together. If the attachment has a user group association, a kmauthtoken must be sent in the header with the GET request for the attachment.

Example:

A request to get the content:

curl --location --request GET --header 'Accept: application/json' \
--header 'kmauthtoken: {"localeId":"en_US", "siteName":"my_site", "integrationUserToken":"[token]"}' \
'https://my-site-irs.custhelp.com/km/api/v1/content/answers/1000247'
 

The necessary elements of the response (the XML will, of course, vary according to your content type schema):

{ [...],
"xml":"<DEMO><TITLE><![CDATA[Answer with attachment]]></TITLE>
    <CONTENT><TEXT><![CDATA[This article has an attachment.]]></TEXT>
    <ATTACHMENT SIZE=\"1095\"><![CDATA[five.png]]></ATTACHMENT></CONTENT></DEMO>",
"resourcePath":"https://my-site-as.custhelp.com/fas/resources/my_site/content/draft/002254d02a244016ff7c30645013c0/002254d02a244016ff7c30645013c7/"
}
 

Finally, the request for the attachment:

curl --location --request GET --output five.png \
--header 'kmauthtoken: {"localeId":"en_US", "siteName":"my_site", "integrationUserToken":"[token]"}' \
'https://my-site-as.custhelp.com/fas/resources/my_site/content/draft/002254d02a244016ff7c30645013c0/002254d02a244016ff7c30645013c7/five.png'
 

Available Languages for this Answer:

Notify Me
The page will refresh upon submission. Any pending input will be lost.