question

James Peragine avatar image
James Peragine asked ·

Admin API Account

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.

api
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image
Phong Vu answered ·

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)
          })
    }
  )
}


Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

James Peragine avatar image
James Peragine answered ·

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?

1 comment Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Surely it will work with CURL.

0 Likes 0 · ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.