Questions about TimingIDs and SetBalance method properties

100 views
Skip to first unread message

Salvinder Parhar

unread,
May 13, 2026, 9:53:33 PMMay 13
to cgr...@googlegroups.com
Hello CGRateS team,

Can you please help me with some of my questions regarding TimingIDs and some of the properties we set when setting/updating a balance for an account, and the syntax I need to use for their values when calling the SetBalance method.

Here are the steps I followed. My questions are at the end. Please let me know if I'm doing something wrong in any of the steps.

1) Set two TP Timing ID's
TP_TIMINGID_01 - Covers AM hours from 12am to 11:59am (Months, MonthDays, WeekDays, Years are same for both Timing ID's)
TP_TIMINGID_02 - Covers PM hours from 12pm to 11:59pm

{
    "id": 1,
    "method": "APIerSv1.SetTPTiming",
    "params": [
        {
            "TPid": "TPid-01",
            "ID": "TP_TIMINGID_01",
            "MonthDays": "11;12;13;14;15",
            "Months": "4;5;6;7",
            "Time": "00:00:00;11:59:59",
            "WeekDays": "*any",
            "Years": "2026;2027"
        }
    ]
}

{
    "id": 1,
    "result": "OK",
    "error": null
}

{
    "id": 1,
    "method": "APIerSv1.SetTPTiming",
    "params": [
        {
            "TPid": "TPid-01",
            "ID": "TP_TIMINGID_02",
            "MonthDays": "11;12;13;14;15",
            "Months": "4;5;6;7",
            "Time": "12:00:00;23:59:59",
            "WeekDays": "*any",
            "Years": "2026;2027"
        }
    ]
}

{
    "id": 2,
    "result": "OK",
    "error": null
}

2) Load the newly created TP Timing IDs from StorDB to DataDB

{
    "id": 3,
    "method": "APIerSv1.LoadTariffPlanFromStorDb",
    "params": [
        {
            "TPid": "TPid-01",
            "Validate": true
        }
    ]
}

{
    "id": 3,
    "result": "OK",
    "error": null
}

3) Set a new Account

{
    "id": 4,
    "method": "APIerSv2.SetAccount",
    "params": [
        {
            "Tenant": "uc.hostedpbx.ca",
            "Account": "TEST_ACCOUNT_ID_001",
            "ExtraOptions": {
                "AllowNegative": false,
                "Disabled": false
            },
            "ReloadScheduler": true,
            "ActionPlanIDs": null,
            "ActionPlansOverwrite": false,
            "ActionTriggerIDs": null,
            "ActionTriggerOverwrite": false
        }
    ]
}

4) Set a monetary type balance for the newly created account, and assign it the two Timing ID's created above. TP_TIMINGID_01 is assigned as is, while TP_TIMINGID_02 is assigned with a bang sign "!".

{
    "id": 5,
    "method": "APIerSv1.SetBalance",
    "params": [
        {
            "Tenant": "uc.hostedpbx.ca",
            "Account": "TEST_ACCOUNT_ID_001",
            "BalanceType": "*monetary",
            "Value": 20,
            "Balance": {
                "ID": "TEST_MONETARY_BALANCE_01",
                "DestinationIDs": "DST_CA_ALL;DST_CA_TOLLFREE;DST_USA_ALL;!DST_CA_INTERNATIONAL;",
                "RatingSubject": null,
                "Categories": "call-in;!call-out",
                "SharedGroups": null,
                "TimingIDs": "TP_TIMINGID_01;!TP_TIMINGID_02",
                "ExpiryTime": "*unlimited",
                "Factors": null,
                "Blocker": false,
                "Weight": 10,
                "Disabled": false
            },
            "ActionExtraData": null,
            "Cdrlog": false
        }
    ]
}

5) Fetch the account and its balance using method GetAccount

{
    "id": 6,
    "method": "APIerSv2.GetAccount",
    "params": [
        {
            "Tenant": "uc.hostedpbx.ca",
            "Account": "TEST_ACCOUNT_ID_001"
        }
    ]
}

