cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
ELHADIALLO
Level 2

Subject: Authentication Issue with API - 400 Error "Cookie Missing"

Hello everyone,

I'm encountering a problem while attempting to authenticate with a specific API. After following the official documentation to establish a connection and sending an authentication request using Python's `requests` library, I consistently receive a 400 error with the following message: `{"error": {"code": "400.002.002", "description": "Cookie Missing"}}`.

Here is a simplified snippet of my code:

```python

import requests
import json

# Charger les paramètres à partir du fichier JSON
s = json.load(open("settings.json", "r", encoding="utf-8"))

# Extraire le nom d'utilisateur et le mot de passe
username = s['REVENERA']['USER']
password = s['REVENERA']['PASSWORD']


# Extract header values
content_type = s['headers']['Content-Type']
rui_client = s['headers']['RUI-Client']
rui_client_version = s['headers']['RUI-Client-Version']
origin = s['headers']['Origin']



user = {
    "user": username,
    "password": password
}


# Setup the headers dictionary
headers = {
   
    "Content-Type": content_type,
    "RUI-Client": rui_client,
    "RUI-Client-Version": rui_client_version,
    "Origin": origin
   
}

# URL d'authentification de l'API

# Création d'une session pour maintenir les cookies
with requests.Session() as session:
   
        # Faire la requête d'authentification avec les en-têtes et le corps corrects
        response = session.post(URL, json=user, headers=headers)
        print(response.cookies)

        # Vérifiez la réussite de l'authentification
        if response.ok:
            print("Authentification réussie")
            # L'ID de session et éventuellement d'autres données peuvent être extraits ici
            session_id = response.json().get("sessionId")
            print("ID de session :", session_id)
        else:
            print(f"Échec de l'authentification: {response.status_code} - {response.text}")

# Exécuter la fonction d'authentification (Cette ligne sera décommentée dans le script final)
# authenticate_and_execute()
   

```

I ensure the session is initiated, and all headers required by the documentation are included. However, the error seems to indicate a missing cookie in my request, although the documentation does not explicitly mention the need for such a cookie for authentication.

Has anyone encountered this type of error before? Is there an additional step or a specific header I might have missed to transmit or receive the required cookie?

Any help or suggestion would be greatly appreciated.

Thank you in advance for your support.

(3) Replies
BhargavaNagaraj
Revenera
Revenera

Hi @ELHADIALLO ,

There is an additional step required, and we will update the documentation accordingly. Since most of our team is on holiday due to the region's public holiday schedule, we will be able to assist you by end of this week or early next week. In the meantime, could you please create a support ticket? https://community.flexera.com/t5/Usage-Intelligence-Knowledge/How-to-Create-a-Support-Ticket-for-Usage-Intelligence/ta-p/142952

Thank you,

Bhargava

jenseggerath
Level 2

Hello @BhargavaNagaraj 

I have the same question - can you please update the documentation or let us know here what's missing?

Regards

Jens

AkSharma
Revenera
Revenera

We have updated the v3 API documentation with additional instructions required for authentication. 

Thanks

0 Kudos