-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
43 lines (31 loc) · 1.7 KB
/
Copy pathProgram.cs
File metadata and controls
43 lines (31 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// See https://aka.ms/new-console-template for more information
using System.Net.Http.Headers;
//variables:
//CustomConnectorUrl(Required) - url of the api used in the custom connector.
string CustomConnectorUrl = "https://conferenceapi.azurewebsites.net/sessions";// "[REPLACE WITH YOUR CUSTOM CONNECTOR URL]";
//OperationId(Required) - the operation id for the custom connector.
string OperationId = "GetSessions";//"[REPLACE WITH YOUR OPERATION ID]";
//Ocp-Apim-Subscription-Key(Optional) - the subscription key for the custom connector if using a service like API-M.
string OcpApimSubscriptionKey = "[REPLACE WITH YOUR OCP APIM SUBSCRIPTION KEY]";
try
{
//create the HttpRequest that matches the request on the custom connector
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, CustomConnectorUrl);
requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//ADD ANY ADDITIONAL HEADERS HERE
//API-Management Subscription Key - uncomment if using API-M
// requestMessage.Headers.Add("Ocp-Apim-Subscription-Key", OcpApimSubscriptionKey);
//create a new script object
var myScript = new Script();
//create a scriptcontext object and assign it to the Context property of the script class
var myScriptContext = new ScriptContext(OperationId, requestMessage);
myScript.Context = myScriptContext;
//use the script object to execute the api call
HttpResponseMessage response = myScript.ExecuteAsync().ConfigureAwait(true).GetAwaiter().GetResult();
//write the results to the console.
Console.WriteLine(response.Content.ReadAsStringAsync().Result);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}