Need Help with python sdk subscription api

I am using square to create a subscription model. I have created plan and item. I have followed the Youtube video on How to create Subscriptions and there it was instructed to create an Order and get the id from there. But I am receiving the below error:

Create subscription result: <ApiResponse {"errors": [{"code": "BAD_REQUEST","detail": "Subscription cannot have both a top-level order template id and phases.","category": "INVALID_REQUEST_ERROR"}]}

Here’s my payload for reference as well

subscription_body: {'location_id': 'my-location-id', 'customer_id': '98MX7M8P10JWJ18F24J1703PMW', 'idempotency_key': 'fd5eafc4-53d0-4074-8f50-f457de13e48a', 'order_template_id': 'Xap9Ff0bDt9lvqhUu6twhOI6yZ4F', 'source': {'name': 'BC7YR4URYBJCD7RFK4PS2N2H'}, 'phases': [{'ordinal': 0, 'order_template_id': 'Xap9Ff0bDt9lvqhUu6twhOI6yZ4F'}], 'plan_variation_id': 'BC7YR4URYBJCD7RFK4PS2N2H'}

:wave: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:

https://developer.squareup.com/docs/app-marketplace/requirements/subscriptions-api

Additional Documentation

Create Orders
Orders API: How It Works
Guidelines and Limitations

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

The above docs didn’t solve my problem as I’m trying to start subscription using create_subscription api in python sdk. But the above mentioned one is for subscription checkout

The error message indicates that you’re trying to use both a top-level order template id and phases in your subscription, which is not allowed.

In your payload, you’re specifying ‘order_template_id’ at the top level and also within ‘phases’. You should only specify it in one place.

If you want to use phases, remove the ‘order_template_id’ from the top level of your payload. If you don’t want to use phases, remove the ‘phases’ section from your payload.

Here’s how your payload should look if you’re using phases:

subscription_body: {
    'location_id': 'L655HC47K33ZY', 
    'customer_id': '98MX7M8P10JWJ18F24J1703PMW', 
    'idempotency_key': 'fd5eafc4-53d0-4074-8f50-f457de13e48a', 
    'source': {'name': 'BC7YR4URYBJCD7RFK4PS2N2H'}, 
    'phases': [{'ordinal': 0, 'order_template_id': 'Xap9Ff0bDt9lvqhUu6twhOI6yZ4F'}], 
    'plan_variation_id': 'BC7YR4URYBJCD7RFK4PS2N2H'
}

And here’s how it should look if you’re not using phases:

subscription_body: {
    'location_id': 'L655HC47K33ZY', 
    'customer_id': '98MX7M8P10JWJ18F24J1703PMW', 
    'idempotency_key': 'fd5eafc4-53d0-4074-8f50-f457de13e48a', 
    'order_template_id': 'Xap9Ff0bDt9lvqhUu6twhOI6yZ4F', 
    'source': {'name': 'BC7YR4URYBJCD7RFK4PS2N2H'}, 
    'plan_variation_id': 'BC7YR4URYBJCD7RFK4PS2N2H'
}

Remember to choose the correct structure based on your specific use case.

This answer was reviewed by @Bryan-Square.

Thanks Could you just let me know how would I add a trial here as well I want to give customer 14 days trial before charging for subscription