AnsweredAssumed Answered

Struggling to Authenticate with API

Question asked by joeprice99 on Sep 6, 2018
Latest reply on Sep 24, 2018 by joeprice99

I'm just starting out with connecting our FM database to an out of house database API.  I'm trying to authenticate to get a token and drop it a global field using insert URL.

 

I'm using this for the URL with auto encode:

"https://corpid/Authentication/AuthorizeUser"

 

What do I use for the cURL?  The example below is from the API I'm trying to access.  I know the user & pw & corpid, and have been able to get a token with API's test tool.

 

using System.Net.Http;
using System.Net.Http.Headers;

string apiToken;

 

HttpClient client = new HttpClient();
client.BaseAddress = new Uri("https://corpid.api.rentmanager.com/");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

 

// Replace Username, Password, and Location ID with those supplied by LCS.
UserAuthorizationModel uam = new UserAuthorizationModel
{

Username = "QsUser",
Password = "123456",
LocationID = 1

};

 

HttpResponseMessage response = await client.PostAsJsonAsync("/Authentication/AuthorizeUser", uam);
response.EnsureSuccessStatusCode();

 

apiToken = response.Content.ReadAsStringAsync().Result.Trim('"');

 

// For each additional API request include the apiToken in the Request Header:
client.DefaultRequestHeaders.Add("X-RM12Api-ApiToken", apiToken);

public class UserAuthorizationModel
{

public string Username { get; set; }
public string Password { get; set; }
public int LocationID { get; set; }

}

 

Please help!

 

Joe

Outcomes