Getting started overview
Integrating with Mercedes-Benz APIs involves a structured process to ensure secure and compliant access to vehicle data. This guide outlines the essential steps from account creation to making a successful API call. The Mercedes-Benz Developer Portal serves as the central hub for all documentation, API access, and support. Developers can access various APIs, including the Car Data Platform API, EV Status API, and Charging Status API, which provide data for applications in fleet management, usage-based insurance, and smart charging solutions. The platform also supports the Pay-by-Plate API for payment solutions.
The initial setup typically involves registering an account, creating an application, and obtaining the necessary API credentials. Due to the sensitive nature of vehicle data, certain APIs may require additional verification steps to ensure data privacy and security, aligning with regulations such as GDPR compliance.
Here’s a quick reference table for the getting started process:
| Step | What to Do | Where |
|---|---|---|
| 1. Account Creation | Register on the Mercedes-Benz Developer Portal. | Developer Portal Registration |
| 2. Application Setup | Create a new application to generate API credentials. | My Applications Dashboard |
| 3. API Key Retrieval | Locate and copy your API key and secret. | Application details page |
| 4. API Subscription | Subscribe your application to the required APIs (e.g., Car Data Platform API). | API Catalog |
| 5. Authorization Flow | Implement OAuth 2.0 for user consent to access vehicle data. | OAuth 2.0 Documentation |
| 6. First API Request | Execute a test call using your credentials and an access token. | Car Data Platform API Quickstart |
Create an account and get keys
To begin, navigate to the Mercedes-Benz Developer Portal and complete the registration process. This typically involves providing an email address, setting a password, and agreeing to the terms of service. After registration, you will need to verify your email address.
- Register for an account: Visit the registration page and fill out the required information.
- Verify your email: Check your inbox for a verification link from Mercedes-Benz and click it to activate your account.
- Log in: Once verified, log in to the Developer Portal.
- Create an application: From your dashboard, locate the "My Applications" section and select "Create new app." You will need to provide an application name and description.
- Obtain API credentials: Upon creating your application, the portal will generate an API Key (also referred to as Client ID) and an API Secret (Client Secret). These are crucial for authenticating your application. Store these securely. The portal also allows you to define redirect URIs for OAuth 2.0 flows, which are essential for user consent.
- Subscribe to APIs: Browse the API catalog and subscribe your newly created application to the specific APIs you intend to use. For a quick start, subscribing to the Car Data Platform API is recommended, as it offers a free tier for initial development.
Note that for some APIs, particularly those involving sensitive vehicle data, Mercedes-Benz may require additional verification steps or approval processes before full access is granted. This is part of their commitment to data security and privacy.
Your first request
After setting up your account, creating an application, and subscribing to an API, the next step is to make your first authenticated request. Mercedes-Benz APIs primarily use OAuth 2.0 for authorization, which involves obtaining an access token after a user grants consent for their vehicle data to be accessed. The OAuth 2.0 documentation provides detailed flows.
For this example, we'll focus on a simple request to the Car Data Platform API, assuming you have already completed the OAuth 2.0 flow and obtained an access token. This token will be used in the Authorization header of your HTTP requests.
Example: Get a list of available vehicles (Car Data Platform API)
First, ensure you have an active access token. This token is typically short-lived and obtained through an OAuth 2.0 authorization code grant flow, where a vehicle owner explicitly authorizes your application. Consult the Car Data Platform API quickstart guide for details on obtaining the access token.
cURL Example:
curl -X GET \
'https://api.mercedes-benz.com/vehicledata/v2/vehicles' \
-H 'accept: application/json' \
-H 'Authorization: Bearer YOUR_ACCESS_TOKEN'
Replace YOUR_ACCESS_TOKEN with the actual access token obtained from the OAuth 2.0 process.
Python Example:
import requests
access_token = 'YOUR_ACCESS_TOKEN' # Replace with your actual access token
headers = {
'accept': 'application/json',
'Authorization': f'Bearer {access_token}'
}
url = 'https://api.mercedes-benz.com/vehicledata/v2/vehicles'
try:
response = requests.get(url, headers=headers)
response.raise_for_status() # Raise an exception for HTTP errors (4xx or 5xx)
print(response.json())
except requests.exceptions.HTTPError as http_err:
print(f'HTTP error occurred: {http_err}')
except Exception as err:
print(f'Other error occurred: {err}')
Remember to install the requests library if you haven't already: pip install requests.
JavaScript (Node.js with node-fetch) Example:
const fetch = require('node-fetch');
const accessToken = 'YOUR_ACCESS_TOKEN'; // Replace with your actual access token
const url = 'https://api.mercedes-benz.com/vehicledata/v2/vehicles';
async function getVehicles() {
try {
const response = await fetch(url, {
method: 'GET',
headers: {
'accept': 'application/json',
'Authorization': `Bearer ${accessToken}`
}
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
console.log(data);
} catch (error) {
console.error('Error fetching vehicles:', error);
}
}
getVehicles();
Install node-fetch if needed: npm install node-fetch.
A successful response will typically return a JSON array of vehicle IDs or aggregated vehicle information, depending on the specific API endpoint and the permissions granted by the vehicle owner.
Common next steps
Once you've made your first successful API call, consider these common next steps to further develop your integration:
- Explore other APIs: Mercedes-Benz offers a range of APIs beyond the Car Data Platform, such as the EV Status API, Charging Status API, and Fuel Status API. Review the API catalog to identify services relevant to your application's needs.
- Implement webhooks: For real-time event notifications (e.g., vehicle status changes, charging events), explore the use of webhooks. This can reduce polling and improve efficiency. Consult the Webhook documentation for implementation details.
- Manage data consent: For production applications, robust handling of user consent and data privacy is paramount. Ensure your application aligns with GDPR and other relevant data protection regulations. The Mercedes-Benz data privacy guidelines provide critical information.
- Monitor API usage: Utilize the developer portal's tools to monitor your API call volume and performance. This helps in understanding usage patterns and managing your API subscriptions and costs.
- Scale your application: As your application grows, you may need to upgrade your API subscription plan from the free tier to a paid plan. Review the pricing page for details on different tiers and custom pricing options.
- Explore SDKs: While Mercedes-Benz does not list official SDKs, community-contributed libraries or custom wrappers can simplify API interactions. Consider abstracting API calls into a reusable module for your chosen programming language.
Troubleshooting the first call
Encountering issues during your initial API call is common. Here are some troubleshooting tips:
- Check API Key and Secret: Ensure your API Key (Client ID) and Secret (Client Secret) are correctly copied from your application details page on the Developer Portal. Incorrect credentials will result in authentication failures.
- Verify Access Token: The most frequent issue is an expired or invalid OAuth 2.0 access token. Access tokens are typically short-lived. Re-run your OAuth 2.0 flow to obtain a fresh access token. Ensure the token is correctly placed in the
Authorization: Bearer YOUR_ACCESS_TOKENheader. - Review API Subscription: Confirm that your application is subscribed to the specific API you are trying to call (e.g., Car Data Platform API). If not subscribed, you will receive authorization errors. Check your application subscriptions.
- Incorrect Endpoint or Method: Double-check the API endpoint URL and the HTTP method (GET, POST, etc.) against the API reference documentation. A common mistake is using a GET request for an endpoint that requires a POST, or vice-versa.
- Scope Permissions: Ensure the access token you obtained has the necessary scopes (permissions) for the data you are trying to access. If a vehicle owner did not grant permission for a specific data point, the API will return an authorization error.
- Network Issues: Verify your internet connection and ensure no firewalls or proxies are blocking your outgoing requests to
api.mercedes-benz.com. - Rate Limits: For the free tier, there are rate limits (e.g., 1,000 requests/month). If you exceed these, you may receive
429 Too Many Requestserrors. Monitor your usage in the Developer Portal. - Consult Documentation and Support: If issues persist, refer to the specific API documentation for error codes and troubleshooting guides. The Mercedes-Benz Developer Portal also provides support forums and contact options.