Is there an API method to get the IPFS hash of a file?

The CID in IPFS is not the hash of the file. It’s the hash of the root
block of a DAG representing that file.

When you add a file to IPFS, the file is split into blocks (chunks) and
those blocks are hashed. A DAG is built up out of those blocks. So a
file has very very many possible hashes in IPFS, even if you don’t
account for hashing algorithm.

Let’s take a quick example. I don’t know how this is going to come out,
since I’m writing it in email.

I have this file stored on my node. The SHA256 hash of the file is:
d088ffe20ea1eb6b51ffaed1833310446812096beb19e2c444147cd3a3cdd77e.
Its CID is: QmSuook5umbYEELYcY9pDmfpmbEwCjNdjutXMi19spYFPg.

$ ipfs dag stat QmSuook5umbYEELYcY9pDmfpmbEwCjNdjutXMi19spYFPg
Size: 52488471, NumBlocks: 204

$ ipfs block stat QmSuook5umbYEELYcY9pDmfpmbEwCjNdjutXMi19spYFPg
Key: QmSuook5umbYEELYcY9pDmfpmbEwCjNdjutXMi19spYFPg
Size: 109

The Qm CID above is like a pointer. It’s the content address of the
root block of the file. That root block is a protobuf, so we can drill
down a little bit and see what’s inside.

ipfs block get QmSuook5umbYEELYcY9pDmfpmbEwCjNdjutXMi19spYFPg \
>protoc --decode_raw

The protoc output is kinda inscrutable, but if you peek at it closely
enough, it describes a block containing two links to additional blocks.
The block also contains a data field, which is basically like a file header,
telling us that this block represents a file and the total file size is
52475881 bytes.

Those two additional blocks are going to link to even more blocks.

There isn’t really a concept of “the hash of a file in IPFS”. There is
a hash of the root block made from one particular splitting of a file,
and that’s all.