Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

<Accounts> "Custom" triggers

75 views
Skip to first unread message

Domen

unread,
May 16, 2025, 9:52:09 AMMay 16
to CGRateS
Greetings,

I've got a question regarding triggers or maybe it is solved differently.

So lets say I have 2 actions like below:
```
ACTION1,*topup_reset,,,ACTION1-DATA,*data,category1,DST_1,,,*unlimited,,100,10,false,false,10

ACTION2,*topup_reset,,,ACTION2-DATA,*data,category2,DST_2,,,*unlimited,,100,10,false,false,10
```
I then tried to setup a ActionTrigger that would trigger when the balance of the ACTION2 would run out:
```
STANDARD_TRIGGER_ACTION2,,*min_balance,0,false,0,,,,*data,,,,,,,,,,POST_WARNING,10
```
Now while this works if the ACTION2 runs out of its balance, but I've noticed that the same happens when ACTION1 runs out of its balance.

So the question is, if it is possible to have an ActionTrigger that triggers when only the balance of the ACTION2 runs out?

Best regards,

Domen

Armir Veliaj

unread,
May 20, 2025, 5:21:36 AMMay 20
to CGRateS
Hi Domen,

Both of your actions are setting *data balances (ACTION1-DATA and ACTION2-DATA). The trigger you set checks all *data balances in the account, which is why it also reacts when ACTION1-DATA runs out.If you want the trigger to work only with ACTION2-DATA, you should set the BalanceTag field (the one just before the balance type in the CSV). That way, it will apply only to that specific balance.

Hope this helps!

Thanks,
Armir

Domen

unread,
May 20, 2025, 7:21:12 AMMay 20
to CGRateS
Hey Armir,

thank you for the pointers abd the fast reply. I've managed to make it work with the CSVs and now the next step is trying to make it work with the API calls.
Now I'm using this call to setup the ActionTrigger:
{
    "method": "APIerSv1.SetActionTrigger",
    "params": [
        {
            "GroupID": "STANDARD_TRIGGER_ACTION2",
            "UniqueID": "",
            "ActionTrigger": {
                "UniqueID": "",
                "ThresholdType": "*min_balance",
                "ThresholdValue": 0,
                "Recurrent": false,
                "MinSleep": 0,
                "ExpirationDate": "0001-01-01T00:00:00Z",
                "ActivationDate": "0001-01-01T00:00:00Z",
                "BalanceType": "*data",
                "BalanceTag": "ACTION_DATA2",
                "Weight": 0,
                "ActionsID": "LOG_WARNING",
                "MinQueuedItems": 10,
                "Executed": false,
                "LastExecutionTime": "0001-01-01T00:00:00Z"
            }
        }
    ]
}

Now the call executes with no errors.

But when I fetch it again it returns like this:
{
    "id": null,
    "result": [
        {
            "ID": "STANDARD_TRIGGERS_B",
            "UniqueID": "9a19d224-30c8-4624-a472-8f7fcd73012f",
            "ThresholdType": "*min_balance",
            "ThresholdValue": 0,
            "Recurrent": false,
            "MinSleep": 0,
            "ExpirationDate": "0001-01-01T00:00:00Z",
            "ActivationDate": "0001-01-01T00:00:00Z",
            "Balance": {
                "Uuid": null,
                "ID": null,
                "Type": "*data",
                "Value": null,
                "ExpirationDate": null,
                "Weight": null,
                "DestinationIDs": null,
                "RatingSubject": null,
                "Categories": null,
                "SharedGroups": null,
                "TimingIDs": null,
                "Timings": null,
                "Disabled": null,
                "Factors": null,
                "Blocker": null
            },
            "Weight": 0,
            "ActionsID": "LOG_WARNING",
            "MinQueuedItems": 10,
            "Executed": false,
            "LastExecutionTime": "0001-01-01T00:00:00Z"
        }
    ],
    "error": null
}

All of the Balance part is null and I'm not sure why.

Best regards,

Domen

torek, 20. maj 2025 ob 11:21:36 UTC+2 je oseba armir....@itsyscom.com napisala:

Domen

