Creating an event via HTTP API

Hi!

I am trying to use the HTTP API to both pull and push data about events in a given category. Using a token, I am able to fetch existing events and to modify them (update the title, the speakers, etc.).

To update an existing event, I followed the idea described here: using my browser’s tools to get the form data sent, and then reproducing the same POST request.

What I want to do now is to create a new event (still in the same category). To achieve that, I opened Firefox’s tools and created a new event on Indico to see the form that is sent in such a case. However, trying to reproduce the request led to nothing.

I’m using Python, with the package requests to send a POST request to /event/create/lecture, with an Authorization header containing my token. I send all the fields I see in Firefox, but all I get in response is an HTML which seems to be Indico’s homepage.

At this point, I just have no idea about what is happening, as I follow the exact same process as for the other forms. Is there something I can do to at least understand the issue?

Thanks in advance!

Please share your code (with the token censored). This will be much more useful than a textual description of what you’re sending.

Anyway, if you look through the HTML you’ll actually find the validation errors somewhere. If you want to be lazy, save the HTML response to a file and open it in a browser.

Below is the code I’m using to test the request.

import json
import requests

url = 'https://indico.math.cnrs.fr/event/create/lecture'

headers = {
	'Authorization': 'Bearer MY_TOKEN'
}

cat_data = {
	'id': 535,
	'title': 'Séminaire MAC'
}

dt_data = [
	{
		'date': '2024-07-14',
		'time': '09:00',
		'duration': 60
	}
]

location_data = {
	'address': '',
	'inheriting': False
}

data = {
	'event-creation-create_booking': 'false',
	'event-creation-category': json.dumps(cat_data, ensure_ascii = False),
	'event-creation-title': 'Test',
	'event-creation-occurrences': json.dumps(dt_data, ensure_ascii = False),
	'event-creation-timezone': 'Europe/Paris',
	'event-creation-location_data': json.dumps(location_data, ensure_ascii = False),
	'event-creation-person_link_data': '[]',
	'event-creation-protection_mode': 'inheriting',
	'event-creation-description': '',
	'event-creation-theme': ''
}

res = requests.post(url, headers = headers, data = data)

I don’t see anything special in the output, it seems that it’s nothing but the homepage.

maybe you can share the HTML response? :wink:

Oh, I was sure I did it… Below is the full response.

I replaced two details by comments to be under the characters number limit (they are related to the language).

<!DOCTYPE html>

<html prefix="og: http://ogp.me/ns#"
      data-static-site="false">
<head>
    <title>Home · Service de gestion de conférences de Mathrice (Indico)</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="csrf-token" id="csrf-token" content="a96149e2-fbb4-4c29-9bea-24cb3841f079">
    <link rel="shortcut icon" type="image/x-icon" href="/images/indico.ico">

    <meta property="og:site_name" content="Service de gestion de conférences de Mathrice (Indico)">
    <meta property="og:image" content="https://indico.math.cnrs.fr/images/indico_square.png">
    

    
    
    

    <script type="text/javascript" src="/assets/i18n/fr_FR.js"></script>
    <script type="text/javascript" src="/assets/i18n/fr_FR-react.js"></script>
    <script type="text/javascript" src="/assets/js-vars/global.js"></script>

    <script src="/dist/js/exports.8d176b89.bundle.js"></script>
    <script src="/dist/js/common-runtime.9c14a10e.bundle.js"></script>
    <link rel="stylesheet" href="/dist/css/common.c31173ad.css" />
    <script src="/dist/js/common.3c029b59.bundle.js"></script>
    <link rel="stylesheet" href="/dist/css/react.714d0dbe.css" />
    <script src="/dist/js/react.92af1a49.bundle.js"></script>
    <script src="/dist/js/semantic-ui.766f6b91.bundle.js"></script>
    <link rel="stylesheet" href="/dist/css/semantic-ui.03304b73.css" />
    <link rel="stylesheet" href="/dist/css/jquery.3ea47bb4.css" />
    <script src="/dist/js/jquery.dcb15e3f.bundle.js"></script>
    <link rel="stylesheet" href="/dist/css/main.1bce9d1b.css" />
    <script src="/dist/js/main.7bb061f8.bundle.js"></script>
    <script src="/dist/js/module_core.bc4af069.bundle.js"></script>
    <script src="/dist/js/module_events.creation.d4bebc8c.bundle.js"></script>
    <script src="/dist/js/module_attachments.02979617.bundle.js"></script>
    <script src="/dist/js/outdatedbrowser.10708c2f.bundle.js"></script>
    <link rel="stylesheet" href="/dist/css/outdatedbrowser.1f43ad02.css" />
    <script src="/dist/js/module_categories.4be12a4a.bundle.js"></script>
    <link rel="stylesheet" href="/dist/css/module_categories.1535631c.css" />
    
    

    

    
        <script>
            moment.locale(["fr", 'en']);
            IndicoGlobalVars.isUserAuthenticated = true;
        </script>
    

    <script type="text/javascript" src="/assets/js-vars/user.js"></script>

    <link rel="alternate" type="application/atom+xml" title="Événements de &#34;Home&#34;" href="/category/0/events.atom">

    

    
