mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 21:07:28 -08:00
🐛 Fix Philips Hue API Connection (#2631)
* 🐛 Fix Philips Hue API Connection
* Philips Hue Node: Fixed typo in update operation description
This commit is contained in:
parent
c9e1892cd9
commit
e0ef645514
|
@ -21,13 +21,13 @@ export class PhilipsHueOAuth2Api implements ICredentialType {
|
|||
displayName: 'Authorization URL',
|
||||
name: 'authUrl',
|
||||
type: 'hidden',
|
||||
default: 'https://api.meethue.com/oauth2/auth',
|
||||
default: 'https://api.meethue.com/v2/oauth2/authorize',
|
||||
},
|
||||
{
|
||||
displayName: 'Access Token URL',
|
||||
name: 'accessTokenUrl',
|
||||
type: 'hidden',
|
||||
default: 'https://api.meethue.com/oauth2/token',
|
||||
default: 'https://api.meethue.com/v2/oauth2/token',
|
||||
},
|
||||
{
|
||||
displayName: 'Auth URI Query Parameters',
|
||||
|
|
|
@ -19,7 +19,7 @@ export async function philipsHueApiRequest(this: IExecuteFunctions | ILoadOption
|
|||
method,
|
||||
body,
|
||||
qs,
|
||||
uri: uri || `https://api.meethue.com${resource}`,
|
||||
uri: uri || `https://api.meethue.com/route${resource}`,
|
||||
json: true,
|
||||
};
|
||||
try {
|
||||
|
@ -36,14 +36,15 @@ export async function philipsHueApiRequest(this: IExecuteFunctions | ILoadOption
|
|||
}
|
||||
|
||||
//@ts-ignore
|
||||
return await this.helpers.requestOAuth2.call(this, 'philipsHueOAuth2Api', options, { tokenType: 'Bearer' });
|
||||
const response = await this.helpers.requestOAuth2.call(this, 'philipsHueOAuth2Api', options, { tokenType: 'Bearer' });
|
||||
return response;
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getUser(this: IExecuteFunctions | ILoadOptionsFunctions): Promise<any> { // tslint:disable-line:no-any
|
||||
const { whitelist } = await philipsHueApiRequest.call(this, 'GET', '/bridge/0/config', {}, {});
|
||||
const { whitelist } = await philipsHueApiRequest.call(this, 'GET', '/api/0/config', {}, {});
|
||||
//check if there is a n8n user
|
||||
for (const user of Object.keys(whitelist)) {
|
||||
if (whitelist[user].name === 'n8n') {
|
||||
|
@ -51,7 +52,7 @@ export async function getUser(this: IExecuteFunctions | ILoadOptionsFunctions):
|
|||
}
|
||||
}
|
||||
// n8n user was not fount then create the user
|
||||
await philipsHueApiRequest.call(this, 'PUT', '/bridge/0/config', { linkbutton: true });
|
||||
const { success } = await philipsHueApiRequest.call(this, 'POST', '/bridge', { devicetype: 'n8n' });
|
||||
await philipsHueApiRequest.call(this, 'PUT', '/api/0/config', { linkbutton: true });
|
||||
const { success } = await philipsHueApiRequest.call(this, 'POST', '/api', { devicetype: 'n8n' });
|
||||
return success.username;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ export const lightOperations: INodeProperties[] = [
|
|||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
description: 'Update an light',
|
||||
description: 'Update a light',
|
||||
},
|
||||
],
|
||||
default: 'update',
|
||||
|
|
|
@ -74,13 +74,13 @@ export class PhilipsHue implements INodeType {
|
|||
const lights = await philipsHueApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/bridge/${user}/lights`,
|
||||
`/api/${user}/lights`,
|
||||
);
|
||||
|
||||
const groups = await philipsHueApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/bridge/${user}/groups`,
|
||||
`/api/${user}/groups`,
|
||||
);
|
||||
|
||||
for (const light of Object.keys(lights)) {
|
||||
|
@ -144,7 +144,7 @@ export class PhilipsHue implements INodeType {
|
|||
const data = await philipsHueApiRequest.call(
|
||||
this,
|
||||
'PUT',
|
||||
`/bridge/${user}/lights/${lightId}/state`,
|
||||
`/api/${user}/lights/${lightId}/state`,
|
||||
body,
|
||||
);
|
||||
|
||||
|
@ -161,7 +161,7 @@ export class PhilipsHue implements INodeType {
|
|||
|
||||
const user = await getUser.call(this);
|
||||
|
||||
responseData = await philipsHueApiRequest.call(this, 'DELETE', `/bridge/${user}/lights/${lightId}`);
|
||||
responseData = await philipsHueApiRequest.call(this, 'DELETE', `/api/${user}/lights/${lightId}`);
|
||||
|
||||
}
|
||||
if (operation === 'getAll') {
|
||||
|
@ -169,7 +169,7 @@ export class PhilipsHue implements INodeType {
|
|||
|
||||
const user = await getUser.call(this);
|
||||
|
||||
const lights = await philipsHueApiRequest.call(this, 'GET', `/bridge/${user}/lights`);
|
||||
const lights = await philipsHueApiRequest.call(this, 'GET', `/api/${user}/lights`);
|
||||
|
||||
responseData = Object.values(lights);
|
||||
|
||||
|
@ -183,7 +183,7 @@ export class PhilipsHue implements INodeType {
|
|||
|
||||
const user = await getUser.call(this);
|
||||
|
||||
responseData = await philipsHueApiRequest.call(this, 'GET', `/bridge/${user}/lights/${lightId}`);
|
||||
responseData = await philipsHueApiRequest.call(this, 'GET', `/api/${user}/lights/${lightId}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue