
Getting Started
In your welcome email, you should have received the following information that is required for you to start using the Skanska API.
Client Id - This ID is specific to you and your company.
Client Secret - The password for your Client Id. Do not share this or lose it! We can regenerate a new one for you, but cannot give you the original value.
Tennant Id - The ID of our tennant. This is used to request a JWT.
APIM Uri - The Uri of our API, which will be used as the scope or audience of your authorization request.
Postman Collection
Our example postman collection includes requests that demonstrate how to get a JWT and how to call the Skanska API.
The collection expects you to have environmental variables setup for the information mentioned above.
Visual Studio Code
The REST Client extension makes it super easy to make requests within VS Code. Use the following snippet to grab a token and start using the API right away.
@tennantId = {tennant Id}@apimUri = {APIM Uri}@clientId = {your client id}@clientSecret = {your client secret}
### Get the JWT token using the v2 endpoint.# @name apiProxy
POST https://login.microsoftonline.com/{{tenantId}}/oauth2/v2.0/tokenContent-Type: application/x-www-form-urlencoded
client_id={{clientId}}&client_secret={{clientSecret}}&scope=apimUri&grant_type=client_credentials
@authToken = {{apiProxy.response.body.access_token}}
### Call the Protected endpointGET https://us-skanska-dev.azure-api.net/Entities/api/CostCodes?$count=false&api-version=1.0Authorization: Bearer {{authToken}}
ASP.Net Core 3.1
The RestSharp NuGet package makes it simple to build and make requests.
private static string tennantId = {"tennant Id"}; private static string apimUri = {"APIM Uri"}; private static string clientId = {"client Id"}; private static string clientSecret = {"client secret"};
static void Main(string[] args){string jwt = GetJWT();
MakeRequest(jwt);Console.WriteLine("Hit ENTER to exit...");Console.ReadLine();
}
static string GetJWT(){var client = new RestClient("https://login.microsoftonline.com/" + tennantId + "/oauth2/v2.0/token");client.Timeout = -1;var request = new RestRequest(Method.POST);request.AddHeader("Content-Type", "application/x-www-form-urlencoded"); request.AddParameter("client_id", clientId); request.AddParameter("client_secret", clientSecret);request.AddParameter("scope", apimUri); request.AddParameter("grant_type", "client_credentials");
IRestResponse response = client.Execute(request);
string token = JsonSerializer.Deserialize<Dictionary<string, object>>(response.Content)["access_token"].ToString();
if (token != null){return token;} else{throw new Exception("No token");}
}
static void MakeRequest(string jwt){var client = new RestClient("https://us-skanska-dev.azure-api.net/Entities/api/Offices?api-version=1.0");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", jwt);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
}