{
    "id": 6,
    "result": {
        "ID": "uc.hostedpbx.ca:TEST_ACCOUNT_ID_001",
        "BalanceMap": {
            "*monetary": [
                {
                    "Uuid": "23a8ff9f-90cb-44d0-b386-6302df41228c",
                    "ID": "TEST_MONETARY_BALANCE_01",
                    "Value": 20,
                    "ExpirationDate": "0001-01-01T00:00:00Z",
                    "Weight": 10,
                    "DestinationIDs": {
                        "DST_CA_ALL": true,
                        "DST_CA_INTERNATIONAL": false,
                        "DST_CA_TOLLFREE": true,
                        "DST_USA_ALL": true
                    },
                    "RatingSubject": "",
                    "Categories": {
                        "call-in": true,
                        "call-out": false
                    },
                    "SharedGroups": {},
                    "Timings": [
                        {
                            "ID": "TP_TIMINGID_01",
                            "Years": [
                                2026,
                                2027
                            ],
                            "Months": [
                                4,
                                5,
                                6,
                                7
                            ],
                            "MonthDays": [
                                11,
                                12,
                                13,
                                14,
                                15
                            ],
                            "WeekDays": [],
                            "StartTime": "00:00:00",
                            "EndTime": "11:59:59"
                        },
                        {
                            "ID": "TP_TIMINGID_02",
                            "Years": [
                                2026,
                                2027
                            ],
                            "Months": [
                                4,
                                5,
                                6,
                                7
                            ],
                            "MonthDays": [
                                11,
                                12,
                                13,
                                14,
                                15
                            ],
                            "WeekDays": [],
                            "StartTime": "12:00:00",
                            "EndTime": "23:59:59"
                        }
                    ],
                    "TimingIDs": {
                        "TP_TIMINGID_01": true,
                        "TP_TIMINGID_02": false
                    },
                    "Disabled": false,
                    "Factors": null,
                    "Blocker": false
                }
            ]
        },
        "UnitCounters": null,
        "ActionTriggers": null,
        "AllowNegative": false,
        "Disabled": false,
        "UpdateTime": "2026-05-13T20:16:22.8805858-04:00"
    },
    "error": null
}

6) Using the method SetBalance again, update this same account's monetary type balance and remove the TimingIDs from it.

{
    "id": 7,
    "method": "APIerSv1.SetBalance",
    "params": [
        {
            "Tenant": "uc.hostedpbx.ca",
            "Account": "TEST_ACCOUNT_ID_001",
            "BalanceType": "*monetary",
            "Balance": {
                "ID": "TEST_MONETARY_BALANCE_01",
                "TimingIDs": "",
                "Disabled": false
            },
            "ActionExtraData": null,
            "Cdrlog": false
        }
    ]
}

7) Use the method GetAccount to fetch the account details again

{
    "id": 8,
    "method": "APIerSv2.GetAccount",
    "params": [
        {
            "Tenant": "uc.hostedpbx.ca",
            "Account": "TEST_ACCOUNT_ID_001"
        }
    ]
}

{
    "id": 8,
    "result": {
        "ID": "uc.hostedpbx.ca:TEST_ACCOUNT_ID_001",
        "BalanceMap": {
            "*monetary": [
                {
                    "Uuid": "23a8ff9f-90cb-44d0-b386-6302df41228c",
                    "ID": "TEST_MONETARY_BALANCE_01",
                    "Value": 20,
                    "ExpirationDate": "0001-01-01T00:00:00Z",
                    "Weight": 10,
                    "DestinationIDs": {
                        "DST_CA_ALL": true,
                        "DST_CA_INTERNATIONAL": false,
                        "DST_CA_TOLLFREE": true,
                        "DST_USA_ALL": true
                    },
                    "RatingSubject": "",
                    "Categories": {
                        "call-in": true,
                        "call-out": false
                    },
                    "SharedGroups": {},
                    "Timings": [
                        {
                            "ID": "TP_TIMINGID_01",
                            "Years": [
                                2026,
                                2027
                            ],
                            "Months": [
                                4,
                                5,
                                6,
                                7
                            ],
                            "MonthDays": [
                                11,
                                12,
                                13,
                                14,
                                15
                            ],
                            "WeekDays": [],
                            "StartTime": "00:00:00",
                            "EndTime": "11:59:59"
                        },
                        {
                            "ID": "TP_TIMINGID_02",
                            "Years": [
                                2026,
                                2027
                            ],
                            "Months": [
                                4,
                                5,
                                6,
                                7
                            ],
                            "MonthDays": [
                                11,
                                12,
                                13,
                                14,
                                15
                            ],
                            "WeekDays": [],
                            "StartTime": "12:00:00",
                            "EndTime": "23:59:59"
                        }
                    ],
                    "TimingIDs": {},
                    "Disabled": false,
                    "Factors": null,
                    "Blocker": false
                }
            ]
        },
        "UnitCounters": null,
        "ActionTriggers": null,
        "AllowNegative": false,
        "Disabled": false,
        "UpdateTime": "2026-05-13T20:30:39.717866863-04:00"
    },
    "error": null
}

In the GetAccount response back above, "TimingIDs" is now an empty object, which would mean to me that the two TimingID's we originally assigned to the account are no longer assigned to the account anymore. But the "Timings" array in the same response still shows the expanded version of those two TimingIDs. Is this normal? Will the account balance still take into account the two TimingIDs despite the fact that they've been removed from the account? How do I remove these leftover "Timings"?

