I don't know if that's true. At least it you wrote a story which is almost exactly like Harry Potter from scratch, without referencing the original and with none of the original characters, I don't believe this would be an issue under current copyright rules.
That's true, but not relevant to the point of the comment you are replying to. Taking a copy of an existing work, and simply replacing words with synonyms and renaming characters would still count as copying. Maybe there would be enough creativity in your choice of synonyms to make your work separately copyrightable as a derivative work, but that would still require permission of the existing work's copyright owner.
Producing a new work that happens to be similar to, or even word for word identical to an existing work, if you truly created it yourself from scratch without taking anything from the existing work, would not be copying.
As a practical matter, unless you had extraordinary proof that you really had never read Harry Potter books, watched the movies, read the plot summaries on Wikipedia, attended a party shortly after one of the books came out where everyone was talking about it, you would lose in a copyright infringement lawsuit. If you work is very similar to Harry Potter and you had access to Harry Potter, that's sufficient for the plaintiff to make their case, switching the burden to you to prove that you did not copy it.
A book is subject to veru different considerations - it has a plot, main characters, and other characteristics that you would be copying. All of these are a protected product of the author's creativity.
There is no plot in an API, no main characters, etc. It communicates matters of technical nature, and there aren't five different way of writing 'sqrt()' or whatever. It is more appropriately compares to architechtural blueprints and other technical documents.