How can I return the entire JSON

I’m using the following code, which returns “200.” However, I would like to retrieve the complete JSON response instead.

pack.addFormula({
name: “All_UniteLegale”,
description: “”,

parameters: [ coda.makeParameter({
type: coda.ParameterType.String,
name: “siren”,
description: “Numéro SIREN de l entreprise”,
}
),
],

resultType: coda.ValueType.String,

execute: async function ([siren], context) {
let response = await context.fetcher.fetch({
method : “GET”,
url:https://api.insee.fr/entreprises/sirene/V3.11/siren/${siren},
});

return response.body;

},
});

can you share with us what you get returned if you

return response;

so we can see the entire JSON.
from that it may be possible to work out which part of the response you need to use.

I can’t return response, it gives me an error in the code.
But the entire JSON is this one :
{
“header”: {
“statut”: 200,
“message”: “OK”
},
“uniteLegale”: {
“siren”: “908268709”,
“statutDiffusionUniteLegale”: “O”,
“dateCreationUniteLegale”: “2021-12-10”,
“sigleUniteLegale”: null,
“sexeUniteLegale”: null,
“prenom1UniteLegale”: null,
“prenom2UniteLegale”: null,
“prenom3UniteLegale”: null,
“prenom4UniteLegale”: null,
“prenomUsuelUniteLegale”: null,
“pseudonymeUniteLegale”: null,
“identifiantAssociationUniteLegale”: null,
“trancheEffectifsUniteLegale”: null,
“anneeEffectifsUniteLegale”: null,
“dateDernierTraitementUniteLegale”: “2024-03-22T14:26:06.000”,
“nombrePeriodesUniteLegale”: 1,
“categorieEntreprise”: “PME”,
“anneeCategorieEntreprise”: “2021”,
“periodesUniteLegale”: [
{
“dateFin”: null,
“dateDebut”: “2021-12-10”,
“etatAdministratifUniteLegale”: “A”,
“changementEtatAdministratifUniteLegale”: false,
“nomUniteLegale”: null,
“changementNomUniteLegale”: false,
“nomUsageUniteLegale”: null,
“changementNomUsageUniteLegale”: false,
“denominationUniteLegale”: “OPTIMIZIO”,
“changementDenominationUniteLegale”: false,
“denominationUsuelle1UniteLegale”: null,
“denominationUsuelle2UniteLegale”: null,
“denominationUsuelle3UniteLegale”: null,
“changementDenominationUsuelleUniteLegale”: false,
“categorieJuridiqueUniteLegale”: “5710”,
“changementCategorieJuridiqueUniteLegale”: false,
“activitePrincipaleUniteLegale”: “70.22Z”,
“nomenclatureActivitePrincipaleUniteLegale”: “NAFRev2”,
“changementActivitePrincipaleUniteLegale”: false,
“nicSiegeUniteLegale”: “00015”,
“changementNicSiegeUniteLegale”: false,
“economieSocialeSolidaireUniteLegale”: “N”,
“changementEconomieSocialeSolidaireUniteLegale”: false,
“societeMissionUniteLegale”: null,
“changementSocieteMissionUniteLegale”: false,
“caractereEmployeurUniteLegale”: null,
“changementCaractereEmployeurUniteLegale”: false
}
]
}
}

In your Pack code you have resultType: coda.ValueType.String, which indicates that the formula will return a string. The JSON response from the API is automatically parsed into a JavaScript object. You can turn it back into a string using JSON.stringify().

That said, the ideal way to return an object to your Coda doc is to use a the result type Object and define a schema that matches the JSON structure. You can learn more here:

1 Like