Once a TP TimingID is set in StorDB, and loaded into DataDB, and then assigned to one or more accounts, if I need to update the values in that TimingID, how do I do that? Can I just update the same TP TimingID in StorDB first, and load it into DataDB again? Will this automatically update all the account balances 
(Don't think so but just want to confirm) that were already using that TimingID? OR do I need to repeat the same process of creating a brand new TP TimingID with the updated values in StorDB, load it into DataDB, and remove the existing TimingID from all the account balances using that TimingID, and then assign the newly created/loaded TimingID?

In step 4 above, when SetBalance is used to set a new balance:
- TP_TIMINGID_01 is assigned as is, while TP_TIMINGID_02 is assigned with a bang sign "!" in front of it. Would this mean that this balance will only be used when the actual time falls between TP_TIMINGID_01 and it will not match when the actual time falls between TP_TIMINGID_02?
- Same question for other properties in there, like "DestinationIDs", "RatingSubject", "Categories", "SharedGroups". A bang sign "!" can be used in front of one or more of the string values of these properties to inverse match and it'll behave as a logical NOT when this balance is queried, right?

Thanks,
Sal

Armir Veliaj

unread,
May 21, 2026, 9:42:07 AMMay 21
to CGRateS
Hi Sal,


We checked your API methods on the scenario that you have created and here are the answers grouped on the four main inquiries you had:

1. Timings remain after setting TimingIDs: ""
Clearing Timings can be done by updating the balance itself without any TimingIDs, although this may not be ideal in all cases where you need to update only TimingIDs. You could open a GitHub issue on this so that "Timings" gets cleaned up together with "TimingIDs".

2. Updating an existing TimingID into Accounts
You do not need to create a new TimingID. However, updating just the TimingID itself will not automatically update existing account balances. To have the update reflected after reloading into DataDB, you need to call SetBalance again for each affected balance using the same TimingID.

3. Does ! in front of a TimingID behave as logical NOT?
You could open a GitHub issue for this too, and we can implement the use of it for TimingIDs.

4. Does ! work as logical NOT for DestinationIDs, Categories, SharedGroups, and RatingSubject?
For DestinationIDs and Categories, yes, "!" works correctly as logical NOT. For SharedGroups, technically "!" sets the value to false, but it has no practical use since not including a group at all produces the same result. For RatingSubject, "!" is treated as a literal character and does not behave as logical NOT.

Hope this helps clarify things.

Thanks,
Armir

Salvinder Parhar

unread,
May 21, 2026, 10:52:17 PMMay 21
to CGRateS
Hi Armir,

Thank you for your response.

1. I'm sorry, but what do you mean when you say "Clearing Timings can be done by updating the balance itself without any TimingIDs". In my previous email above, Step 6 - when I use the "APIerSv1.SetBalance" with empty TimingIDs string, doesn't that count as updating the balance without any TimingIDs? Doing this didn't clear the Timings. Am I missing something in my API call? Also, I've opened a Github issue for this #5193, requesting "Timings" gets automatically cleared when "TimingIDs" are removed from a balance.

2. Exactly how I thought it would work. Thanks for the confirmation.

3. I've opened a separate Github feature request for this as well, #5194.

4. Got it.

Thanks,
Sal

Armir Veliaj

unread,
May 22, 2026, 1:10:34 PMMay 22
to CGRateS
Hi Sal,


It means to have a new balance set on the account replacing with the old one without TimingIDs, but as this cannot be used in all cases when you just need to change only TimingIDs, we will follow up on this through the GitHub issue you created and update you from there.

Thanks,
Armir

Salvinder Parhar

unread,
May 25, 2026, 3:54:50 PM (11 days ago) May 25
to CGRateS
Thanks Armir.

One more question regarding TimingIDs if I may. Until today I thought there were no APIerS methods to interact with TimingIDs in DataDB because there aren't any methods listed in Go API docs for this. But today while looking through the source code, I found that methods APIerSv1.GetTiming, APIerSv1.SetTimingAPIerSv1.RemoveTiming are actually available to GET/SET/REMOVE TimingIDs in DataDB using APIerS (Not sure why they are not shown in the Go API docs). Is there a reason why method APIerSv1.GetTimingIDs (to be able to get all TimingIDs in DataDB) is not there? If there isn't really a blocking reason for this, you think I can open a feature request for this on Github?

Thanks,
Sal

Armir Veliaj

unread,
May 26, 2026, 11:25:54 AM (11 days ago) May 26
to CGRateS
Hi Sal,

For all existing API methods that you see in our source code, they already exist and are also visible on pkg.go.dev. But, the link you were using was not directing to the latest master version. You can check the latest documentation of APIs here:

https://pkg.go.dev/github.com/cgrates/cgrates/apier@master

All the APIs you mentioned are available there.

Regarding APIerSv1.GetTimingIDs, you can open a feature request for this on GitHub, and we can implement it.

Thanks,
Armir

Salvinder Parhar

unread,
May 26, 2026, 3:46:48 PM (10 days ago) May 26
to CGRateS
Thanks Armir for pointing me to the correct Go Docs URL.

I've opened another feature request on Github for method APIerSv1.GetTimingIDs, #5199
Reply all
Reply to author
Forward
0 new messages