unread,
May 22, 2025, 6:40:46 AMMay 22
to CGRateS
So after abit of digging in the go docs I've found that my request needs a *BalanceFilter. Now I've tried to set it up accordingly like this:
{
    "method": "APIerSv1.SetActionTrigger",
    "params": [
        {
            "GroupID": "STANDARD_TRIGGERS_ACTION2",
            "UniqueID": "",
            "ActionTrigger": {
                "UniqueID": "",
                "ThresholdType": "*min_balance",
                "ThresholdValue": 0,
                "Recurrent": false,
                "MinSleep": 0,
                "ExpirationDate": "0001-01-01T00:00:00Z",
                "ActivationDate": "0001-01-01T00:00:00Z",
                "Balance": {
                        "Uuid": "4845deac-c43f-4ded-9812-c306331ec77e",
                        "ID": "ACTION2-DATA",
                        "Type": "*data"
                },
                "Weight": 0,
                "ActionsID": "LOG_WARNING",
                "MinQueuedItems": 0,
                "Executed": false,
                "LastExecutionTime": "0001-01-01T00:00:00Z"

            }

        }
    ]
}


I have tried to copy the exact Uuid and the ID of the balance for that specific balance. It seems I got the same result as above:
{
    "id": null,
    "result": [
        {
            "ID": "STANDARD_TRIGGERS_ACTION2",
            "UniqueID": "b523dd5a-59fd-4f65-ba9a-c0f15e7a5616",

I kept on digging and found another method, AddTriggeredAction which did yield better results, but turned out to be deprecated so I'm not sure if its even viable to use.
It pointed me towards AddAccountActionTriggers, which I already use to add the trigger to the account itself, but it does require to have the correctly setup ActionTrigger.
So with it AddTriggeredAction I managed to add the ActionTrigger with the BalanceId pointing to the balance. After that I've tried testing the trigger, but it never triggered.

 So now I'm kinda stuck, because it seems I cannot point the trigger to the balance as well.

Best regards,

Domen
torek, 20. maj 2025 ob 13:21:12 UTC+2 je oseba Domen napisala:

Armir Veliaj

unread,
May 22, 2025, 11:02:37 AMMay 22
to CGRateS
Hi Domen,

The APIs you are using are only related to ActionTriggers. To retrieve account information including balance data, you can use APIerSv1.GetAccount for a single account or APIerSv1.GetAccounts for multiple accounts (it will  also include any ActionTriggers bound to the accounts).

Thanks,
Armir

Domen

unread,
May 22, 2025, 12:53:51 PMMay 22
to CGRateS
Hey Armir,

thank you for the pointers. I see the triggers are applied to the account, but the problem remains, I cannot point it to the exact balanceID. With SetActionTrigger I only managed to set the BalanceType, and not the exact BalanceID. Am I using a wrong API call?

Thanks and BR,

Domen
četrtek, 22. maj 2025 ob 17:02:37 UTC+2 je oseba armir....@itsyscom.com napisala:

Armir Veliaj

unread,
May 23, 2025, 9:49:18 AMMay 23
to CGRateS
Hi Domen,

You can use the APIerSv1.SetActionTrigger API, but the fields inside that API aren't correct. There are no nested fields in the balance.

You can check the fields that you can use here:
https://pkg.go.dev/github.com/cgrates/cgrates/apier/v1#AttrAddActionTrigger.ActionTriggersId

Below is an example of how the API should look:


 
{
  "method": "APIerSv1.SetActionTrigger",
  "params": [{
    "GroupID": "STANDARD_TRIGGER_ACTION2",
    "UniqueID": "",
    "ActionTrigger": {
      "ThresholdType": "*min_balance",
      "Recurrent": true,
      "BalanceType": "*data",
      "BalanceID": "ACTION_DATA2",
      "ActionsID": "LOG_WARNING"
    }
  }]
}


Hope this helps.

Thanks,
Armir

Domen

unread,
May 28, 2025, 5:55:14 AMMay 28
to CGRateS
Hey Armir,

with the updated field BalanceID, it is now correctly targetting the balance I wanted. Thank you for all the help!

Best regards,

Domen

petek, 23. maj 2025 ob 15:49:18 UTC+2 je oseba armir....@itsyscom.com napisala:
Reply all
Reply to author
Forward
0 new messages