# How to call API?

## How to call API?

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

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

**Request Headers**

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.\\

   <figure><img src="https://1427773792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhQxsg0xCpG1doJ626L8X%2Fuploads%2F7DCR5h6l0nWuH2bjY3Dn%2FScreenshot%202025-02-27%20at%202.16.57%E2%80%AFAM.png?alt=media&#x26;token=e34ee7a9-dff1-43f7-8ca7-04818a2d6ea5" alt=""><figcaption></figcaption></figure>
2. Then the Installation tab, then Mobile App Installation.\\

   <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.\\

   <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**

**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);
  });
}
```
