Create Articles with Attachments
As a developer trying to import content, you may need to import articles that have attached files. You can import articles with multiple attachments by using the Create content method of the Content REST resource.
Suppose, Jen is a developer in a service organization who is required to import several knowledge articles to Oracle Knowledge. Let’s look at how Jen can import articles of a content type FAQ, with and without attachments.
Create an FAQ without Attachments
Jen imports an FAQ by performing a POST operation on the content resource.
Example URL
The following cURL command is used to create an FAQ:
curl -X POST https://<IM_REST_API_HOST>/km/api/latest/content" \
-u "<username:password>" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "@<FilePath/RequestBody.json>"
Example Request Body
The following is an example of request body in JSON format.
{
"locale":{ "recordId":"en_US" },
"contentType":{ "recordId":"98055D055BA8467B8097FB0B52923FD2", "referenceKey":"FAQ", "name":"FAQ" },
"xml":"<FAQ><SUMMARY><![CDATA[This is the title of my article]]></SUMMARY><ANSWER><![CDATA[This is the body of my article.]]></ANSWER></FAQ>",
"isForEdit":true
}
The example shows the minimum necessary payload to create an article. To include more information, see the Create content task.
Note that for creating an article without an attachment:
- Content-Type of this request is application/json
- Request body is json
- There are no KM_ATTACHMENTS_ATTR elements in the xml
Create an FAQ with Attachments
Jen can import an FAQ with attachments by performing a POST operation on the content resource.
Prerequisite
Before Jen can create an article with attachments, she must make sure that the FAQ content type is configured to accept attachments.
To configure a content type to accept attachments:
- Go to Setup and Maintenance, and from the Service offering, select Knowledge Management.
- Click Manage Knowledge Content Types.
- In the Manage Content Types page, select the content type that you want to configure. For example, FAQ.
- Click Next to configure the content schema.
- Under File Attachments, select the Enable File Attachments check box and save your configuration.
Example URL
The following cURL command is used to create an FAQ with attachments:
curl -X POST https://<IM_REST_API_HOST>/km/api/latest/content" \
-u "<username:password>" \
-H "Accept: application/json" \
-H "Content-Type: multipart/form-data" \
-d "@<FilePath/RequestBody.json>"
Note that a multipart form is used so that the json of the article and the files to be attached can go in the same POST request.
Example Request Body
The following is an example of request body:
--form 'contentBO="{
\"locale\":{ \"recordId\":\"en_US\" },
\"contentType\": { \"recordId\":\"98055D055BA8467B8097FB0B52923FD2\", \"referenceKey\":\"FAQ\", \"name\":\"FAQ\" },
\"xml\":\"<FAQ><SUMMARY><![CDATA[This is the title of my article]]></SUMMARY><ANSWER><![CDATA[This is the body of my article.]]></ANSWER><KM_ATTACHMENTS_ATTR><FILE><TITLE>File 1</TITLE><DESCRIPTION>First upload file</DESCRIPTION><FILENAME><![CDATA[file1.txt]]></FILENAME></FILE></KM_ATTACHMENTS_ATTR><KM_ATTACHMENTS_ATTR><FILE><TITLE>File 2</TITLE><DESCRIPTION>Second upload file</DESCRIPTION><FILENAME><![CDATA[file2.txt]]></FILENAME></FILE></KM_ATTACHMENTS_ATTR></FAQ>\",
\"isForEdit\":true
}";type=application/json' \
--form 'filesToUpload=@"file1.txt"' \
--form 'filesToUpload=@"file2.txt"'