Invoke code is wrapping a function. you cannot use “import” inside a fuction.
If you type Console.Writeline("Hi mom") inside Invoke code it will generated someting like
using first.import.from.importstab;
using second.import.from.importstab;
namespace SomeNamespace { public class {
public static variable1type variable1 = default(variable1type);
public static variable2type variable2 = default(variable2type);
public static void ExpressionValue() {
Console.Writeline("Hi mom")
}
}}
It compiles this to a type and calls ExpressionValue()
This is why you get debug messages in the console, to let you know the number of lines added to the type, so when you get an error message you know how many lines to subtract from the line number in the error message to find it in your invoke code code editor
var client = new System.Net.Http.HttpClient();
var request = new System.Net.Http.HttpRequestMessage
{
Method = System.Net.Http.HttpMethod.Post,
RequestUri = new Uri("https://text-analysis12.p.rapidapi.com/language-detection/api/v1.1"),
Headers = {
{ "X-RapidAPI-Key", "SIGN-UP-FOR-KEY" },
{ "X-RapidAPI-Host", "text-analysis12.p.rapidapi.com" },
},
Content = new System.Net.Http.StringContent("{ \"text\": \"Hello how are you? Have you heard about SpaceX?\"}")
{
Headers = { ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json") }
}
};
var responseTask = client.SendAsync(request);
responseTask.Wait();
var response = responseTask.Result;
response.EnsureSuccessStatusCode();
var bodyTask = response.Content.ReadAsStringAsync();
bodyTask.Wait();
var body = bodyTask.Result;
Console.WriteLine(body);