$id = wp_create_category('My category name');
By above function category created & categary id is returned.
If the category already exists, it is not duplicated. The ID of the original existing category is returned without error.
You can use $id
as category id.
Reference
http://codex.wordpress.org/Function_Reference/wp_create_category