-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate-base.js
41 lines (32 loc) · 1.12 KB
/
create-base.js
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
33
34
35
36
37
38
39
40
41
const fs = require('fs');
const axios = require('axios');
const CredentialsStore = require('./credential-store');
var keyFileContents = fs.readFileSync('./keys.crd','utf8');
var credentialStore = new CredentialsStore(keyFileContents);
var apiKey = credentialStore.getCredential('airtableApiKey');
var workspaceId = credentialStore.getCredential('airtableWorkspaceId');
const args = process.argv.slice(2);
var baseName = args[0];
if (!baseName) {
console.error('Error: Base name is required');
process.exit(1);
}
baseName = `Panoply:${baseName}`;
const url = `https://api.airtable.com/v0/meta/bases`;
const schema = JSON.parse(fs.readFileSync('airtable_schema.json', 'utf8'));
var data = {
name: baseName,
tables: schema.tables,
workspaceId: workspaceId
};
console.log(data);
axios.post(url, data, {
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
}
}).then(response => {
console.log('Base created successfully:', response.data);
}).catch(error => {
console.error('Error creating base:', error.response ? error.response.data : error.message);
});