How do you replace an existing IdP's certificate with a new one using the API?

As the topic title states, how do you replace an existing IdP’s certificate with a new one (provided from a customer as a .cert file) using the API?

I am trying to automate the manual process that is done via the UI at Admin > Security > Identity Providers > SAML Protocol Settings > IdP Signature Certificate, but am struggling.

Thanks.