Question

Admin API Account

  • 7 June 2020
  • 2 replies
  • 1280 views

How can I setup an Admin account that can access records for all agents in an API call?

I want to get ALL records for from ALL agents for a phone number. ie. if I want to return all SMS messages that were sent to a phone number company wide.

Right now I have to provide credentials for a specific agent and it will only return Calls or SMS message that were sent from that one agent.


2 replies

Userlevel 1

Login your app with an Admin user (user extension with the Super Admin role. E.g. the default 101 extension). Read account extension and parse the response to make a list of extension ids (Note: extension id, NOT extension number!). Then read the message store of each extension by specifying the extension id for that extension in the query path. If you have an account with a large number of extensions (> 50 extensions) , do take care of the API rate limit. Here is a snippet code in Node JS, showing how to extensions and read the message store of other extension.

var extensionList = []
function get_extensions() {
  platform.get('/restapi/v1.0/account/~/extension')
      .then(function(resp){
          var jsonObj = resp.json
          for (var record of jsonObj.records){
              extensionList.push(record.id)
          }
          readExtensionMessageStore()
      })
      .catch(function(resp){
          console.log("Something went wrong.")
      })
}

function readExtensionMessageStore(){
  async.each(extensionList,
    function(extensionId, callback){
        var endpoint = '/account/~/extension/'+ extensionId +'/message-store
        platform.get(endpoint, {
                   dateFrom: '2018-01-01T00:00:00.000Z',
                   dateTo: '2018-07-31T23:59:59.999Z',
                   phoneNumber: "1223343434"
                   messageType: 'SMS'
          })
          .then(function (resp) {
            var jsonObj = resp.json()
            console.log(extensionId)
            console.log("=========== EXTENSION MESSAGE STORE ===========")
            console.log(JSON.stringify(jsonObj))
            console.log("+++++++++++++++++++++++++++++++++++++")
          })
          .catch(function(ex){
            console.log(ex.message)
          })
    }
  )
}


Nice I will work on getting this implemented this evening.


Can the same thing be accomplished using the API with a CURL command and putting the Super Admins login details in the header?

Reply