API Authentication

Modified on Thu, 27 Mar at 12:58 PM

The API uses OpenID Connect (OIDC) as an authentication protocol. It is a well-known standard and subset of OAuth 2.0. There are many libraries that can be useful when implementing a client in most languages.


How to get an access token

The client uses a client ID and secret to identify itself and receives an access token upon successful authentication. Please contact Position Green to get credentials to use when accessing the API.


Get an access token

POST  https://login.positiongreen.com/connect/token

First, send an HTTP POST to/connect/token with the parameters below. Where grant_type is “client_credentials” and client_id and client_secret have been provided for your client. 


The response, if the status code is 200, contains JSON with the property access_token. This is used in all requests with Position Green API. 


Send an HTTP POST to /connect/token with the following form parameters to retrieve an access token.


Path Parameters

NameTypeDescription

client_id

string

The client id you've received from Position Green

client_secret

string

The client secret you've received from Position Green

grant_type

string

Should be set to client_credentials



{
    "access_token":"<access token>",
    "expires_in":3600,
    "token_type":"Bearer"
}

Example, getting an access token using curl


Execute the following on one line and replace client_secret, client_id, and api-url.

curl --location --request POST 
--header "Content-Type: application/x-www-form-urlencoded" 
--data-urlencode "grant_type=client_credentials"
--data-urlencode "client_secret=<client_secret>"
--data-urlencode "client_id=<client_id>"
"<api-url>/connect/token"

Example getting an access token using C#


var client = new HttpClient(); 
client.BaseAddress = new Uri(loginUrl); 

var data = new Dictionary<string, string> 
{
{"client_id", "your-client-id"},
{"client_secret","your-client-secret" }, 
{"grant_type", "client_credentials"}, 
};
var response = await client.PostAsync( 
"/connect/token", 
new FormUrlEncodedContent(data)); 

var stringResponse = await response.Content.ReadAsStringAsync();


Response


{
   "access_token": "<access token>",
   "expires_in": 3600,
   "token_type": "Bearer"
}

Alternatively, use client_id and secret in the header


articleInstead of getting an access token it is possible to send the client id and secret when accessing any operations in Position Green API. To generate API credentials check this article.


Send the client id and secret


NameValue

client_id

Your client id

client_secret

Your client secret



Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article