Skip to content

Status

Check the status of the API.

status(url=os.getenv('RECEPTIVITI_URL', ''), key=os.getenv('RECEPTIVITI_KEY', ''), secret=os.getenv('RECEPTIVITI_SECRET', ''), dotenv=False, verbose=True)

Check the API's status.

Ping the Receptiviti API to see if it's available, and if your credentials are valid.

PARAMETER DESCRIPTION
url

The URL of the API.

TYPE: str DEFAULT: getenv('RECEPTIVITI_URL', '')

key

Your API key.

TYPE: str DEFAULT: getenv('RECEPTIVITI_KEY', '')

secret

Your API secret.

TYPE: str DEFAULT: getenv('RECEPTIVITI_SECRET', '')

dotenv

Path to a .env file to read environment variables from, or True to look for a file in the current directory.

TYPE: bool | str DEFAULT: False

verbose

If False, will not print status messages.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
Union[Response, None]

Response from the API server.

Examples:

receptiviti.status()
Source code in src\receptiviti\status.py
def status(
    url: str = os.getenv("RECEPTIVITI_URL", ""),
    key: str = os.getenv("RECEPTIVITI_KEY", ""),
    secret: str = os.getenv("RECEPTIVITI_SECRET", ""),
    dotenv: Union[bool, str] = False,
    verbose=True,
) -> Union[requests.Response, None]:
    """
    Check the API's status.

    Ping the Receptiviti API to see if it's available, and if your credentials are valid.

    Args:
      url (str): The URL of the API.
      key (str): Your API key.
      secret (str): Your API secret.
      dotenv (bool | str): Path to a .env file to read environment variables from, or `True`
        to look for a file in the current directory.
      verbose (bool): If `False`, will not print status messages.

    Returns:
      Response from the API server.

    Examples:
        ```python
        receptiviti.status()
        ```
    """
    _, url, key, secret = _resolve_request_def(url, key, secret, dotenv)
    try:
        res = requests.get(url.lower() + "/v1/ping", auth=(key, secret), timeout=9999)
    except requests.exceptions.RequestException:
        if verbose:
            print("Status: ERROR\nMessage: URL is unreachable")
        return None
    content = res.json() if res.text[:1] == "{" else {"message": res.text}
    if verbose:
        print("Status: " + ("OK" if res.status_code == 200 else "ERROR"))
        print(
            "Message: "
            + (
                str(res.status_code)
                + (" (" + str(content["code"]) + ")" if "code" in content else "")
                + ": "
                + content["pong" if "pong" in content else "message"]
            )
        )
    return res