Enode Developers

Make your first API call

The Enode API lets you connect to a wide range of green energy hardware. In this guide, we will show you how to link devices to a user and make your first API call by fetching the user.

Copy linkPrerequisites

Copy linkFetching simulated or real devices

You will receive one set of credentials for the sandbox environment, and one set of credentials for the production environment. Before making any requests, you should decide whether you want to fetch mocked or real devices.

  • For mocked devices, use the sandbox environment
  • For real devices, use the production environment

In this guide, we will refer to the sandbox environment. If you would like to fetch real devices, replace the sandbox with production in the URLs below. Make sure your client_id and client_secret matches the environment your are working against.

Copy linkStep 1: Get an API access token

To begin, use your client_id and client_secret to call the Enode OAuth API.

While this guide uses cURL for examples, you can follow along in Postman if you prefer. To obtain your access token in Postman, use these settings. We also keep an updated Postman collection.

Sample

curl https://oauth.sandbox.enode.io/oauth2/token \
-X POST \
-u {YOUR_CLIENT_ID}:{YOUR_CLIENT_SECRET} \
-d "grant_type=client_credentials"

If you provided the right values, you should get a successful response back containing an access_token.

Sample

{
	"access_token": "{YOUR_ACCESS_TOKEN}",
	"expires_in": 3599,
	"scope": "",
	"token_type": "bearer"
}

Next up, use the returned access_token to create a LinkAPI session. This session will give the user temporary access to Enode Link UI, a simple web interface for linking their hardware to your app.

Sample

curl https://enode-api.sandbox.enode.io/users/1ab23cd4/link \
-X POST \
-H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d '{ "vendorType": "vehicle" }'

In this call, 1ab23cd4 represents the userId of your user. You can pass any string uniquely identifying your user. If this user does not already exist, the API will create a user for you. You can read more about this in our API referenceAPI.

If you provided a valid access_token to this call, you should get a successful response back including a linkUrl.

Link response

{
  "linkState": "WFiMjNjZDRANThlZmIyMzMtYTNjNS00NjkwLWEwNmEtMGRhNmJhNWQ0Y2QzOjlkZjVhY2NiMzc1MjcyYzI1YzRlNjY3YzczMTVlNmI2ZGM3ODQwMDExMmRhZjcxNzZjNjk0YzYwZTVkY2Q1MzE=",
  "linkUrl": "{YOUR_LINK_URL}"
}

Copy and open the linkUrl returned from the previous step in your browser. To go through the flow, you can pick any vehicle brand.

  • The sandbox environment does not authenticate users, so you can provide any combination of e-mail, password and two-factor authentication code, like the example below
  • The production environment does authenticate real users and will only accept valid user credentials

Sample

Username: user@example.com
Password: 1234
Two-factor code: 123456
Download

If you see a Connection successful screen at the end of the Link flow, you can move on to the next step.

In this case, clicking “Complete” on the Connection successful screen will redirect you to about:blank. If you wish to specify your own redirect URL, you can do so by passing a redirectUri to the Link call completed in the previous step. For more information, see our API referenceAPI.

Copy linkStep 4: Fetch the user

Now that you have linked one or multiple vehicles to your user, you can fetch the user using the /me endpoint. You refer to your user by passing an Enode-User-Id header with our request.

Sample

curl https://enode-api.sandbox.enode.io/me \
-X GET \
-H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" \
-H "Enode-User-Id: 1ab23cd4"

If you provided the correct values, you should get a response back containing the user object. The linkedVendors array should include the vendor you linked in step 3.

Sample

{
  "id": "1ab23cd4",
  "linkedVendors": [
    {
      "vendor": "{YOUR_LINKED_VENDOR}", // For example: "TESLA", "VOLKSWAGEN"
      "isValid": true
    },
		// If you linked additional vendors, they will show up here
  ]
}

Copy linkAll done!

Congratulations, you just made your first call to the Enode API! To learn more about using our API, you can continue to our next guide or browse our API reference.

Next article: Fetch vehicle charge state

Get live data from your linked device

Browse our API reference

The ins and outs of our endpoints

Was this article helpful?