diff --git a/integrationos-platform-oauth/src/connections/microsoftDynamics365BusinessCentral/init.ts b/integrationos-platform-oauth/src/connections/microsoftDynamics365BusinessCentral/init.ts index 18ab4a00..7745ac48 100644 --- a/integrationos-platform-oauth/src/connections/microsoftDynamics365BusinessCentral/init.ts +++ b/integrationos-platform-oauth/src/connections/microsoftDynamics365BusinessCentral/init.ts @@ -22,12 +22,25 @@ export const init = async ({ body }: DataObject): Promise => { data: { access_token, expires_in, token_type }, } = response; + const companiesURL = `https://api.businesscentral.dynamics.com/v2.0/${body.metadata?.formData?.ENVIRONMENT_NAME}/api/v2.0/companies`; + + const companies = await axios.get(companiesURL, { + headers: { + Authorization: `Bearer ${access_token}`, + }, + }); + + const { + data: { value: companiesData }, + } = companies; + const companyId = companiesData[0].id; + return { accessToken: access_token, refreshToken: "", expiresIn: +expires_in, tokenType: token_type, - meta: {}, + meta: { companyId }, }; } catch (error) { throw new Error( diff --git a/integrationos-platform-oauth/src/connections/microsoftDynamics365BusinessCentral/refresh.ts b/integrationos-platform-oauth/src/connections/microsoftDynamics365BusinessCentral/refresh.ts index 13735b2f..b2dca7e4 100644 --- a/integrationos-platform-oauth/src/connections/microsoftDynamics365BusinessCentral/refresh.ts +++ b/integrationos-platform-oauth/src/connections/microsoftDynamics365BusinessCentral/refresh.ts @@ -8,6 +8,7 @@ export const refresh = async ({ body }: DataObject): Promise => { OAUTH_CLIENT_ID: client_id, OAUTH_CLIENT_SECRET: client_secret, OAUTH_REQUEST_PAYLOAD: { formData }, + OAUTH_METADATA, } = body; const requestBody = { grant_type: "client_credentials", @@ -32,7 +33,9 @@ export const refresh = async ({ body }: DataObject): Promise => { refreshToken: "", expiresIn: +expires_in, tokenType: token_type, - meta: {}, + meta: { + ...OAUTH_METADATA?.meta, + }, }; } catch (error) { throw new Error(