Fortellis WIP
This commit is contained in:
137
fortellis.js
137
fortellis.js
@@ -100,6 +100,21 @@ async function GetBulkVendors() {
|
||||
}
|
||||
}
|
||||
|
||||
async function FetchVehicles({ SubscriptionID }) {
|
||||
const access_token = await GetAuthToken();
|
||||
try {
|
||||
//This doesn't seem to work as it is for production only.
|
||||
const Vehicles = await axios.get(`https://api.fortellis.io/cdkdrive/service/v1/vehicles/`, {
|
||||
headers: { Authorization: `Bearer ${access_token}`, "Subscription-Id": SubscriptionID }
|
||||
});
|
||||
console.log("🚀 ~ FetchVehicles ~ Vehicles:", Vehicles);
|
||||
|
||||
return Vehicles.data;
|
||||
} catch (error) {
|
||||
console.log("🚀 ~ FetchVehicles ~ error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
async function PostVehicleServiceHistory() {
|
||||
const access_token = await GetAuthToken();
|
||||
const ReqId = uuid();
|
||||
@@ -108,7 +123,7 @@ async function PostVehicleServiceHistory() {
|
||||
?.apiDmsInfo.find((info) => info.name === "CDK Drive Async Vendors")?.departments; //Departments are categorized by API name and have an array of departments.
|
||||
|
||||
//Need to get a vehicle ID from somewhere.
|
||||
|
||||
const vehicles = await FetchVehicles({ SubscriptionID });
|
||||
try {
|
||||
//TODO: This is pointing towards the test environment. Need to carefully watch for the production switch.
|
||||
const Vendors = await axios.post(
|
||||
@@ -128,4 +143,124 @@ async function PostVehicleServiceHistory() {
|
||||
}
|
||||
}
|
||||
|
||||
//PostVehicleServiceHistory();
|
||||
//GetBulkVendors();
|
||||
|
||||
async function GetDepartmentId() {
|
||||
const departmentIds = (await FetchSubscriptions())
|
||||
.find((s) => s.subscriptionId === SubscriptionID) //Get the subscription object.
|
||||
?.apiDmsInfo.find((info) => info.name === "CDK Drive Async Vendors")?.departments; //Departments are categorized by API name and have an array of departments.
|
||||
|
||||
return departmentIds[0].id;
|
||||
}
|
||||
//////////////////GL WIP Section //////////////////////
|
||||
async function OrgHelpers() {
|
||||
console.log("Executing Org Helpers");
|
||||
const ReqId = uuid();
|
||||
const access_token = await GetAuthToken();
|
||||
const DepartmentId = await GetDepartmentId();
|
||||
|
||||
try {
|
||||
//This doesn't seem to work as it is for production only.
|
||||
const OrgHelpers = await axios.get(`https://api.fortellis.io/cdk-test/drive/businessofficeglwippost/orgHelper`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${access_token}`,
|
||||
"Subscription-Id": SubscriptionID,
|
||||
"Request-Id": ReqId,
|
||||
"Department-Id": DepartmentId
|
||||
}
|
||||
});
|
||||
console.log("🚀 ~ OrgHelpers ~ Data:", OrgHelpers);
|
||||
|
||||
return OrgHelpers.data;
|
||||
} catch (error) {
|
||||
console.log("🚀 ~ OrgHelpers ~ error:", error);
|
||||
}
|
||||
}
|
||||
async function JournalHelpers({ glCompanyNumber }) {
|
||||
console.log("Executing Journal Helpers");
|
||||
const ReqId = uuid();
|
||||
const access_token = await GetAuthToken();
|
||||
const DepartmentId = await GetDepartmentId();
|
||||
|
||||
try {
|
||||
//This doesn't seem to work as it is for production only.
|
||||
const JournalHelpers = await axios.get(
|
||||
`https://api.fortellis.io/cdk-test/drive/businessofficeglwippost/jrnlHelper/${glCompanyNumber}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${access_token}`,
|
||||
"Subscription-Id": SubscriptionID,
|
||||
"Request-Id": ReqId,
|
||||
"Department-Id": DepartmentId
|
||||
}
|
||||
}
|
||||
);
|
||||
console.log("🚀 ~ JournalHelpers ~ Data:", JournalHelpers);
|
||||
return JournalHelpers.data;
|
||||
} catch (error) {
|
||||
console.log("🚀 ~ JournalHelpers ~ error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
async function GlSalesChain() {
|
||||
console.log("Executing GL Sales Chain");
|
||||
const ReqId = uuid();
|
||||
const access_token = await GetAuthToken();
|
||||
const DepartmentId = await GetDepartmentId();
|
||||
|
||||
try {
|
||||
//This doesn't seem to work as it is for production only.
|
||||
const GlSalesChain = await axios.get(
|
||||
`https://api.fortellis.io/cdk-test/drive/businessofficeglwippost/glSalesChain`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${access_token}`,
|
||||
"Subscription-Id": SubscriptionID,
|
||||
"Request-Id": ReqId,
|
||||
"Department-Id": DepartmentId
|
||||
}
|
||||
}
|
||||
);
|
||||
console.log("🚀 ~ GlSalesChain ~ Data:", GlSalesChain);
|
||||
return GlSalesChain.data;
|
||||
} catch (error) {
|
||||
console.log("🚀 ~ GlSalesChain ~ error:", error);
|
||||
}
|
||||
}
|
||||
async function GlExpenseAllocation() {
|
||||
console.log("Executing GL Expense Allocation");
|
||||
const ReqId = uuid();
|
||||
const access_token = await GetAuthToken();
|
||||
const DepartmentId = await GetDepartmentId();
|
||||
|
||||
try {
|
||||
//This doesn't seem to work as it is for production only.
|
||||
const GlExpenseAllocation = await axios.get(
|
||||
`https://api.fortellis.io/cdk-test/drive/businessofficeglwippost/glExpenseAllocation`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${access_token}`,
|
||||
"Subscription-Id": SubscriptionID,
|
||||
"Request-Id": ReqId,
|
||||
"Department-Id": DepartmentId
|
||||
}
|
||||
}
|
||||
);
|
||||
console.log("🚀 ~ GlExpenseAllocation ~ Data:", GlExpenseAllocation);
|
||||
return GlExpenseAllocation.data;
|
||||
} catch (error) {
|
||||
console.log("🚀 ~ GlSalesChain ~ error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
///EXEC FUNCTIONS
|
||||
async function PostAccountsGLWIP() {
|
||||
//const orgHelpers = await OrgHelpers();
|
||||
//const jrnlHelpers = await JournalHelpers({ glCompanyNumber: orgHelpers[0].coID });
|
||||
|
||||
//const glSalesChain = await GlSalesChain();
|
||||
const glExpenseAllocation = await GlExpenseAllocation();
|
||||
}
|
||||
|
||||
PostAccountsGLWIP();
|
||||
|
||||
Reference in New Issue
Block a user