> For the complete documentation index, see [llms.txt](https://docs.servoy.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.servoy.com/reference/servoyextensions/server-plugins/oauth/oauthresponsejson.md).

# OAuthResponseJSON

## Overview

The `OAuthResponseJSON` object is designed for handling JSON responses during OAuth authentication. It provides methods to extract key elements from the response, such as the body content, HTTP response code, and headers. Additionally, it allows parsing the response body into a JSON object for easier manipulation.

The `getAsJSON()` method converts the response body into a JSON object, enabling structured data handling. For accessing raw content, the `getBody()` method returns the response body as a string. The `getCode()` method retrieves the HTTP response code as a number, which is useful for determining the status of the OAuth transaction. To access specific metadata, the `getHeader(name)` method fetches the value of a header by name, while the `getHeaders()` method returns all headers in an array format.

For more information about authentication using the OAuth service, refer to the [OAuth Provider](https://docs.servoy.com/guides/develop/security/authentication#oauth-provider) from the [Authentication](https://docs.servoy.com/guides/develop/security/authentication) section of this documentation.

## Methods Summarized

| Type                                                     | Name                               | Summary |
| -------------------------------------------------------- | ---------------------------------- | ------- |
| [Object](/reference/servoycore/dev-api/js-lib/object.md) | [getAsJSON()](#getasjson)          |         |
| [String](/reference/servoycore/dev-api/js-lib/string.md) | [getBody()](#getbody)              |         |
| [Number](/reference/servoycore/dev-api/js-lib/number.md) | [getCode()](#getcode)              |         |
| [String](/reference/servoycore/dev-api/js-lib/string.md) | [getHeader(name)](#getheader-name) |         |
| [Array](/reference/servoycore/dev-api/js-lib/array.md)   | [getHeaders()](#getheaders)        |         |

## Methods Detailed

### getAsJSON()

**Returns:** [Object](/reference/servoycore/dev-api/js-lib/object.md) A JSON object representation of the response body.\
If the response body is a JSON array, it is wrapped in an object with the key "array".\
Returns null if the response body is empty or cannot be parsed as JSON.

### getBody()

**Returns:** [String](/reference/servoycore/dev-api/js-lib/string.md) The response body as a string, or null if an error occurs while reading it.

### getCode()

**Returns:** [Number](/reference/servoycore/dev-api/js-lib/number.md) The HTTP status code of the OAuth response.

### getHeader(name)

**Parameters**

* [String](/reference/servoycore/dev-api/js-lib/string.md) **name** ;

**Returns:** [String](/reference/servoycore/dev-api/js-lib/string.md) The value of the specified header, or null if the header is not present.

### getHeaders()

**Returns:** [Array](/reference/servoycore/dev-api/js-lib/array.md) An array of all header names in the OAuth response.

***


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.servoy.com/reference/servoyextensions/server-plugins/oauth/oauthresponsejson.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
