How to apply CSS with pages API ?

Jump to solution
CartonKam
Community Member

I would like to create page with API.
No matter I put the css in inline or internal way, API fail to handle it.
Are there any way that can apply CSS to API call? Thank you.

Labels (1)
0 Likes
1 Solution

Creating a wiki page with inline CSS works for me, the difference i think is that I sent the parameters in the body of the request instead of as query parameters. Attached is a screenshot of a request:

Screenshot 2023-05-12 at 07.26.03.png

This returned the following JSON from Canvas which appears to show the page correctly having CSS:

{
    "title": "API Page-2",
    "created_at": "2023-05-12T06:21:45Z",
    "url": "api-page-2",
    "editing_roles": "teachers",
    "page_id": 383,
    "last_edited_by": {
        "id": 112,
        "anonymous_id": "34",
        "display_name": "Matthew Buckett",
        "avatar_image_url": "https://secure.gravatar.com/avatar/0b238ed6001c42521b1ae20ea78e66ad?s=128&d=identicon",
        "html_url": "https://oxeval.instructure.com/courses/164/users/112",
        "pronouns": null
    },
    "published": false,
    "hide_from_students": true,
    "front_page": false,
    "html_url": "https://oxeval.instructure.com/courses/164/pages/api-page-2",
    "todo_date": null,
    "publish_at": null,
    "updated_at": "2023-05-12T06:21:45Z",
    "locked_for_user": false,
    "body": "<p style=\"color: red;\">A red paragraph</p>"
}

Postman should do the escaping for you when you send a request to Canvas, you only need to do escaping if you are sending the request body as JSON.

 

View solution in original post