How to set a template with wp_insert_post

I'm trying to set my template to the Elementor Canvas when using wp_insert_post but it isn't working. It is creating the new page fine but not using the canvas. What am I doing wrong?

{
action: create_post,
post_author: authorID,
post_content: post content,
post_title: Leave us a Review,
post_status: publish,
post_type: page,
comment_status: closed,
post_name: post-name,
page_template: elementor_canvas

}

Topic rest-api php templates api Wordpress

Category Web


You can check this code I am able to work with this

function cutom_function() {

    $new_page_id = wp_insert_post( array(
        'post_title'     => 'PKB',
        'post_type'      => 'page',
        'post_name'      => 'pkb',
        'comment_status' => 'closed',
        'ping_status'    => 'closed',
        'post_content'   => '',
        'post_status'    => 'publish',
        'post_author'    => get_user_by( 'id', 1 )->user_id,
        'menu_order'     => 0,
        // Assign page template
        'page_template'  => 'pratik.php'
    ) );

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.