</head>
<body data-user-id="3509"
      data-debug="false">
    
        <div class="header">




    
    


    
    


<div class="page-header clearfix">
    <div class="flexrow f-j-space-between f-a-start">
        <a style="min-height: 60px;" href="/">
                <img class="header-logo" src="/images/logo_indico_bw.svg">
            </a>
        

        <div class="flexcol">
            
    

    <div id="session-bar" class="session-bar flexrow f-j-end ">
        <div class="toolbar">
            <div class="group">
                
                    
    
        
    

    <div id="protection-details" style="display: none;" class="protectionWidget">
        <div class="protectionWidgetSection">
            
                L'information sur cette page est visible par tout le monde
            
        </div>
        
        
    </div>

    <button id="protection-details-link"
       class="arrow i-button protection-public icon-earth">
        
            Publique
        
    </button>

                    <script>
                        $.ui.sticky({
                            sticky: nothing,
                            normal: nothing
                        });
                    </script>
                

                
    
        <div id="tz-selector-widget" style="display: none;" class="tz-selector-widget settingsWidget">
            <div style="line-height: 17px;">
                <span class="settingsWidgetHeader">Choisissez le fuseau horaire</span><br>
            </div>
            <div class="settingsSeparator"></div>
            <div class="tz-mode-container">
                <div>
                    <input type="radio" name="tz_mode" id="tz-mode-local" value="local"
                           checked>
                    <label for="tz-mode-local">Utiliser le fuseau horaire de l'événement/catégorie</label>
                </div>
                
                    <div>
                        <input type="radio" name="tz_mode" id="tz-mode-user" value="user"
                               >
                        <label for="tz-mode-user">
                            Votre fuseau horaire par défaut
                            <em>(Europe/Paris)</em>
                        </label>
                    </div>
                
                <div>
                    <input type="radio" name="tz_mode" id="tz-mode-custom" value="custom"
                           >
                    <label for="tz-mode-custom">Veuillez spécifier un fuseau horaire</label>
                </div>
            </div>
            <select name="tz" class="tz-select" size="12" disabled>
                <!-- a lot of options -->
            </select>
            
                <div class="tz-update-user-container">
                    <input type="checkbox" name="update_user" id="tz-update-user" value="1">
                    <label for="tz-update-user">Se souvenir de ces paramètres</label>
                </div>
            
            <div class="tz-save-container">
                <button class="i-button highlight" type="button"
                        data-href="/change-timezone"
                        data-method="POST"
                        data-params-selector="#tz-selector-widget input[name=tz_mode]:checked,
                                              #tz-selector-widget select[name=tz]:not(:disabled),
                                              #tz-update-user:checked"
                        data-reload-after
                        data-ajax>
                    Sauver
                </button>
            </div>
        </div>

        <button id="tz-selector-link" class="i-button icon-time arrow">Europe/Paris</button>
    


                
                    
    <div id="user-settings-widget" style="display: none;" class="settingsWidget">
        <div style="line-height: 17px;">
            <span class="settingsWidgetHeader">Jérémy Heleine</span><br>
            <span style="font-size: 12px;">[here appears my email address]</span>
        </div>
        <div class="settingsSeparator"></div>
        <div class="settingsWidgetSection">
            <a href="/user/dashboard/">Mon profil</a>
        </div>
        <div class="settingsWidgetSection">
            <a href="/user/preferences/">Mes préférences</a>
        </div>
        <div class="settingsWidgetSection">
            
    
    
    
    
    
        <a id="language-selector-link"
           href=""
           class="arrow js-dropdown" data-toggle="dropdown">Ma langue (Français)
        </a>
    
    
        <ul class="i-dropdown">
            <!-- some options to change the language -->
        </ul>
    

        </div>
        
        
        <div style="border-bottom: 1px solid #ddd; margin-bottom: 5px; margin-top: 10px"></div>
        <div class="settingsWidgetSection">
            <a href="/logout/?next=/">Déconnexion</a>
        </div>
    </div>

    <button id="user-settings-link" class="i-button icon icon-user arrow">
        J. Heleine
    </button>

                
            </div>
        </div>
    </div>

            
        </div>
    </div>

    <div class="global-menu toolbar">
        
            
                
                    <a href="/">Accueil</a>
                
            
                
                    <a class="arrow js-dropdown" href="#" data-toggle="dropdown">Créer un événement</a>
                    <ul class="i-dropdown">
                        
                
                    
                    <li>
                        
                            
                            <a href="/#create-event:lecture"
       
           data-href="/event/create/lecture?category_id=0"
           data-title="Créer une nouvelle présentation"
           data-ajax-dialog
           data-ignore-href
       
       id="create-lecture">
        Créer une présentation
    </a>
                        
                    </li>
                
            
                
                    
                    <li>
                        
                            
                            <a href="/#create-event:meeting"
       
           data-href="/event/create/meeting?category_id=0"
           data-title="Créer une nouvelle réunion"
           data-ajax-dialog
           data-ignore-href
       
       id="create-meeting">
        Créer une réunion
    </a>
                        
                    </li>
                
            
                
                    
                    <li>
                        
                            
                            <a href="/#create-event:conference"
       
           data-href="/event/create/conference?category_id=0"
           data-title="Créer une nouvelle conférence"
           data-ajax-dialog
           data-ignore-href
       
       id="create-conference">
        Créer une conférence
    </a>
                        
                    </li>
                
            
                    </ul>
                
            
                
                    <a href="/rooms/">Réservation de salle</a>
                
            
                
            
                
                    <a href="/user/dashboard/">Mon profil</a>
                
            
                
            
        
    </div>
