How to authenticate and access Servicenow workflow from .net c# REST API call. Servicenow account having OCTA authentication

nataraju
Kilo Explorer

My organization having Service now account and created workflow and currently accessing through servicenow website. Having the authorization connected with microsoft account. i need to access workflow from .net c# with REST API call.i tried with basic authentication code, but am not able to authorize to access. Can you help me to how to authorize to servicenow account and access the workflow.

var client = new HttpClient();
client.BaseAddress = new Uri("https://XXXXX/nav_to.do?uri=%2Fu_accounts_XXXXX_list.do%3Fsysparm_first_row%3D1%26sysparm_query%3Dactive%253Dtrue%255Eu_assignment_group%2XXXXX484%26sysparm_view%3D");

var request = new HttpRequestMessage(HttpMethod.Post, "/path");

var byteArray = new UTF8Encoding().GetBytes("<clientid>:<clientsecret>");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));

var formData = new List<KeyValuePair<string, string>>();
formData.Add(new KeyValuePair<string, string>("grant_type", "password"));
formData.Add(new KeyValuePair<string, string>("username", "XXXX@lkqcorp.com"));
formData.Add(new KeyValuePair<string, string>("password", "XXXXX"));
formData.Add(new KeyValuePair<string, string>("scope", "all"));

request.Content = new FormUrlEncodedContent(formData);
var response = await client.SendAsync(request);
var contents = await response.Content.ReadAsStringAsync();

 

11 REPLIES 11

If i use above mentioned login , is it allow me to get workflow data without authorization.

Ravi9
ServiceNow Employee
ServiceNow Employee

you cant access anything without authorization in the platform