Why does the UnbilledCharge.create API return a currency_code error?
Problem Statement
You see the error chargebee.api_error.InvalidRequestError: currency_code : Not applicable when subscription_id is specified when using the UnbilledCharge.create API.
Related Scenarios
- Error when passing
currency_codefor charges in Product Catalog 2.0
Solution
This error usually occurs when you pass currency_code for charges in Product Catalog 2.0. The currency_code field is applicable only for quick charges, and it must match the subscription currency.
Referring to the API documentation for Create unbilled charges for item subscription, currency_code is a required input parameter for quick charges, not an optional one.
Charges
If you want to add charges, pass item_prices[item_price_id][0..n] and do not add currency_code when multi-currency is enabled. Chargebee automatically uses the subscription currency.
Quick Charges
Quick charges require a currency code because they are not predefined and are created manually. You will also see this field in the Chargebee UI.
Sample screenshot of quick charges in the Chargebee UI:
For quick charges or one-time charges, you must pass the currency_code parameter and it must match the subscription currency.
To learn more, see the API docs.
Related links: