Normally you can only cancel/disable a subscription by code if the subscription is empty.
If you add IgnoreResourceCheck=true and thereby still cancel the subscription. This give you the grace time before deletion. Remember to change {subscriptionId} in the URI
Documentation on grace period