# Authentication

The APIs described in this documentation utilize OAuth 2.0 authentication. This means that all requests must include an access token, which is obtained through an authentication request using your Client ID and Client Secret.

## Retrieving Access token

To begin the backend integration process, you must first obtain an **access token**. This requires your **Client ID** and **Client Secret**, which are provided via email when you register for the Merchant Portal. If you have not received these credentials, please contact Getnet support for assistance.  

Note that each access token is valid for **60 minutes**. It is recommended to implement a mechanism that automatically retrieves a new token before the current one expires to ensure uninterrupted access to the APIs.

To consume the APIs use the following DNS values for the `host_getnet_api` key:

* [**https://api.pre.globalgetnet.com**](https://api.pre.globalgetnet.com) (homologation environment)
* [**https://api.globalgetnet.com**](https://api.globalgetnet.com) (production environment)

**Request example with Curl**

```json
curl --location '{{host_getnet_api}}/authentication/oauth2/access_token' 
--header 'Content-Type: application/x-www-form-urlencoded' 
--header 'Accept: application/json' 
--data-urlencode 'grant_type=client_credentials' 
--data-urlencode 'client_id={{PUT_YOUR_CLIENT_ID_HERE}}' 
--data-urlencode 'client_secret={{PUT_YOUR_CLIENT_SECRET_HERE}}'
```

**Response**

```json
{
    "access_token": "eyJ0eXAiOiJKV1QiLCJraWQiOiI1amhLMy9xK0ZpK0tTRkIrRUwwN3VhMFYwdGM9Ii...",
    "scope": "name-scope:r",
    "token_type": "Bearer",
    "expires_in": 3599
}
```

**Request with Node.js with Axios example**

```json
const axios = require('axios');
const qs = require('qs');
let data = qs.stringify({
  'grant_type': 'client_credentials',
  'client_id': '{{client_id}}',
  'client_secret': '{{client_secret}}' 
});

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: '{{host_getnet_api}}/authentication/oauth2/access_token',
  headers: { 
    'Content-Type': 'application/x-www-form-urlencoded', 
    'Accept': 'application/json'
  },
  data : data
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});
```

**Request with PHP example**

```json
<?php
$client = new Client();
$headers = [
  'Content-Type' => 'application/x-www-form-urlencoded',
  'Accept' => 'application/json'
];
$options = [
'form_params' => [
  'grant_type' => 'client_credentials',
  'client_id' => '{{client_id}}',
  'client_secret' => '{{client_secret}}'
]];
$request = new Request('POST', '{{host_getnet_api}}/authentication/oauth2/access_token', $headers);
$res = $client->sendAsync($request, $options)->wait();
echo $res->getBody();
```

### Next Steps

Now that you have completed the authentication process, proceed to the next steps:

* Create your first payment transaction: [Quickstart: Create Payment](/en/web-checkout/first-steps-wbc/quick-create-payment-wbc)
* See all the payment options available: [Supported Payment Methods](https://docs.globalgetnet.com/en/products/online-payments/regional-api)