News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Message Store Export C# Index does not contain definition for List
Tags: developer sandbox, sms and text messaging, message, sdk, rest api
Feb 29, 2024 at 9:28am   •   1 replies  •  0 likes
Adam Burgess

I am trying to test out the Message Store Export (kinda new at this) and am running into some errors. I am using the code from the documentation here. I already replaced the depreciated WebClient with HTTP but am still getting this error:

Error CS1061 'Index' does not contain a definition for 'List' and no accessible extension method 'List' accepting a first argument of type 'Index' could be found (are you missing a using directive or an assembly reference?)

I do have the RingCentral SDK installed. Any help would be appreciated!

using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using RingCentral;

namespace Export_MessageStore
{
    class Program
    {
        static RestClient restClient;
        static HttpClient httpClient = new HttpClient();

        static async Task Main(string[] args)
        {
            try
            {
                // Instantiate the SDK
                restClient = new RestClient("SANDBOX-APP-CLIENTID", "SANDBOX-APP-CLIENTSECRET", "https://platform.devtest.ringcentral.com");
                // Authenticate a user using a personal JWT token
                await restClient.Authorize("SANDBOX_JWT");

                await CreateMessageStoreReport();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        static private async Task CreateMessageStoreReport()
        {
            var bodyParams = new CreateMessageStoreReportRequest
            {
                dateFrom = "2023-03-01T00:00:00.000Z",
                dateTo = "2023-03-31T23:59:59.999Z"
            };

            var response = await restClient.Restapi().Account().MessageStoreReport().Post(bodyParams);
            await GetMessageStoreReportTask(response.id);
        }

        static private async Task GetMessageStoreReportTask(string taskId)
        {
            bool isCompleted = false;
            while (!isCompleted)
            {
                var response = await restClient.Restapi().Account().MessageStoreReport(taskId).Get();
                Console.WriteLine("Task creation status: " + response.status);
                switch (response.status)
                {
                    case "Completed":
                        isCompleted = true;
                        await GetMessageStoreReportArchive(taskId);
                        break;
                    case "AttemptFailed":
                    case "Failed":
                    case "Cancelled":
                        Console.WriteLine("Export message store failed.");
                        return;
                    default:
                        await Task.Delay(10000); // Use non-blocking delay
                        break;
                }
            }
        }

        static private async Task GetMessageStoreReportArchive(string taskId)
        {
            Console.WriteLine("Getting report uri ...");
            var resp = await restClient.Restapi().Account().MessageStoreReport(taskId).Archive().List();
            var dateStr = DateTime.Now.ToString("yyyy-MM-dd-HH_mm");
            for (var i = 0; i < resp.records.Length; i++)
            {
                var fileName = $"message_store_content_{dateStr}_{i}.zip";
                var contentUrl = $"{resp.records[i].uri}?access_token={restClient.token.access_token}";

                // Use HttpClient for downloading the file
                var response = await httpClient.GetAsync(contentUrl);
                if (response.IsSuccessStatusCode)
                {
                    using (var stream = await response.Content.ReadAsStreamAsync())
                    using (var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
                    {
                        await stream.CopyToAsync(fileStream);
                    }
                    Console.WriteLine($"{fileName} file is saved to the local machine.");
                }
                else
                {
                    Console.WriteLine($"Failed to download file: {fileName}");
                }
            }
        }
    }
}
1 Answer
answered on Feb 29, 2024 at 1:39pm  

There was a change and it causes the mistake in the sample code. Please modify the code in this function. Change List() to Get().

static private async Task get_message_store_report_archive(String taskId)
{
    Console.WriteLine("Getting report uri ...");
    var resp = await restClient.Restapi().Account().MessageStoreReport(taskId).Archive().Get();
    DateTime value = DateTime.Now;
    ...
}

I will update the sample code soon.


 1
on Mar 1, 2024 at 11:05am   •  0 likes

For some reason when I filter to SMS, I get nothing. I can Read_MessageStore and filter it to SMS and that come out okay. When I filter this line of code (with your awesome fix), nothing comes up when it is outputted. Is filtering not able to be used when exporting?

        static private async Task CreateMessageStoreReport()
        {
            var bodyParams = new CreateMessageStoreReportRequest
            {
                dateFrom = "2024-03-01T12:00:00.000Z",
                dateTo = "2024-03-01T13:00:00.000Z",
                messageTypes = new[] {"SMS"}
            };

            var response = await restClient.Restapi().Account().MessageStoreReport().Post(bodyParams);
            await GetMessageStoreReportTask(response.id);
        }

        static private async Task GetMessageStoreReportTask(string taskId)
        {
            bool isCompleted = false;
            while (!isCompleted)
            {
                var response = await restClient.Restapi().Account().MessageStoreReport(taskId).Get();
                Console.WriteLine("Task creation status: " + response.status);
                switch (response.status)
                {
                    case "Completed":
                        isCompleted = true;
                        await GetMessageStoreReportArchive(taskId);
                        break;
                    case "AttemptFailed":
                    case "Failed":
                    case "Cancelled":
                        Console.WriteLine("Export message store failed.");
                        return;
                    default:
                        await Task.Delay(10000); // Use non-blocking delay
                        break;
                }
            }
        }

        static private async Task GetMessageStoreReportArchive(string taskId)
        {
            Console.WriteLine("Getting report uri ...");
            var resp = await restClient.Restapi().Account().MessageStoreReport(taskId).Archive().Get();
            var dateStr = DateTime.Now.ToString("yyyy-MM-dd-HH_mm");
            for (var i = 0; i < resp.records.Length; i++)
            {
                var fileName = $"message_store_content_{dateStr}_{i}.zip";
                var contentUrl = $"{resp.records[i].uri}?access_token={restClient.token.access_token}"
on Mar 1, 2024 at 12:46pm   •  0 likes

It should work and it worked for me. I am not sure about your message store and if there is any SMS sent/received between that period of time. And BTW, which zip file did you check? The 0.zip should be the one that contain the SMS message, the x.zip file(s) are for attachments (MMS, Fax, Voicemails etc.) if any.

on Mar 1, 2024 at 7:44pm   •  0 likes

Is there a time frame in which SMS can be retrieved? Like you have to wait X time before you can export SMS data from the message store, like it will be available?

on Mar 2, 2024 at 8:11am   •  0 likes

No. If you still can read the message store using the list messages API, you should be able to export it via the message store report API. Please wait for the dev support team to look into your case.

on Mar 1, 2024 at 1:20pm   •  0 likes

I am really not sure what is going on. I am not getting anything even without filtering. I know my auth creds are right and the app has the MessageRead permission (unless it needs more?) I submitted a ticket to dev support, hopefully we can figure it out. I am only getting one Zip back and in that time range there were definitely faxes/vms/sms in that time range.



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

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us