Setting a featured image while creating the post
As far as I know you can’t add the thumbnail in the first array you send to create the post, you’ll need to grab the post ID after the wp_insert_post, then run update_post_meta after the first part of the function. If you post your function here we might be able to help a little further.