The error in question — “Invalid parameter(s): tags” and “tags[0] is not of type integer.“, means that you need to supply a list of tag IDs and not names or slugs. So for examples, 'tags' => 123 and 'tags' => [ 123 ] are both valid. (Comma-separated list is also accepted, e.g. 'tags' => '123,4,5'.)
And all that also apply to the default category taxonomy and custom taxonomies (e.g. my_tax), except that for category, you should use categories and not category. So for example, use 'categories' => 5 and not 'category' => 5.
From your comment:
is there a way for me to always use the name instead of the ID?
You can try one of these (or both for testing..):
-
You can first create the tag/category using the REST API (e.g.
/wp/v2/categoriesfor categories) and get the tag/category ID from the API response, and then use it when creating your post.So you’d be making two REST API requests, one for creating the tag/category, and another for creating the post.
-
On your WordPress site, you can register custom REST API fields like
tags_nameandcategories_slug:// In your theme functions.php file: add_action( 'rest_api_init', 'my_register_rest_fields' ); function my_register_rest_fields() { register_rest_field( 'post', 'tags_name', [ 'update_callback' => function ( $names, $post ) { return wp_set_post_tags( $post->ID, $names ); } ] ); register_rest_field( 'post', 'categories_slug', [ 'update_callback' => function ( $slugs, $post ) { $ids = []; foreach ( wp_parse_list( $slugs ) as $slug ) { if ( $category = get_category_by_slug( $slug ) ) { $ids[] = $category->term_id; } } return ( ! empty( $ids ) ) ? wp_set_post_categories( $post->ID, $ids ) : false; } ] ); }Then when creating your post, in the API request body/data, use
'categories_slug' => 'cat-one, cat-two, etc'for categories, and'tags_name' => 'one, two, etc'for tags. And remember, for categories, you need to use the category slug and not name.