</div>

<script type="text/html" id="event-type-tooltip-lecture">Une <strong>présentation</strong> est un événement simple pour annoncer un exposé.<br><strong>Fonctionnalités</strong>: création de poster, gestion des participants...</script>
<script type="text/html" id="event-type-tooltip-meeting">Une <strong>réunion</strong> est un événement qui définit un ordre du jour avec des présentations multiples.<br><strong>Fonctionnalités</strong>: ordre du jour, comptes-rendus, création de poster, gestion des participants...</script>
<script type="text/html" id="event-type-tooltip-conference">Une <strong>conférence</strong> est un événement complexe avec des fonctionnalités pour gérer l'intégralité du cycle de vie d'une conférence.<br><strong>Fonctionnalités</strong>: appel à contribution, inscription, paiement électronique, ordre du jour, création des badges, relecture des articles...</script>

<script>
    (function() {
        'use strict';

        ['lecture', 'meeting', 'conference'].forEach(function(evt_type) {
            $('#create-' + evt_type).qtip({
                content: $('#event-type-tooltip-' + evt_type).html(),
                position: {
                    my: 'left center',
                    at: 'right center'
                }
            });
        });
    })();
</script></div>
<div class="main"><div>

<div class="category-container">
    <div class="category-header flexrow">
        <h1 class="category-title">
            
                
                    
                        Catégories principales
                    
                
            
        </h1>
        
            <div id="category-toolbar" class="toolbar fixed-height">
                <div class="group">
                    <div id="search-box" class="search-box"
                         data-category="{&#34;id&#34;:0,&#34;isRoot&#34;:true,&#34;title&#34;:&#34;Home&#34;}"
                         
                    ></div>
                </div>
                <div class="group">
                    
                        
    <a href="" class="highlight i-button arrow js-dropdown"
       
       data-toggle="dropdown">Créer un événement</a>
    <ul class="i-dropdown">
        <li><a href="/#create-event:lecture"
       
           data-href="/event/create/lecture?category_id=0"
           data-title="Créer une nouvelle présentation"
           data-ajax-dialog
           data-ignore-href
       
       >
        Présentation
    </a></li>
        <li><a href="/#create-event:meeting"
       
           data-href="/event/create/meeting?category_id=0"
           data-title="Créer une nouvelle réunion"
           data-ajax-dialog
           data-ignore-href
       
       >
        Réunion
    </a></li>
        <li><a href="/#create-event:conference"
       
           data-href="/event/create/conference?category_id=0"
           data-title="Créer une nouvelle conférence"
           data-ajax-dialog
           data-ignore-href
       
       >
        Conférence
    </a></li>
    </ul>

                    
                </div>
                <div class="group">
                    
                        <button id="navigate-button" class="i-button icon-compass2"
                                title="Naviguer les catégories">
                            Naviguer
                        </button>
                    
                </div>
                <div class="group">
                    
                        
                    
                    
                        <div id="category-calendar-link" data-category-id="0"></div>
                    
                    
                        <button class="i-button icon-eye arrow js-dropdown"
                                title="Voir"
                                data-toggle="dropdown"></button>
                        <ul class="i-dropdown">
                            
                            <li>
                                <a href="/category/0/upcoming">Événement à venir</a>
                            </li>
                            <li>
                                <a href="/category/0/overview?period=day">Événements du jour</a>
                            </li>
                            <li>
                                <a href="/category/0/overview?period=week">Événements de la semaine</a>
                            </li>
                            <li>
                                <a href="/category/0/calendar">Calendrier</a>
                            </li>
                            <li>
                                <a href="/category/0/statistics">Statistiques de la catégorie</a>
                            </li>
                        </ul>
                    
                    
                        
                    
                </div>
                
                    
                
            </div>
        
    </div>

    
        <div class="category-sidebar">
        <div class="title">
            <h2 class="icon-bullhorn">Nouvelles</h2>
            <a href="/news/" class="more-icon">voir plus...</a>
        </div>
        <ul class="main-page-list">
            
                <li>
                    <a class="title" href="/news/9-authentification">
                        Authentification
                    </a>
                    <span class="timing">
                        Posté le 31 août 2022
                    </span>
                </li>
            
                <li>
                    <a class="title" href="/news/8-migration-et-mise-a-jour">
                        Migration et mise à jour
                    </a>
                    <span class="timing">
                        Posté le 30 août 2022
                    </span>
                </li>
            
                <li>
                    <a class="title" href="/news/7-mise-a-jour-majeur">
                        Mise à jour majeur
                    </a>
                    <span class="timing">
                        Posté le 11 mars 2021
                    </span>
                </li>
            
        </ul>
    
        <div class="title">
            <h2 class="icon-alarm">Événements à venir</h2>
        </div>
        <ul class="main-page-list">
            
                <li>
                    <a href="/event/8995/" class="title" title="Quantum many-body systems out-of-equilibrium, Paris" >
                        Quantum many-body systems out-of-equilibrium, Paris
                    </a>
                    <span class="timing">
                        
                            en cours jusqu'à  22 mars 2024
                        
                    </span>
                </li>
            
                <li>
                    <a href="/event/11273/" class="title" title="Workshop on Multisymplectic Structures in Geometry and Physics" >
                        Workshop on Multisymplectic Structures in Geometry and Physics
                    </a>
                    <span class="timing">
                        
                            Commence à Demain
                        
                    </span>
                </li>
            
                <li>
                    <a href="/event/10364/" class="title" title="Analytic Stacks" >
                        Analytic Stacks
                    </a>
                    <span class="timing">
                        
                            Commence à Demain
                        
                    </span>
                </li>
            
                <li>
                    <a href="/event/10975/" class="title" title="Pierre Lavigne (Université Côte d’Azur)" >
                        Pierre Lavigne (Université Côte d’Azur)
                    </a>
                    <span class="timing">
                        
                            Commence à Demain
                        
                    </span>
                </li>
            
                <li>
                    <a href="/event/11298/" class="title" title="L’obstruction de Brauer–Manin et la méthode de la descente" >
                        L’obstruction de Brauer–Manin et la méthode de la descente
                    </a>
                    <span class="timing">
                        
                            Commence à Demain
                        
                    </span>
                </li>
            
                <li>
                    <a href="/event/11299/" class="title" title="Introduction to real del Pezzo surfaces" >
                        Introduction to real del Pezzo surfaces
                    </a>
                    <span class="timing">
                        
                            Commence à Demain
                        
                    </span>
                </li>
            
                <li>
                    <a href="/event/10798/" class="title" title="Abel à Paris" >
                        Abel à Paris
                    </a>
                    <span class="timing">
                        
                            Commence à jeudi
                        
                    </span>
                </li>
            
                <li>
                    <a href="/event/10599/" class="title" title="Nonlinear Quantum Graphs" >
                        Nonlinear Quantum Graphs
                    </a>
                    <span class="timing">
                        
                            Commence à jeudi
                        
                    </span>
                </li>
            
                <li>
                    <a href="/event/10905/" class="title" title="Annalisa Grossi, &#34;Birational equivalence and deformation equivalence for Hyperkähler manifolds&#34;" >
                        Annalisa Grossi, &#34;Birational equivalence and deformation equivalence for Hyperkähler manifolds&#34;
                    </a>
                    <span class="timing">
                        
                            Commence à jeudi
                        
                    </span>
                </li>
            
                <li>
                    <a href="/event/11322/" class="title" title="Extracting geometric information from Kuznetsov components and application" >
                        Extracting geometric information from Kuznetsov components and application
                    </a>
                    <span class="timing">
                        
                            Commence à jeudi
                        
                    </span>
                </li>
            
                <li>
                    <a href="/event/11281/" class="title" title="Nonlinear Quantum Graphs" >
                        Nonlinear Quantum Graphs
                    </a>
                    <span class="timing">
                        
                            Commence à jeudi
                        
                    </span>
                </li>
            
                <li>
                    <a href="/event/11359/" class="title" title="Aspects dynamiques des groupes infinis et leurs actions non-libres" >
                        Aspects dynamiques des groupes infinis et leurs actions non-libres
                    </a>
                    <span class="timing">
                        
                            Commence à jeudi
                        
                    </span>
                </li>
            
                <li>
                    <a href="/event/10660/" class="title" title="Pascal et l&#39;invention du raisonnement par récurrence" >
                        Pascal et l&#39;invention du raisonnement par récurrence
                    </a>
                    <span class="timing">
                        
                            Commence à jeudi
                        
                    </span>
                </li>
            
                <li>
                    <a href="/event/10511/" class="title" title="Rigidity property of some 2d point processes" >
                        Rigidity property of some 2d point processes
                    </a>
                    <span class="timing">
                        
                            Commence à jeudi
                        
                    </span>
                </li>
            
                <li>
                    <a href="/event/10765/" class="title" title="Réduction des quartiques planes et octades de Cayley" >
                        Réduction des quartiques planes et octades de Cayley
                    </a>
                    <span class="timing">
                        
                            Commence à jeudi
                        
                    </span>
                </li>
            
        </ul>
    </div>
    

    <div class="category-content-wrapper">
        <div class="category-content">
            

    <div id="flashed-messages" class="flashed-messages"></div>

            
    <div class="category-info flexrow">
        
        
    
        <p>
            Bienvenue dans Indico. Le logiciel Indico permet de gérer des conférences complexes, des ateliers ou de simples réunions.
            <br>
            Pour commencer votre navigation, veuillez sélectionner une catégorie ci-dessous.
        </p>
    

    </div>
    
    
        
            
                
    
        <ul class="category-list" data-subcat-info-url="/category/0/subcat-info">
            
                <li>
                    <span class="protection "></span>
                    <span class="number-events" id="category-event-count-24"></span>
                    <a href="/category/24/" class="name">Les GDR</a>
                </li>
            
                <li>
                    <span class="protection "></span>
                    <span class="number-events" id="category-event-count-55"></span>
                    <a href="/category/55/" class="name">Les conférences</a>
                </li>
            
                <li>
                    <span class="protection "></span>
                    <span class="number-events" id="category-event-count-1"></span>
                    <a href="/category/1/" class="name">Mathrice</a>
                </li>
            
                <li>
                    <span class="protection "></span>
                    <span class="number-events" id="category-event-count-6"></span>
                    <a href="/category/6/" class="name">Région Parisienne</a>
                </li>
            
                <li>
                    <span class="protection "></span>
                    <span class="number-events" id="category-event-count-7"></span>
                    <a href="/category/7/" class="name">Région nord-ouest &amp; dépendances de l&#39;Océan Indien</a>
                </li>
            
                <li>
                    <span class="protection "></span>
                    <span class="number-events" id="category-event-count-8"></span>
                    <a href="/category/8/" class="name">Région nord-est</a>
                </li>
            
                <li>
                    <span class="protection "></span>
                    <span class="number-events" id="category-event-count-9"></span>
                    <a href="/category/9/" class="name">Région sud-est &amp; Corse</a>
                </li>
            
                <li>
                    <span class="protection "></span>
                    <span class="number-events" id="category-event-count-10"></span>
                    <a href="/category/10/" class="name">Région sud-ouest &amp; dépendances de l&#39;Océan Atlantique</a>
                </li>
            
                <li>
                    <span class="protection "></span>
                    <span class="number-events" id="category-event-count-230"></span>
                    <a href="/category/230/" class="name">International</a>
                </li>
            
                <li>
                    <span class="protection icon-shield"></span>
                    <span class="number-events" id="category-event-count-43"></span>
                    <a href="/category/43/" class="name">Test</a>
                </li>
            
        </ul>
        <script>
            setupCategoryDisplaySubcatList();
        </script>
    

            
            

    <div class="event-list"
         data-show-future-events-url="/category/0/show-future-events"
         data-show-past-events-url="/category/0/show-past-events">
        
        <div>
            
    

        </div>
        
    </div>
    <script>
        setupCategoryDisplayEventList(false,
                                      false,
                                      false,
                                      {});
    </script>

        
    

        </div>
    </div>
