forked from andnilsson/dyn365-deploy-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.ts
32 lines (27 loc) · 985 Bytes
/
functions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { variables } from './ivariables';
import getTokenAsync from 'dyn365-access-token';
var unirest = require("unirest");
export async function getAccessToken(config: variables) {
var req = {
username: config.username,
password: config.password,
client_id: config.clientid,
client_secret: config.clientsecret,
resource: config.resource,
commonAuthority: config.commonAuthority,
}
return await getTokenAsync(req);
}
export async function publishcrm(token: string, resource: string, apiversion: string): Promise<void> {
return new Promise<void>((resolve, reject) => {
var req = unirest("POST", `${resource}/api/data/v${apiversion}/PublishAllXml`);
req.headers({
"content-type": "application/json",
"authorization": `Bearer ${token}`
});
req.end((res) => {
if (res.error) throw new Error(res.error);
resolve();
});
});
}