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
@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: [PassThrough], disturbed: false, error: null }, [Symbol(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"]}', [Symbol(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 }, [Symbol(Request internals)]: { method: 'POST', redirect: 'follow', headers: [Headers], parsedURL: [Url], signal: null } }, originalMessage: 'Response has unsuccessful status' }
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.
Thank you that worked, and sorry for confusion for super admin account I looked under sandbox account->Organization->developer list and another place I looked at was under ringcetral admin panel user list and searched for my user which said Super Admin. What am I missing can you please guide? @Phong Vu
As a "Standard" user, you cannot change the role for yourself. You have to ask the account super admin user to login the account service web (be it a production account or a sandbox account) to change the user role for other users. Here is how your user extension looks like before I changed the role.
Can you try again?
Did still getting same error
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 jsonObj['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.
That api isn't returning me any roles. I do have Read Accounts app perm and I waited good amount of time before making those api calls to ensure the perms are placed. Could it be because of the Feature Flag? if yes how do I set or unset a feature flag? Also if I log into admin panel I do have the super admin role there (the user I am using JWT of).
Response { size: 0, timeout: 0, [Symbol(Body internals)]: { body: Gunzip { _writeState: [Uint32Array], _readableState: [ReadableState], _events: [Object: null prototype], _eventsCount: 5, _maxListeners: undefined, _writableState: [WritableState], allowHalfOpen: true, bytesWritten: 0, _handle: [Zlib], _outBuffer: <Buffer 7b 0a 20 20 22 72 65 63 6f 72 64 73 22 20 3a 20 5b 20 7b 0a 20 20 20 20 22 69 64 22 20 3a 20 22 33 22 2c 0a 20 20 20 20 22 61 75 74 6f 41 73 73 69 67 ... 16334 more bytes>, _outOffset: 0, _chunkSize: 16384, _defaultFlushFlag: 2, _finishFlushFlag: 2, _defaultFullFlushFlag: 3, _info: undefined, _maxOutputLength: 4294967295, _level: -1, _strategy: 0, [Symbol(kCapture)]: false, [Symbol(kTransformState)]: [Object], [Symbol(kError)]: null }, disturbed: false, error: null }, [Symbol(Response internals)]: { url: 'https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/assigned-role?showHidden=true', status: 200, statusText: 'OK', headers: Headers { [Symbol(map)]: [Object: null prototype] }, counter: 0 } }
What is your app client id? And how do you call and catch the response of the above API?
Client ID:4NHVwk5lqM4bN5Q5gbaiWl
and thats just a console.log of the response I get back from 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.
A new Community is coming to RingCentral!
Posts are currently read-only as we transition into our new platform.We thank you for your patience
during this downtime.
Try Workflow Builder
Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!Try RingCentral Workflow Builder