Both of them have the same meaning about that. And so both are right.
But it's a delicate difference nuance.
If when you ask someone, "これは何といいますか？". In this case, you are not such interested.
If when you ask someone, "これを何といいますか？". In this case, you want to know it in particular.
For example, in first your question case, you can say "What's this?" and "What's this called in Japanese?".
And in next situation case, you can say "What do you call this in Japanese?" .
Then you can say "How do you say this in Japanese?".