# How to call API?

Base URL: Calls for ReferralHero API are relative to the URL

```
https://app.referralhero.com/api/sdk/v1/
```

#### Request Headers <a href="#request-headers" id="request-headers"></a>

1. Authorization - Your access token
2. Accept - `application/vnd.referralhero.v1`
3. Content-Type - `application/json`

To summarize, your request headers should look like this

```jsx
{ 
  'Content-Type': 'application/json',
  'Accept': 'application/vnd.referralhero.v1',
  'Authorization': 'xxxxxxxxxx'
}
```

**Step 1:** Prepare Your Environment

1. Open your React Native project.
2. Install a library for making HTTP requests, such as axios or use the built-in fetch API.

**Step 2:** Make Your First API Call

1. Set up your API call:

```jsx
const apiUrl = 'https://app.referralhero.com/api/sdk/v1/';
const apiToken = 'Your-api-token';

axios.get(`${apiUrl}endpoint`, {
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/vnd.referralhero.v1',
    'Authorization': apiToken
  }
})
.then(response => {
  console.log(response.data);
})
.catch(error => {
  console.error('Error making API call', error);
});
```

**Step 3:**

1. On the ReferralHero overview, click to edit your desired Campaign.<br>

   <figure><img src="/files/ZkubYUzopXTqNXkcov9i" alt=""><figcaption></figcaption></figure>
2. Then the Installation tab, then Mobile App Installation.<br>

   <figure><img src="https://support.referralhero.com/~gitbook/image?url=https%3A%2F%2F363135598-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LsuqexOLPOWiUrWg_Ko%252Fuploads%252FBUI2ezbackSvMEslulbH%252Fimage.png%3Falt%3Dmedia%26token%3Da1fd127b-274c-45e9-81fc-5903f13eccdc&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=743f950c&#x26;sv=2" alt=""><figcaption></figcaption></figure>
3. Get your `UUID`: The 12-letter ID that starts with ‘MF’ in *Edit Campaign > launch > Mobile app installation*, e.g. MF15298bba6d.<br>

   <figure><img src="https://support.referralhero.com/~gitbook/image?url=https%3A%2F%2F363135598-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LsuqexOLPOWiUrWg_Ko%252Fuploads%252FOR6ko6dqhgLkO5sK1OKe%252Fimage.png%3Falt%3Dmedia%26token%3D220c625b-571d-46a2-bb73-2060552692cc&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=6a6c0f7c&#x26;sv=2" alt=""><figcaption></figcaption></figure>
4. Add the Campaign Token obtained from the campaign, and UUID from the installation Tab.

**Step 4:**

In the Goal section of your Campaign settings, ensure you have added the Google Play and Apple App Store links and a default referral link for desktop web users.

<figure><img src="https://support.referralhero.com/~gitbook/image?url=https%3A%2F%2F363135598-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LsuqexOLPOWiUrWg_Ko%252Fuploads%252FSLzES0rNLCBAIR49Kw7t%252Fimage.png%3Falt%3Dmedia%26token%3Dbdbc76d1-db16-472a-b5c3-5212283258d4&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=1b99cab4&#x26;sv=2" alt=""><figcaption></figcaption></figure>

Well done! You should now be able to build and run your campaign. Before using the more advanced features of the API, you should learn about a couple of important concepts.

#### Helper Functions <a href="#helper-functions" id="helper-functions"></a>

**Get Device Type**

You can use the `react-native-device-info` library to get the device type.

```jsx
import DeviceInfo from 'react-native-device-info';

function getDeviceType() { 
  let deviceType = "Desktop";
  if (Platform.OS === 'ios') 
    { if (DeviceInfo.getModel().toLowerCase().includes("ipad")) { 
      deviceType = "iPad"; 
    } else if (DeviceInfo.getModel().toLowerCase().includes("ipod")) {
       deviceType = "iPod"; 
    } else { deviceType = "iPhone"; } 
  } else if (Platform.OS === 'android') { 
    deviceType = "Android"; 
  } else if (Platform.OS === 'windows') { 
    deviceType = "Windows Phone"; 
  } else if (Platform.OS === 'blackberry') {
     deviceType = "BlackBerry"; 
  } else { 
    deviceType = "Unknown Device";
  } 
  return deviceType; 
}
```

**Get Operating System**

You can use the `Platform` module from React Native to get the operating system type.

```jsx
import { Platform } from 'react-native';

function getOperatingSystem() {
  return Platform.OS; // Returns 'ios' or 'android'
}
```

### Adding the Subscriber Data <a href="#adding-the-subscriber-data" id="adding-the-subscriber-data"></a>

With this information, you should be able to add the subscriber data using the `addSubscriber` method to automatically identify or track a referral:

```jsx
function formSubmit() {
  axios.post(`https://app.referralhero.com/api/sdk/v1/lists/MFxxxxxxxxx/subscribers`, referralParams, {
    headers: {
      'Content-Type': 'application/json',
      'Accept': 'application/vnd.referralhero.v1',
      'Authorization': apiToken
    }
  })
  .then(response => {
    console.log('Subscriber added successfully:', response.data);
  })
  .catch(error => {
    console.error('Error adding subscriber', error);
  });
}
```


---

# Agent Instructions: 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:

```
GET https://berylsystems.gitbook.io/referral-hero-documentation/integrations/mobile-sdks/react-native/how-to-call-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
