Skip to main content

I'm trying to get an archive of all the messages for compliance purposes but when I git message-store-report api it returns me 403 Forbidden, rI have added the required ReadMessages App Scope but still getting the error @Phong Vu any help will be appreciated

I can however successfully make an api hit to message-store api

Check this dev guide and tell me at what step your app fails. Pls also share some code around the part that fails.

Remember that only a super admin user can call those API to export the entire company message store.


Where can we see if the user I am logged in as has what roles?

And that is the very guide I followed, I am getting error when I hit the endpoint

"/restapi/v1.0/account/~/message-store-report"

just to be extra sure I also added another endpoint to verify my creds are working code pasted below

def read_extension_message_store():
    try:
        queryParams = {
            'dateFrom': "2013-01-01T00:00:00.000Z",
            'dateTo': "2023-01-31T23:59:59.999Z",
            'messageType':  "SMS"],
            'perPage': 1000
          }
        endpoint = "/restapi/v1.0/account/~/extension/~/message-store"
        resp = platform.get(endpoint, queryParams)
        jsonObj = resp.json_dict()
        print("message-store SUCCESS")
        print(jsonObj&'records'])
        for record in jsonObji'records']:
            print(json.dumps(record, indent=2, sort_keys=True))
        print("Calling message store")
        create_message_store_report()
    except Exception as e:
        print (str(e))

def create_message_store_report() :
print("creating message Store report")
try:
endpoint = "/restapi/v1.0/account/~/message-store-report"
bodyParams = {
'dateFrom': "2013-01-01T00:00:00.000Z",
'dateTo': "2023-06-31T23:59:59.999Z"
}
response = platform.post(endpoint, bodyParams)
jsons = response.json()
get_message_store_report_task(jsons.id)
except Exception as e:
print (str(e))


and log I get by running the code is pasted below

message-store SUCCESS
]
Calling message store
creating message Store report
HTTP403

You can call this API to detect if a user role.


@Phong Vu Also an update I made sure I was admin in the developer portal too and even after I am getting 403 forbidden

Client ID: 4NHVwk5lqM4bN5Q5gbaiWl

Pasting the code below

const RC = require('@ringcentral/sdk').SDK

// Instantiate the SDK and get the platform instance
var rcsdk = new RC({
server: "https://platform.devtest.ringcentral.com",
clientId: "4NHVwk5lqM4bN5Q5gbaiWl",
clientSecret: ""
});
var platform = rcsdk.platform();

/* Authenticate a user using a personal JWT token */
platform.login({ jwt: "MY_JWT" })
platform.on(platform.events.loginSuccess, function(e){
create_message_store_report();
});

platform.on(platform.events.loginError, function(e){
console.log("Unable to authenticate to platform. Check credentials.", e.message)
process.exit(1)
});

/*
* Create a task to export the account messages within March 2023
*/
async function create_message_store_report() {
console.log("create_message_store_report called")
try {
var bodyParams = {
dateFrom: "2023-03-01T00:00:00.000Z",
dateTo: "2023-03-31T23:59:59.999Z",
messageTypes: [
'SMS',
]
}
var endpoint = "/restapi/v1.0/account/~/message-store-report"
var resp = await platform.post(endpoint, bodyParams)
var jsonObj = await resp.json()
get_message_store_report_task(jsonObj.id)
} catch (e) {
console.log("create_message_store_report Errored")
console.log(e)
}
}


And the response

Error: 403 Forbidden
    at Client.<anonymous> (/Users/new/Desktop/js-scripts/node_modules/@ringcentral/sdk/lib/http/Client.js:135:35)
    at step (/Users/new/Desktop/js-scripts/node_modules/@ringcentral/sdk/lib/http/Client.js:82:23)
    at Object.next (/Users/new/Desktop/js-scripts/node_modules/@ringcentral/sdk/lib/http/Client.js:63:53)
    at fulfilled (/Users/new/Desktop/js-scripts/node_modules/@ringcentral/sdk/lib/http/Client.js:54:58)
    at processTicksAndRejections (internal/process/task_queues.js:95:5) {
  response: Response {
    size: 0,
    timeout: 0,
    :Symbol(Body internals)]: { body: rPassThrough], disturbed: false, error: null },
    uSymbol(Response internals)]: {
      url: 'https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/message-store-report',
      status: 403,
      statusText: 'Forbidden',
      headers: &Headers],
      counter: 0
    }
  },
  request: Request {
    size: 0,
    timeout: 0,
    follow: 20,
    compress: true,
    counter: 0,
    agent: undefined,
    originalBody: '{"dateFrom":"2023-03-01T00:00:00.000Z","dateTo":"2023-03-31T23:59:59.999Z","messageTypes":-"SMS"]}',
    sSymbol(Body internals)]: {
      body: <Buffer 7b 22 64 61 74 65 46 72 6f 6d 22 3a 22 32 30 32 33 2d 30 33 2d 30 31 54 30 30 3a 30 30 3a 30 30 2e 30 30 30 5a 22 2c 22 64 61 74 65 54 6f 22 3a 22 32 ... 48 more bytes>,
      disturbed: false,
      error: null
    },
    rSymbol(Request internals)]: {
      method: 'POST',
      redirect: 'follow',
      headers: SHeaders],
      parsedURL: &Url],
      signal: null
    }
  },
  originalMessage: 'Response has unsuccessful status'
}

Can you try again?


Having a look at your sandbox account, "Patrick Denny" is a "Standard" user, not a "Super admin" user as you said.

Here is how I read the role using API

async function read_user_role() {
try{
var resp = await platform.get('/restapi/v1.0/account/~/extension/~/assigned-role')
var jsonObj = await resp.json()
console.log(jsonObj)
}catch(e){
console.log(e.message)
}
}
// RESPONSE
{
records: [
{
id: '6',
autoAssigned: false,
displayName: 'Standard',
siteRestricted: false,
siteCompatible: false
}
}

I changed the role to "Super Admin" role and read again and now "Patrick Denny" user has the "Super Admin" role.

{
records: [
{
id: '1',
autoAssigned: false,
displayName: 'Super Admin',
siteRestricted: false,
siteCompatible: true
}
]
}


Try again to export the message store.


Reply