There are many scenarios where you may encounter errors when working with the
Display \& Video 360 API. These could relate to a bug in your code, invalid user input,
or even an issue with the API itself. Whatever the reason, knowing how to
troubleshoot errors is an important part of the development process. This guide
will provide some best practice tips to get you started.

## Reviewing the basics

1. Review the [prequisites guide](https://developers.google.com/display-video/api/guides/getting-started/overview#prerequisites). Ensure you have access to Display \& Video 360 and a properly configured API project.
2. If your response contains HTTP errors, make sure you review these carefully and ensure that the request is being made to the correct API and service.
3. Review the [authorization guide](https://developers.google.com/display-video/api/guides/how-tos/authorizing). Ensure your request contains the necessary OAuth 2.0 credentials.
4. Verify that you're using the correct credentials. See the
   [Set Up Your Application guide](https://developers.google.com/display-video/api/guides/getting-started/configure) for details on generating
   authentication credentials. You may also pass your access token to the
   [Google OAuth2 API's tokeninfo endpoint](https://developers.google.com/apis-explorer/#p/oauth2/v2/oauth2.tokeninfo) to verify that it is
   issued to the correct API project and authorized for the correct scope(s):

       POST https://www.googleapis.com/oauth2/v2/tokeninfo?access_token={YOUR_ACCESS_TOKEN}

       200 OK

       {
        "issued_to": "{API_PROJECT_CLIENT_ID}",
        "audience": "...",
        "scope": "{API_SCOPES}",
        "expires_in": ...
       }

## Understanding errors

When the API encounters an error, it normally returns a JSON response containing
an `error` object. This object provides additional context about the specific
error that was encountered.

    {
     "error": {
      "code": 404,
      "message": "Resource type LINE_ITEM does not exist: advertisers/1/lineItems/1",
      "status": "NOT_FOUND"
     }
    }

> [!NOTE]
> **Note:** If you receive an error response that does not include an `error` object, there's a chance the error is not coming from the Display \& Video 360 API. Please refer back to the section on [reviewing the basics](https://developers.google.com/display-video/api/support/troubleshooting#basics) before continuing.

Usually the contents of the `error` object will contain enough information to
help you identify what's gone wrong. If not, you may need to do some additional
research to figure out what the error means.

### Researching errors

1. Refer to the section on [common errors](https://developers.google.com/display-video/api/guides/best-practices/errors), which provides
   details for some of the most frequently encountered errors.

2. If the error isn't covered in the common errors section, refer to the
   [reference documentation](https://developers.google.com/display-video/api/reference/rest) and try searching for the error code,
   status, and message.

3. If you come across any errors that aren't documented, please let us know.

> [!IMPORTANT]
> **Key Point:** If the error you've encountered relates to field validation or a partner/advertiser limit, review the [Display \& Video 360 help center](https://support.google.com/displayvideo) for more information. These rules and limits are inherited from Display \& Video 360 and are not enforced by the Display \& Video 360 API itself.

## Identifying the root cause

By this point you've identified the error and understand what it means. If not,
head back to [understanding errors](https://developers.google.com/display-video/api/support/troubleshooting#understand) or jump ahead to
[getting help](https://developers.google.com/display-video/api/support/troubleshooting#get-help) if you believe you've come across an error in the API
that you can't fix yourself.

Before you can fix the error, you'll need to identify what's causing it. Often
this will be a bug in your code or an invalid input value.

To determine whether the issue is related to a bug in your code, you
should first verify that your code is working as intended. As a first step,
consider reviewing the section of code responsible for making the failing
request to check for obvious issues. In some cases it may be necessary to use a
debugging tool to step through the code line-by-line to ensure it's functioning
correctly.

Examining HTTP requests is another useful way to identify potential bugs, as
well as cases of invalid input. Many of the official client libraries can be
configured to log HTTP requests and responses; review the documentation for your
library of choice for more details. An HTTP proxy such as
[Charles](https://www.charlesproxy.com/), [Squid](https://www.squid-cache.org/), or [Fiddler](https://www.telerik.com/fiddler)
can also be used to capture request and response logs. Once you obtain these
logs, review them to ensure that the request parameter values being provided by
your application are correct and match what you expect.

Once you identify the bug or invalid input responsible for causing the error,
the fix will hopefully be obvious. If you're stuck or unsure how best to fix the
problem, however, you can use the information you've gathered so far when
getting help.

### Getting help

If you aren't able to resolve an error yourself, you can contact our support
team via this [form](https://developers.google.com/display-video/api/support/contact) located in the Display \& Video 360 help center.

When filling out this form, you should include as much information as possible
about the issue you're facing and the troubleshooting steps you've already
taken. Useful information to include:

- HTTP request and response logs. Make sure to redact sensitive information such as OAuth 2.0 access tokens, email addresses, etc.
- Code snippet. If you're able to isolate the issue to a particular section of code or suspect the issue is language-specific, include a small snippet to illustrate what you're doing.
- Additional information, such as runtime/interpreter version and platform, which may be useful for others attempting to reproduce the issue.

## Fixing the issue

Once you've identified the cause of the issue and come up with a solution, it's
time to implement a fix. Whenever possible, test your fix in a controlled
environment (such as a partner or advertiser configured specifically for
testing) against a range of both good and bad inputs before deploying to
production.