Skip to content

Enable public api #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add createInviteV1 to create invites using new route
  • Loading branch information
tkla committed Jun 7, 2022
commit 69702c3079e033529dd5a847dd2a05cd04a4d14d
47 changes: 41 additions & 6 deletions lib/EnvoyAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class EnvoyAPI {
this.token = token;
this.baseUrl = process.env.ENVOY_BASE_URL || 'https://app.envoy.com';
this.newUrl = 'https://api.envoy.com/v1';
/*
Request library is deprecated as of 2020, we should update to another REST library soon.
*/
this.request = request.defaults({
headers: {
Authorization: `Bearer ${token}`,
Expand All @@ -58,6 +61,21 @@ class EnvoyAPI {
json: true,
baseUrl: this.baseUrl,
});

/*
Setting ENVOY_BASE_URL in .env to point to the new API endpoint will break some methods below relying on the old route.
A temporary workaround for now is to set a new Request default with the updated endpoint.
*/
// this.requestNewRoute = request.defaults({
// headers: {
// Authorization: `Bearer ${token}`,
// 'Content-Type': 'application/vnd.api+json',
// Accept: 'application/vnd.api+json',
// 'X-Envoy-Context': JSON.stringify(xEnvoyContext),
// },
// json: true,
// baseUrl: this.newUrl,
// })
}

/**
Expand Down Expand Up @@ -123,10 +141,10 @@ class EnvoyAPI {
*/
async companies() {
var options = {
'method': 'GET',
'url': this.newUrl + '/companies',
'headers': {
'Authorization': 'Bearer ' + this.token
method: 'GET',
url: this.newUrl + '/companies',
headers: {
Authorization: 'Bearer ' + this.token
},
json: true,
};
Expand Down Expand Up @@ -524,7 +542,7 @@ class EnvoyAPI {


/**
* @param { {} } invite Object containing query params.
* @param { {} } invite Object containing query params. See invites API documentation for list of all possbile Query params.
* @returns {Promise<EnvoyObject>}
*/
async getInvites(invite){
Expand Down Expand Up @@ -562,7 +580,24 @@ class EnvoyAPI {

return EnvoyAPI.getDataFromBody(body);
}

async createInviteV1(invite) {
var options = {
method: 'GET',
url: this.newUrl + `/invites`,
headers: {
Authorization: 'Bearer ' + this.token
},
body: invite,
json: true
};

const body = await request(options, function (error, response) {
if (error) throw new Error(error);
response.body;
});
}

/**
* Updates an invite.
*
Expand Down Expand Up @@ -785,4 +820,4 @@ class EnvoyAPI {
}
}

module.exports = EnvoyAPI;
module.exports = EnvoyAPI;