Disable an account through an API

189 views
Skip to first unread message

Jose Gavine Cueto

unread,
Aug 12, 2015, 8:11:23 AM8/12/15
to CGRateS
Hi, I've been using CGRates for a while now and I would like to say its an excellent system, even for beginners in the Telecom. billing world like me!

By the way, hi Dan this is Jose, I'm posting here so important information will be shared among other users.

So my question is how can I disable an account without deleting it by just calling API ?  Disabling it would also mean current and future transactions (e.g. calls) will be stopped by CGRates automatically.

As an example,

Customer A's account is billed monthly, however due to some business rules, our system would need to disable customer A's account after the 2nd week.  This said business rule may apply any time, and more importantly its application is not known beforehand.  For instance, after the 2nd week, we decide to end customer A's billing prematurely right and then, but without deleting his account.

Cheers,
Jose

DanB

unread,
Aug 12, 2015, 8:43:51 AM8/12/15
to cgr...@googlegroups.com
Hi Jose,

Happy CGRateS serves you well!

Regarding disabling the account, right now the way to do it is creating
an action plan with an action which will set the disable bit on the account:
https://github.com/cgrates/cgrates/blob/master/engine/action.go#L66

After you have your action plan, call SetAccount with ActionPlanId on it:
http://godoc.org/github.com/cgrates/cgrates/apier/v1#ApierV1.SetAccount

If you open an issue on github (and give us a star there ;)), we can
implement the Disable bit directly in SetAccount API for you.

Cheers,
DanB

Jose Gavine Cueto

unread,
Aug 13, 2015, 5:44:36 AM8/13/15
to CGRateS
Hi Dan, 

I've implemented what you've just suggested, particularly I've used the following data for the associated API calls;

Note:  data format is in JSON, because I'm using the jsonrpc API

ApierV1.SetTPActions 

{
  "name": "a.disable_account",
  "actions": [
    {
      "Identifier": "*disable_account",
      "BalanceType": "*monetary",
      "Direction": "*out",
      "Units": 0,
      "ExpiryTime": "0",
      "DestinationIds": "*any",
      "BalanceWeight": 10,
      "Weight": 10
    }
  ],
  "TPid": "default"
}

ApierV1.SetTPActionPlan

{
  "id": "ap.disable_account",
  "plans": [
    {
      "ActionsId": "a.disable_account",
      "TimingId": "t.asap",
      "Weight": 10
    }
  ],
  "TPid": "default"
}

Then ultimately called SetAccount with ActionPlanId=ap.disable_account.  This worked almost perfectly and that every time I call it the next call will be disabled, except that when the call is ongoing, the account was not disabled.  I confirmed this by running a GetAccount API call and checked that the Disabled key is equal to false.  I'm not sure though if this is a bug or just an unsupported feature.

I'll make a request in Github.  Thanks!

Jose Gavine Cueto

unread,
Aug 13, 2015, 5:46:01 AM8/13/15
to CGRateS
Calling SetAccount while call is ongoing didn't disable the call.

DanB

unread,
Aug 13, 2015, 5:48:55 AM8/13/15
to cgr...@googlegroups.com
Hi Jose,

If you call SetTPActions you need to make sure you reload them to tariffplanDb since these TP* are offline and never make it to live without specific activation.

Try using the ones operating on live data:
http://godoc.org/github.com/cgrates/cgrates/apier/v1#ApierV1.SetActionPlan
http://godoc.org/github.com/cgrates/cgrates/apier/v1#ApierV1.SetActions

Also after calling set on account with disable, you should see Disabled: true in the account.

DanB
--
You received this message because you are subscribed to the Google Groups "CGRateS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cgrates+u...@googlegroups.com.
To post to this group, send email to cgr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cgrates/4684a268-604b-4ce7-96f7-1f2180d21489%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jose Gavine Cueto

unread,
Aug 13, 2015, 7:58:00 AM8/13/15
to CGRateS
Hi Dan,

To be more specific, I've run LoadTariffPlanFromStorDb after running all SetTP* APIs, and then made sure that all the TP* are in the cache.

When TP* are in the cache, I ran SetAccount using the disable action and action plan.  SetAccount worked when the user account associated has no ongoing call, otherwise it didn't do anything, so I have to run it after the call ended.  I've also confirmed this by checking the Disabled attribute to true/false.

On Thursday, August 13, 2015 at 7:48:55 PM UTC+10, DanB wrote:
Hi Jose,

If you call SetTPActions you need to make sure you reload them to tariffplanDb since these TP* are offline and never make it to live without specific activation.

Try using the ones operating on live data:
http://godoc.org/github.com/cgrates/cgrates/apier/v1#ApierV1.SetActionPlan
http://godoc.org/github.com/cgrates/cgrates/apier/v1#ApierV1.SetActions

Thanks for suggesting these APIs, I'll try this and see if it can disable the user account after setting the action plan to the ones I've configured beforehand.

Dan B

unread,
Aug 13, 2015, 2:57:48 PM8/13/15
to cgr...@googlegroups.com

Hi Jose

I just remembered that in the version you are running there was an issue with accout cache. Please upgrade your CGRateS and try again. It should fix the disable issue.

DanB

--
You received this message because you are subscribed to the Google Groups "CGRateS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cgrates+u...@googlegroups.com.
To post to this group, send email to cgr...@googlegroups.com.

Jose Gavine Cueto

unread,
Aug 20, 2015, 8:00:21 AM8/20/15
to CGRateS
Hi Dan,

Thanks for the update, will do this in our next deployment. I'll post back my results then.

Cheers
Reply all
Reply to author
Forward
0 new messages