Example code for migrating tenants using Management API

If you need to deploy to different tenants on a regular basis, such as having a production, staging, dev tenant, you can use the source control extension to automate this, i.e. having separate git branches for each tenant.

You can also consider using the Deploy CLI.
There are example config files at Import/Export Tenant Configuration to Directory Structure

This Deploy CLI can also be nicely integrated into CI/CD build pipelines.

I recommend to go with either of the two options, instead of doing manual calls to the Management API.