0

I continue to bang my head against the wall on this call. It returns perfectly fine in postman, but when I run through VS I get the following:

Exception Message: One or more errors occurred. (Request failed with status code BadRequest).

Exception Data: System.Collections.ListDictionaryInternal

I am trying to use the latest RestSharp build, but might have to downgrade to get it working so I can just use the Postman code provided. I've ensured to get a valid token before running the script as well.

*Note that the code builds fine in VS.

using System;
using RestSharp;
using System.Net.Http;
using System.Threading.Tasks;

namespace NetSuite
{

    class Program
    {

        static void Main(string[] args)
        {

            try
            {

                MainAsync().Wait();

                static async Task MainAsync()
                {

                    var client = new RestClient("https://xxxxxxxxxxxxxxxxxxx.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql?limit=500");
                    var request = new RestRequest();

                    request.AddHeader("Content-Type", "application/json");
                    request.AddHeader("prefer", "transient");
                    request.AddHeader("Authorization", "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");


                    var body = @"{""q"": ""SELECT * FROM entity where id = 999""}";

                    request.AddParameter("application/json", body,  ParameterType.RequestBody);

                    var response = await client.PostAsync(request);

                }

            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR -- Exception Message: " + ex.Message.ToString());
                Console.WriteLine("ERROR -- Exception Data: " + ex.Data.ToString());
                System.Threading.Thread.Sleep(300);
            }

        }

    }
}
warrenk
  • 119
  • 1
  • 7
  • Face the same issue Have you found any solution? – Irfan Soetedja Sep 13 '22 at 02:14
  • @IrfanSoetedja I ended up moving away from restsharp and used Microsoft.AspNetCore.Mvc.RazorPages. ie. var client = new HttpClient(); var request = new HttpRequestMessage(); – warrenk Sep 14 '22 at 15:58

0 Answers0