# Code Examples

## Python Code Example

Non-MFA Orgs:

```python
import os
import requests
from dotenv import load_dotenv

# Load environment variables from .env file
load_dotenv()

# Access the environment variables
EMAIL = os.getenv("EMAIL")
PASS = os.getenv("PASS")
SITE = os.getenv("SITE")

creds = dict(
    site_name=SITE,
    username=EMAIL,
    password=PASS
)

session = requests.Session()
response = session.post(
    url=f"https://florecruit.com/app/{creds['site_name']}/admin/auth/",
    data={
        "email": creds['username'],
        "password": creds['password']
    },
    allow_redirects=False
)

api_response = session.get(
    "https://api.florecruit.com/v1/job-applications",
    params={
        "job_application_status_start": "2025-08-01T00:00:00",
        "job_application_status_end": "2025-10-31T23:59:59",
        "job_application_status": "Hired Status"
    },
    headers={
       "Accept": "application/json"
        }
)

print(f"\nAPI status: {api_response.status_code}")
if api_response.status_code == 200:
    print("✓ Authentication successful")
    print(f"Results: {len(api_response.json())} records")
    print(json.dumps(api_response.json(), indent=2))
elif api_response.status_code == 401:
    print("✗ Authentication failed")
else:
    print(f"Unexpected response: {api_response.text}")
```

MFA Orgs

– Add the MFA\_SECRET Key from the authentication setup to the .env file so it can be used to generate passcodes that will be included with the Login request

```python
import os
import requests
import pyotp
from dotenv import load_dotenv

# Load environment variables from .env file
load_dotenv()

# Access the environment variables
EMAIL = os.getenv("EMAIL")
PASS = os.getenv("PASS")
SITE = os.getenv("SITE")
MFA_SECRET_KEY = os.getenv("MFA_SECRET_KEY")

creds = dict(
    site_name=SITE,
    username=EMAIL,
    password=PASS,
    totp=pyotp.TOTP(MFA_SECRET_KEY),
)

session = requests.Session()
response = session.post(
    url=f"https://florecruit.com/app/{creds['site_name']}/admin/auth/",
    data={
        "email": creds['username'],
        "password": creds['password'],
	 "mfaCode": creds['totp'].now()
    },
    allow_redirects=False
)

api_response = session.get(
    "https://api.florecruit.com/v1/job-applications",
    params={
        "job_application_status_start": "2025-08-01T00:00:00",
        "job_application_status_end": "2025-10-31T23:59:59",
        "job_application_status": "Hired Status"
    },
    headers={
       "Accept": "application/json"
        }
)

print(f"\nAPI status: {api_response.status_code}")
if api_response.status_code == 200:
    print("✓ Authentication successful")
    print(f"Results: {len(api_response.json())} records")
    print(json.dumps(api_response.json(), indent=2))
elif api_response.status_code == 401:
    print("✗ Authentication failed")
else:
    print(f"Unexpected response: {api_response.text}")

```

\
Node.js Code Example
--------------------

Non-MFA Org

```javascript
const axios = require("axios");
const dotenv = require("dotenv");

// Load environment variables from .env file
dotenv.config();
// Access the environment variables
const EMAIL = process.env.EMAIL;
const PASS = process.env.PASS;
const SITE = process.env.SITE;

// Credentials
const creds = {
 site_name: SITE,
 username: EMAIL,
 password: PASS,
};

const BASE_URL = `https://florecruit.com/app/${creds.site_name}/admin/auth/`;

const main = async () => {
 try {
   // Create an axios instance to keep cookies/session
   const session = axios.create({
     withCredentials: true,
     maxRedirects: 0,
     validateStatus: status => status >= 200 && status < 400, // accept 302
     timeout: 30000 // 30 second timeout
   });

   // Login request
   await session.post(BASE_URL, {
     email: creds.username,
     password: creds.password,
   }, {
     headers: {
       'Content-Type': 'application/json'
     }
   });

   // API request after login
   const response = await session.get(
     "https://api.florecruit.com/v1/job-applications",
     {
       params: {
         job_application_status_start: "2025-10-01T00:00:00",
         job_application_status_end: "2025-10-31T23:59:59",
         job_application_status: "Hired"
       },
       headers: {
         Accept: "application/json"
       }
     }
   );

   console.log(JSON.stringify(response.data, null, 2));
 } catch (err) {
   console.error(err.response?.data || err.message);
 }
};


main();

```

**MFA Orgs**

– Add the MFA\_SECRET Key from the authentication setup to the .env file so it can be used to generate passcodes that will be included with the Login request

```javascript
const axios = require("axios");
const dotenv = require("dotenv");
const { authenticator } = require("otplib");


// Load environment variables from .env file
dotenv.config();
// Access the environment variables
const EMAIL = process.env.EMAIL;
const PASS = process.env.PASS;
const SITE = process.env.SITE;
const SECRETMFACODE = process.env.SECRETMFACODE;


// Credentials
const creds = {
 site_name: SITE,
 username: EMAIL,
 password: PASS,
 totp: authenticator.generate(SECRETMFACODE)
};


const BASE_URL = `https://florecruit.com/app/${creds.site_name}/admin/auth/`;


const main = async () => {
 try {
   // Create an axios instance to keep cookies/session
   const session = axios.create({
     withCredentials: true,
     maxRedirects: 0, // IMPORTANT: Do not follow redirects
     validateStatus: status => status >= 200 && status < 400, // accept 302
     timeout: 30000 // 30 second timeout
   });


   // Login request
   const loginResponse = await session.post(BASE_URL, {
     email: creds.username,
     password: creds.password,
     mfaCode: creds.totp
   }, {
     headers: {
       'Content-Type': 'application/json'
     }
   });


   const setCookieHeader = loginResponse.headers['set-cookie'];
   let floAuthCookie = null;


   if (setCookieHeader) {
     const floAuthCookieString = setCookieHeader.find(cookie => cookie.startsWith('FLOAUTH='));
     if (floAuthCookieString) {
       floAuthCookie = floAuthCookieString.split(';')[0];
     }
   }


   const headers = {
     Accept: "application/json"
   };


   if (floAuthCookie) {
     headers.Cookie = floAuthCookie;
   }


   // API request after login
   const response = await session.get(
     "https://api.florecruit.com/v1/job-applications",
     {
       params: {
         job_application_status_start: "2025-10-01T00:00:00",
         job_application_status_end: "2025-10-31T23:59:59",
         job_application_status: "Hired"
       },
       headers: headers
     }
   );


   console.log(JSON.stringify(response.data, null, 2));
 } catch (err) {
   console.error(err.response?.data || err.message);
 }
};


main();
```

\ <br>


---

# 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://docs.joinflo.com/flo-apis/hris-api/code-examples.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.
