Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API REST (en partie?) #2

Open
Cyrille37 opened this issue Sep 19, 2024 · 3 comments
Open

API REST (en partie?) #2

Cyrille37 opened this issue Sep 19, 2024 · 3 comments

Comments

@Cyrille37
Copy link

Hello @yoandm

Suite à la relance de @kepon85 sur l'agora j'ai fouillé et il semble que l'API fonctionne sur le principe REST.

Après le login en http/html comme fait ici, il suffit de conserver le cookie beaker.session.id, pas besoin de CSRF token.

Avec le client GuzzleHttp

            $cookies = new \GuzzleHttp\Cookie\CookieJar;
            /**
             * enDI say "Navigateur non supporté" -> set the User-Agent
             * Auth works with cookie "beaker.session.id"
             */
            $client = new \GuzzleHttp\Client([
                'base_uri' => $_ENV['endi_url'],
                'cookies' => $cookies,
                'headers' => [
                    'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:130.0) Gecko/20100101 Firefox/130.0'
                ],
            ]);

Le login

            $response = $client->post(
                '/login',
                [
                    'form_params' => [
                        // Some params are mandatory !
                        'submit' => 'submit',
                        //'nextpage'=>'/',
                        //'_charset_'=>'UTF-8',
                        //'__formid__' => 'authentication',
                        'login' => $_ENV['endi_username'],
                        'password' => $_ENV['endi_password'],
                    ],
                ]
            );

La liste des clients

        $response = $client->get(
            '/api/v1/companies/'.$company_id.'/customers',
        );

Mise à jour du champs company_name pour un customer

        $response = $client->put(
            '/api/v1/customers/'.$customer_id,
            [
                'json' => [
                    'company_name' => 'My heroic customer'
                ]
            ]
        );
@Cyrille37
Copy link
Author

Et en fait il en est question sur https://framagit.org/caerp/caerp/-/issues/3534

@yoandm
Copy link
Owner

yoandm commented Sep 19, 2024 via email

@Cyrille37
Copy link
Author

Pour une liste de factures j'ai trouvé ce chemin: https://framagit.org/caerp/caerp/-/issues/3534#note_2132980

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants