@@ -8,46 +8,40 @@ const log = logger(module.filename);
88const NB_ELEMENTS_TO_GET = 1000 ;
99
1010module . exports . checkTokenApiEntreprise = async ( ) => {
11+ log . i ( "IN" ) ;
1112 try {
1213 const params = new URLSearchParams ( { token : config . apiEntreprise . token } ) ;
1314 const url = `${ config . apiEntreprise . url } /privileges?${ params } ` ;
1415 const { data } = await axios . get ( url ) ;
16+ log . i ( "DONE" ) ;
1517 return data ;
1618 } catch ( error ) {
19+ log . w ( "DONE with error" ) ;
1720 throw new Error ( `API Entreprise error: ${ error . message } ` ) ;
1821 }
1922} ;
2023
21- const getToken = async ( ) => {
24+ const getInformations = async ( ) => {
2225 log . i ( "IN" ) ;
2326 try {
2427 const { apiInsee } = config ;
25- const cle = `${ apiInsee . CLIENT_ID } :${ apiInsee . CLIENT_SECRET } ` ;
26- const authHeader = `Basic ${ Buffer . from ( cle ) . toString ( "base64" ) } ` ;
27- const token = await axios . post (
28- `${ apiInsee . URL } /token` ,
29- { } ,
30- {
31- headers : {
32- Authorization : authHeader ,
33- "Content-type" : "application/x-www-form-urlencoded" ,
34- } ,
35- params : {
36- grant_type : "client_credentials" ,
37- } ,
38- } ,
28+ const { data } = await axios . get (
29+ `${ apiInsee . URL } ${ apiInsee . URI } /informations` ,
30+ { headers : { "X-INSEE-Api-Key-Integration" : `${ apiInsee . TOKEN } ` } } ,
3931 ) ;
40- return token . data . access_token ;
32+ log . i ( "DONE" ) ;
33+ return data ;
4134 } catch ( error ) {
42- throw new Error ( `API Entreprise error: ${ error . message } ` ) ;
35+ log . w ( "DONE with error" ) ;
36+ throw new Error ( `API Insee error: ${ error . message } ` ) ;
4337 }
4438} ;
4539
46- module . exports . getToken = getToken ;
40+ module . exports . getInformations = getInformations ;
4741
4842module . exports . getEtablissement = async ( siret ) => {
4943 const { apiInsee } = config ;
50- log . w ( "getEtablissement" , { siret } ) ;
44+ log . i ( "getEtablissement" , { siret } ) ;
5145 const dateDuJour = dayjs ( ) . format ( "YYYY-MM-DD" ) ;
5246 const { data } = await axios . get (
5347 `${ apiInsee . URL } ${ apiInsee . URI } /siret/${ siret } ?date=${ dateDuJour } ` ,
0 commit comments