Skip to main content

Erreur : invoices 401 HTTP error: Invalid token provided - Authorization required

Hello, I have this error :

Erreur : invoices 401 HTTP error: Invalid token provided - Authorization required 


How can i fix it please ?

Status: Completed5 comments

Log in to comment and vote

Comments5

  • IanarĂ© SĂ©vi

    Team‱

    Jul 22, 2025

    Hi,

    Looks like you’re trying to access a legacy (v1) model with a new (v2) API key.

    Can you tell me where you got the API key from?

    And where you got the sample code from?

    Thanks much!

  • Les Petits Porteurs

    ‱

    Jul 22, 2025

    here is the code :

    import warnings

    import os

    # Supprimer les messages de debug NumExpr

    os.environ['NUMEXPR_MAX_THREADS'] = '8'

    warnings.filterwarnings('ignore')

    from mindee import Client, product

    import pandas as pd

    from pathlib import Path

    def extract_invoice_to_excel(file_path: str, api_key: str, output_file: str = None):

    try:

    # Initialisation du client Mindee

    mindee_client = Client(api_key=api_key)

    # Chargement et analyse du document

    input_doc = mindee_client.source_from_path(file_path)

    result = mindee_client.parse(product.InvoiceV4, input_doc)

    invoice = result.document

    # Extraction des données des articles

    line_items_data = []

    for item in invoice.inference.prediction.line_items:

    line_items_data.append({

    "Code article": item.product_code,

    "Designation article": item.description,

    "Unite": item.unit_measure,

    "Prix unitaire": item.unit_price,

    "Quantité": item.quantity,

    "Prix total": item.total_amount

    })

    # Vérification qu'il y a des articles

    if not line_items_data:

    print("Aucun article trouvé dans la facture")

    return None

    # Génération du nom de fichier si non spécifié

    if output_file is None:

    file_name = Path(file_path).stem

    output_file = f"FACTURE-{file_name}.xlsx"

    # Export Excel

    df = pd.DataFrame(line_items_data)

    df.to_excel(output_file, index=False)

    print(f"Export terminé : {output_file}")

    return output_file

    except Exception as e:

    print(f"Erreur : {e}")

    return None

    # Lignes à modifier si changement de clé et de facture(chemin)

    API_KEY = "*******************jgws"

    FILE_PATH = r"C:\Users\marga\Les Petits Porteurs Dropbox\LPP Suivi\Factures Ouilink\tests Mindee fournisseurs récurrents\Passion froid\1PSUFACTURW0001385525202403298597825950.Zeendoc.pdf"

    extract_invoice_to_excel(FILE_PATH, API_KEY)

    • IanarĂ© SĂ©vi

      Team‱

      Jul 22, 2025

      Yes this is code for the legacy version. It won’t work with the new version.

      Integration steps are described here:

      https://docs.mindee.com/getting-started/integrating-mindee

      Just out of curiosity, where did you get that sample code from?

      I’m trying to figure that out so we can update any links or documentation pages.

      Thank you!

      • Les Petits Porteurs

        ‱

        Jul 22, 2025

        even if with the code of the new version, we have an error “interference response has no attribute document”, how can we adapt the code to the new version? thanks

        • IanarĂ© SĂ©vi

          Team‱

          Jul 22, 2025

          In the new version, there are no predefined fields and the output structure is different.

          You’ll need to grab the fields of interest from the response.inference.result.fields Python dict.

          
 where the field names are defined in your model => Data Schema page on the platform.

          more details here:

          https://docs.mindee.com/getting-started/integrating-mindee#tab-python-1