[ARCHIVED] Send announcement via API problem: Pragraph marks not preserved

Jump to solution
mmtscn
Community Explorer

Hello,

When I send announcement via API, paragraph marks are not preserved. For instance, the original message is:

this is a test message
this is a test message
this is a test message
this is a test message

on Canvas, it will show this:

this is a test message this is a test message this is a test message this is a test message

(Send message to student API works find. It will preserve the paragraph marks.)

Might be a bug?

Labels (2)
1 Solution
James
Community Champion

You didn't mention that you were using curl.

You need to use --form-string instead of -F. @ and < are special characters in -F. If there are no @ or < then you can just use -F.

Here's what the curl manual says about -F

This enables uploading of binary files etc. To force the 'content' part to be a file, prefix the file name with an @ sign. To just get the content part from a file, prefix the file name with the symbol <. The difference between @ and < is then that @ makes a file get attached in the post as a file upload, while the < makes a text field and just get the contents for that text field from a file.

For --form-string, it says:

(HTTP SMTP IMAP) Similar to -F, --form except that the value string for the named parameter is used literally. Leading '@' and '<' characters, and the ';type=' string in the value have no special meaning. Use this in preference to -F, --form if there's any possibility that the string value may accidentally trigger the '@' or '<' features of -F, --form.

Here's how my request looked, with <token>, <instance>, and <course_id> being replaced.

curl -X POST \
-F "title=this is a test title" \
--form-string 'message=<p>This is a test message.</p>
<p>This is a test message.</p>
<p>This is a test message.</p>
<p>This is a test message.</p>' \
-F "is_announcement=true" \
-F "published=true" \
-H "Authorization: Bearer <token>" \
-H "Accept: application/json" \
"<instance>/api/v1/courses/<course_id>/discussion_topics"‍‍‍‍‍‍‍‍‍‍‍

You can also use -d to put all of the fields together like you would for a GET. According to the curl manual, this should be url encoded.

-d "title=This is a test title&message=<p>this is a test messsage.</p><p>this is a test messsage.</p><p>this is a test messsage.</p><p>this is a test messsage.</p>&is_announcement=true&published=true"

Adding a <br> means that you're using HTML, but specifying line breaks. You were asking about paragraphs, which is what the <p></p> element gives you.

View solution in original post