how to change balance ExpirationDate

136 views
Skip to first unread message

Michal Sejč

unread,
Aug 5, 2020, 7:45:48 AM8/5/20
to CGRateS

Hello,

how does one change the expiration date of a balance?


I’ve tried changing it from the cgr-console on an existing balance as well as while creating a new balance:


cgr> balance_set Tenant="1518536340" Account="default" Balance={"ID":"*default", "ExpirationDate": "2022-01-01T00:00:00Z"} Value=10
cgr> balance_add Tenant="1518536340" Account="default" Balance={"ID":"credit", "ExpirationDate": "2022-01-01T00:00:00Z"} Value=10


It does change the Value to 10 but not the ExpirationDate. I’ve also tried it with HTTP curl using SetBalance method with the same result:


curl -v --noproxy "*" -X POST -i http://192.168.6.23:2088/jsonrpc --data '{"method":"ApierV1.SetBalance","params":[{"Tenant":"1518536340","Account":"default","BalanceType":"*monetary","Value":10,"Balance":{"ID":"*default", "ExpirationDate":"2022-01-01T00:00:00Z"},"ActionExtraData":null,"Cdrlog":false}],"id":1}'


curl -v --noproxy "*" -X POST -i http://192.168.6.23:2088/jsonrpc --data '{"method":"ApierV1.SetBalance","params":[{"Tenant":"1518536340","Account":"default","BalanceType":"*monetary","Value":10,"Balance":{"ID":"*default"},"ActionExtraData":{"ExpirationDate":"2022-01-01T00:00:00Z"},"Cdrlog":false}],"id":1}'


I don’t understand from the godoc whether I should put the ExpirationDate in Balance or in ActionExtraData or elsewhere.

Thanks.

Teofil Voivozeanu

unread,
Aug 5, 2020, 9:20:00 AM8/5/20
to CGRateS
Hi Michal,

We consider ExpiryTime ExpirationDate ( like in this test https://github.com/cgrates/cgrates/blob/master/apier/v1/accounts_it_test.go#L181-L200 ).
If you want you can open a feature request and we will try to uniform this.

Thanks,
TeoV

Arthur Koenig

unread,
Jun 14, 2021, 5:06:28 PM6/14/21
to CGRateS
Did you figure out how to pass the ExpirationDate?  We've tried both options above, but it doesn't work.

Nickolas Daniel Filip

unread,
Jun 23, 2021, 8:52:14 AM6/23/21
to CGRateS
Hi Arthur!

The balance with the ID of *default is, as the name implies, the default, or rather the fallback balance. Thus, you can not change its ExpirationDate, nor the other fields except the Value. 
In order to set a balance of your own desire, you must provide an ID other than *default.

I will attach a short demonstration using ngrep.
We first want to see the fallback balance.
The response on ngrep will look like this: 
T 2021/06/23 14:09:02.878238 127.0.0.1:2012 -> 127.0.0.1:57984 [AP] #2
{"id":44,"result":[{"ID":"cgrates.org:1001","BalanceMap":{"*monetary":[{"Uuid":"a1a92ba1-cc13-48cb-81f4-6c22a1c1e995","ID":"*default","Value":10,"ExpirationDate":"0001-01-01T00:00:00Z","Weight":0,"DestinationIDs":null,"RatingSubject":"","Categories":null,"SharedGroups":null,"Timings":null,"TimingIDs":null,"Disabled":false,"Factor":null,"Blocker":false}]},"UnitCounters":null,"ActionTriggers":null,"AllowNegative":false,"Disabled":false,"UpdateTime":"2021-06-23T11:08:42.287Z"}],"error":null}

We now want to set our balance.
#
T 2021/06/23 14:09:25.026251 127.0.0.1:57984 -> 127.0.0.1:2012 [AP] #8
{"method":"APIerSv1.SetBalance","params":[{"Tenant":"","Account":"1001","BalanceType":"*monetary","Value":15,"Balance":{"ExpiryTime":"2022-01-01T00:00:00Z","ID":"credit","Weight":"30"},"ActionExtraData":null,"Cdrlog":false}],"id":45}

Now we can see the response on the ngrep, which tells us that our balance did set correctly:
#
T 2021/06/23 14:09:25.031794 127.0.0.1:2012 -> 127.0.0.1:57984 [AP] #9
{"id":45,"result":"OK","error":null}

We can send another get request in order to see our new balance.
Now if we look at the ngrep,
#
T 2021/06/23 14:09:28.906806 127.0.0.1:2012 -> 127.0.0.1:57984 [AP] #12
{"id":46,"result":[{"ID":"cgrates.org:1001","BalanceMap":{"*monetary":[{"Uuid":"a1a92ba1-cc13-48cb-81f4-6c22a1c1e995","ID":"*default","Value":10,"ExpirationDate":"0001-01-01T00:00:00Z","Weight":0,"DestinationIDs":null,"RatingSubject":"","Categories":null,"SharedGroups":null,"Timings":null,"TimingIDs":null,"Disabled":false,"Factor":null,"Blocker":false},{"Uuid":"dcf7f3b2-74b1-4b16-85ed-2e4c426787d6","ID":"credit","Value":15,"ExpirationDate":"2022-01-01T00:00:00Z","Weight":30,"DestinationIDs":null,"RatingSubject":"","Categories":null,"SharedGroups":null,"Timings":null,"TimingIDs":null,"Disabled":false,"Factor":null,"Blocker":false}]},"UnitCounters":null,"ActionTriggers":null,"AllowNegative":false,"Disabled":false,"UpdateTime":"2021-06-23T11:09:25.03Z"}],"error":null}

we can see both the fallback, and the desired balance.
There is also another similar discussion that might help understand: https://groups.google.com/g/cgrates/c/Z244hQR9tWQ/m/zBJjb1naAAAJ

Thanks,
@nickolasdaniel
Reply all
Reply to author
Forward
0 new messages