> ## Documentation Index
> Fetch the complete documentation index at: https://docs.megaport.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Troubleshooting the API

> This help topic describes troubleshooting steps to identify and solve problems when using the Megaport API.

If you encounter problems with the API or with the Megaport Terraform solution, step through these troubleshooting actions.

For API tutorials and a step-by-step guide, see [Megaport API Overview](/api). For a full reference, including working examples, see [https://dev.megaport.com/](https://dev.megaport.com/).

To try out the API, we recommend the Postman client with the imported Megaport Collection; information on downloading and using Postman is in the documentation.

## Troubleshooting actions

| **Action**                                  | **Steps**                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| :------------------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Ensure API access token is valid**        | Megaport API calls require an access token that you can generate after creating an API key. An access token is required for authenticating API users, and allows temporary access to only the parts of the Megaport Portal that are required. Access tokens expire after a maximum of 24 hours, after which you need to generate a new access token. For more information, see [Creating an API Key](/api/api-key).                                                                    |
| **Ensure API environment (URL) is correct** | Ensure that the URLs you are using are for the intended environment.<br /><ul><li>PRODUCTION - `https://api.megaport.com`<br />The fully functional, live system. You are responsible for any services and associated costs ordered in this system.</li><li>STAGING - `https://api-staging.megaport.com`<br />Lets you test commands without impact to your production environment. The staging environment is overwritten every 24 hours with the latest production values.</li></ul> |
| **Ensure API parameters are correct**       | The Megaport API uses standard HTTP response codes. Generally speaking, a 400 - Bad Request error is typically caused by missing or incorrect parameters. If you are receiving this error, double check your parameters.                                                                                                                                                                                                                                                               |
| **Ensure your API syntax is correct**       | The correct syntax is essential when interacting with the Megaport API. The Megaport API is based on REST, has predictable URLs, and accepts form-encoded request bodies. <br /><br />You can see examples of the correct calls on [https://dev.megaport.com](https://dev.megaport.com/). Select your preferred language from the drop-down menu on this page, and you can see examples of how to do anything within the API environment.                                              |
| **API Limits**                              | **General Rate Limit** <br />There is a rate limit of 500 requests in a rolling 5 minute period per IP address. <br /><br />**Service Updates** <br />You can only make one service update every 5 minutes, and there is a maximum of 100 updates per month per service. <br /><br />**Note:** Currently, these are not hard limits, but Megaport monitors and reviews when limits are breached. If limit breaches occur, access could be blocked.                                     |

## Common API error messages

### Login error

```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
"message": "Bad session token - try logging in again."
```

Common causes:

* incorrect username, email, or password
* missing or incorrect token

### Syntax error

```text theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
HTTP Status 400 – Bad Request
```

The error commonly occurs when a required syntax is missing or incorrect.

### Incorrect API URL

An example of the error related to an incorrect URL is:

```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
"message": "Service abcd1234 has wrong product type VXC"
```

For this scenario, the customer used this URL:

```text theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
URL = "https://api-staging.megaport.com/v2/product/megaport/abcd1234-1234-1234-1234-abcdef123456/telemetry?from=1614283800000&to=1614284400000&type=BITS"
```

but the correct URL is:

```text theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
URL = "https://api-staging.megaport.com/v2/product/vxc/abcd1234-1234-1234-1234-abcdef123456/telemetry?type=A_BITS&from=1614283800000&to=1614284400000"
```

### Incorrect parameters

As an example, a customer reported no data output when requesting VXC telemetry for this time range:

* From: GMT: Tuesday, August 3, 2021 1:52:23 PM
* To: GMT: Tuesday, August 3, 2021, 1:57:23 PM

Syntax

```text theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
https://api-staging.megaport.com/v2/product/vxc/abcd1234-1234-0000000000telemetry?type=A_BITS&from=1627998743&to=1627999043
```

Output

```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{"serviceUid":"abcd1234-1234-0000000000","type":"A_BITS","timeFrame":{"from":1627998743,"to":"1627999043},"data":[]}
```

From the [Get VXC Telemetry docs](https://dev.megaport.com/#28c05fb0-582b-4498-8e29-d2144111c8de) the From and To parameters must be set in milliseconds for each epoch value (so each value needed extra zeros at the end):

```text theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
https://api-staging.megaport.com/v2/product/vxc/abcd1234-1234-0000000000telemetry?type=A_BITS&from=1627998743000&to=1627999043000
```

## Megaport required data

If the troubleshooting actions do not resolve your issue, contact Megaport Support.
With an API issue, Megaport will investigate and troubleshoot the issue at the back end.

To assist the investigation, provide the results of the tests you performed and any other relevant information, such as:

* Email/account used
* Date, time, and time zone of action and when the error occurred
* API configuration
* API URL
* Body data
* Endpoint parameters and syntax
* Error type and a screenshot of the error

## Helpful references

* [Solutions to Common API Issues With Megaport](https://www.megaport.com/blog/solutions-to-common-api-issues-with-megaport/)