</div>
<script>
    $('#navigate-button').on('click', function(evt) {
        $('<div>').categorynavigator({
            openInDialog: true,
            category: 0,
            actionButtonText: $T.gettext('Navigate to'),
            dialogTitle: $T.gettext('Navigate to a category'),
            onAction: function(category) {
                window.location.href = build_url(Indico.Urls.Categories.display, {category_id: category.id});
            }
        });
    });
</script>
<script type="application/ld+json">
[]
</script></div></div>
<div class="footer ">
    <div class="flexrow f-j-space-between">
            <div class="flexrow f-a-center f-self-stretch">
                
                    
                    <img src="/images/indico_small.png" class="footer-logo" alt="Indico">
                
                <div class="f-self-no-shrink" style="margin-left: 1em;">
                    <span>Fonctionne avec <a href="https://getindico.io">Indico</a>
            
                <span class="version">v3.2.7</span>
            </span>
                </div>
            </div>
            <ul class="footer-links">
                <li>
                    <a href="https://learn.getindico.io">
                        Aide
                    </a>
                </li>
                
                    <li>
                        <a href="/contact">
                            Contact
                        </a>
                    </li>
                
                
            </ul>
            <div class="footer-extra f-self-stretch">
                
                
            </div>
        </div>
    
</div>

<div id="outdated-browser"></div>
    
</body>
</html>
<!--
Queries:         13
Duration (sql):  0.010091s
Duration (req):  0.064192s
Endpoint:        categories.display
RH:              indico.modules.categories.controllers.display.RHDisplayCategory
-->
RH:              indico.modules.categories.controllers.display.RHDisplayCategory

That implies you were back on the category display page.

And indeed, when checking the code I noticed that we have this check…

        if not request.is_xhr:
            return redirect(url_for_index(_anchor=f'create-event:{self.event_type.name}'))

You can pass this check by sending X-Requested-With: xmlhttprequest in the headers (in addition to the auth header you already have).

Indeed, it now works. Thank you very much!