Registration and Authentication
Registration
To access ERCOT APIs, you must register as a user on the ERCOT API Explorer website.
-
-
Navigate to API Explorer in a web browser.
-
Click the Sign In/Sign Up button in the top-right corner to open the Sign in form in a new window.
-
Click the Sign up now link at the bottom of the form to begin registering your new account.
-
Enter your email address in the form and click the Send verification code button.
-
Retrieve the verification code from your email and enter the code in the Verification Code field. Click the Verify code button to complete your email verification.
-
Once your email address has been verified, you will be able to enter a password of your choosing, your display name, and your first and last name into the form. Click the Create button to complete the registration of your account.
-
When your account registration is complete, you will be signed into the API Explorer website and have the option to sign out by clicking the Sign Out link in the top-right corner.
-
Authentication and authorization
Once you have registered, you can then access the ERCOT Public API. There are three components to this process:
- Extract the subscription key from the API Explorer
- Obtain an ID token
- Access the API using the ID token and subscription key
Extract the subscription key from the API Explorer
-
-
Sign in to the API Explorer in a web browser.
-
Navigate to the Products page found in the top navigation.
-
Select the product that you wish to subscribe to from the table: Public API.
-
Enter a name for your subscription: ie. Public API.
-
Click the Subscribe button and you will be redirected to your Profile page to view your active subscriptions.
-
Click the Show button and copy the value of the Primary key.
NOTE: It is only necessary to extract a subscription key once.
-
Obtain an ID token
ID tokens are valid for one hour. There is no way to refresh an ID token. A new ID token may be acquired by sending another POST request.
Below are examples for obtaining an ID token with either Postman, Curl, JavaScript, Java, or Python.
Obtain an ID token
Send a POST HTTP request to retrieve an ID token.
Required Query Parameters | |
---|---|
URL | https://ercotb2c.b2clogin.com/ercotb2c.onmicrosoft.com/B2C_1_PUBAPI-ROPC-FLOW/oauth2/v2.0/token |
username | <username> |
password | <password> |
grant_type | password |
scope | openid+fec253ea-0d06-4272-a5e6-b478baeecd70+offline_access |
client_id | fec253ea-0d06-4272-a5e6-b478baeecd70 |
response_type | id_token |
-
- Send a POST request to retrieve an ID token.
postman 1
https://ercotb2c.b2clogin.com/ercotb2c.onmicrosoft.com/B2C_1_PUBAPI-ROPC-FLOW/oauth2/v2.0/token?username=username@email.com&password=**********&grant_type=password&scope=openid+fec253ea-0d06-4272-a5e6-b478baeecd70+offline_access&client_id=fec253ea-0d06-4272-a5e6-b478baeecd70&response_type=id_token
- Send a POST request to retrieve an ID token.
-
- Send a POST request to retrieve an ID token.
curl 1 2 3 4 5 6 7 8
curl --data '' --request POST 'https://ercotb2c.b2clogin.com/ercotb2c.onmicrosoft.com/B2C_1_PUBAPI-ROPC-FLOW/oauth2/v2.0/token' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data 'username=username@email.com' \ --data '&password=****' \ --data '&grant_type=password' \ --data '&scope=openid+fec253ea-0d06-4272-a5e6-b478baeecd70+offline_access' \ --data '&client_id=fec253ea-0d06-4272-a5e6-b478baeecd70' \ --data '&response_type=id_token'
response 1
{"access_token":"eyJhbGciOiJS......","token_type":"Bearer","expires_in":"3600","refresh_token":"eyJraWQiOiJ.......","id_token":"eyJhbGciOiJSUzI......"}
- Send a POST request to retrieve an ID token.
-
- Send a POST request to retrieve an ID token.
javascript 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
const USERNAME = "username"; const PASSWORD = "password"; const RESOURCE = "https://ercotb2c.b2clogin.com/ercotb2c.onmicrosoft.com/B2C_1_PUBAPI-ROPC-FLOW/oauth2/v2.0/token" + "?username=" + USERNAME + "&password=" + PASSWORD + "&grant_type=password" + "&scope=openid+fec253ea-0d06-4272-a5e6-b478baeecd70+offline_access" + "&client_id=fec253ea-0d06-4272-a5e6-b478baeecd70" + "&response_type=id_token"; const OPTIONS = { method: 'POST' }; fetch(RESOURCE, OPTIONS) .then(response => response.json()) .then(result => console.log(result.id_token)) .catch(error => console.log('error', error));
response 1 2 3 4 5 6 7
{ "access_token": "eyJhbGciOiJS......", "token_type": "Bearer", "expires_in": "3600", "refresh_token": "eyJraWQiOiJ......", "id_token": "eyJhbGciOiJSUzI......" }
- Send a POST request to retrieve an ID token.
-
- Send a POST request to retrieve an ID token.
java 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
final String USERNAME = "username"; final String PASSWORD = "password"; final String SUBSCRIPTION_KEY = "subscription-key"; HttpClient httpClient = HttpClient.newHttpClient(); final String AUTH_URI = "https://ercotb2c.b2clogin.com/ercotb2c.onmicrosoft.com/B2C_1_PUBAPI-ROPC-FLOW/oauth2/v2.0/token" + "?username=" + USERNAME + "&password=" + PASSWORD + "&grant_type=password" + "&scope=openid+fec253ea-0d06-4272-a5e6-b478baeecd70+offline_access" + "&client_id=fec253ea-0d06-4272-a5e6-b478baeecd70" + "&response_type=id_token"; HttpRequest request = HttpRequest.newBuilder() .uri(URI.create(AUTH_URI)) .POST(HttpRequest.BodyPublishers.noBody()) .build(); try { // Sign in/Authenticate HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); String json = response.body(); // Retrieve response body from authorization request // Parse response for access token: String[] data = json.split("."); String bearerToken = null; for (String str : data) { String[] dataPoints = str.split(":"); if (dataPoints[0].contains("access_token")) { bearerToken = dataPoints[1].substring(1, dataPoints[1].length()-1); break; } } // Ensure that you retrieved the bearer token if (bearerToken == null) { throw new Exception("Unable to authorize user."); } System.out.println(bearerToken); }
response 1 2 3 4 5 6 7
{ "access_token": "eyJhbGciOiJS......", "token_type": "Bearer", "expires_in": "3600", "refresh_token": "eyJraWQiOiJ......", "id_token": "eyJhbGciOiJSUzI......" }
- Send a POST request to retrieve an ID token.
-
- Send a POST request to retrieve an ID token.
python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
import requests USERNAME = "username" PASSWORD = "password" SUBSCRIPTION_KEY = "subscription" # Authorization URL for signing into ERCOT Public API account AUTH_URL = "https://ercotb2c.b2clogin.com/ercotb2c.onmicrosoft.com/B2C_1_PUBAPI-ROPC-FLOW/oauth2/v2.0/token\ ?username={username}\ &password={password}\ &grant_type=password\ &scope=openid+fec253ea-0d06-4272-a5e6-b478baeecd70+offline_access\ &client_id=fec253ea-0d06-4272-a5e6-b478baeecd70\ &response_type=id_token" # Sign In/Authenticate auth_response = requests.post(AUTH_URL.format(username = USERNAME, password=PASSWORD)) # Retrieve access token access_token = auth_response.json().get("access_token")
response 1 2 3 4 5 6 7
{ "access_token": "eyJhbGciOiJS......", "token_type": "Bearer", "expires_in": "3600", "refresh_token": "eyJraWQiOiJ......", "id_token": "eyJhbGciOiJSUzI......" }
- Send a POST request to retrieve an ID token.