A quick Python snippet to integrate into the FraudGuard.io API

This Python code performs the following steps:

  1. Sets the FraudGuard.io API credentials (username and password).
  2. Defines the IP address to query.
  3. Constructs the API endpoint URL.
  4. Encodes the credentials for basic authentication using Base64 encoding.
  5. Sets the Authorization header with the encoded credentials.
  6. Sends a GET request to the API endpoint using the requests library.
  7. Checks if the request was successful (status code 200) and prints the response body.
  8. Prints an error message if the request was unsuccessful.
import requests
import base64

# FraudGuard.io API credentials
username = 'username'
password = 'password'

# IP address to query
ip_address = '8.8.8.8'

# API endpoint
api_url = f'https://api.fraudguard.io/ip/{ip_address}'

# Encode credentials for basic authentication
auth_string = f'{username}:{password}'
encoded_auth_string = base64.b64encode(auth_string.encode()).decode()

# Set headers for the request
headers = {
    'Authorization': f'Basic {encoded_auth_string}'
}

# Send GET request to the API
response = requests.get(api_url, headers=headers)

# Check if the request was successful
if response.status_code == 200:
    print(response.text)
else:
    print(f"Error: {response.status_code} - {response.reason}")

Make sure to replace ‘username’ and ‘password’ with your actual API credentials.