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);
}
}
}
}
You're missing the authentication code. Here is a sample using your suiteql request. I have found that RestSharp will not work with the Method.Option for the test post in the NetSuite Rest API Tutorial Postman sample. Wasted a day on that and then decided to try a Method.Post it it worked fine. Get the token information found in the tutorial at NetSuite Getting Started with Token-based Authentication