![]() |
yonezawa
February 23 |
Thanks for the reply.
I am trying to create and run a function in AWS lambda.
The runtime nodejs is implemented in 20.x.
I have included the beginning of the program below.
If you have any suggestions, I would appreciate it if you could let me know.
Failure to obtain an access token.
‐‐‐‐‐‐‐‐‐‐‐
import AWS from 'aws-sdk';
import ini from 'ini';
import platformClient from 'purecloud-platform-client-v2';
import { HttpProxyAgent, HttpsProxyAgent } from 'hpagent';
const proxyUrl = process.env.HTTP_PROXY;
const{HttpsProxyAgent}= require('hpagent');
const client = platformClient.ApiClient.instance;
client.setEnvironment(platformClient.PureCloudRegionHosts.ap_northeast_1);
agent = new HttpsProxyAgent({
proxy: proxyUrl,
});
client.setProxyAgent(agent);
const tokenAPImethod = properties.GenesysSetting_Token.tokenAPImethod;
const tokenAPIURL = properties.GenesysSetting_Token.tokenAPIURL;
const TokenKigenSS = properties.GenesysSetting_Token.TokenKigenSS;
・
・
・
export async function runGTA001CSV() {
const token = await initialize();
}
async function initialize() {
console.log("初期処理を開始します...");
await checkLogFile();
const logLv = '[INFO ]';
const msg = 'インタラクション情報CSV作成処理 開始';
await logOutput(logLv, msg)
// □ アクセストークン取得
// ■ トークン取得
const returnToken = await getAccessToken()
console.log("初期処理完了...");
return returnToken;
}
async function getAccessToken() {
try {
const res = await client.loginClientCredentialsGrant(clientId, clientSecret);
const accessToken = res.accessToken;
return accessToken;
} catch (err) {
console.error('アクセストークンの取得に失敗しました:', err);
const logLv = '[ERROR ]';
const msg = `トークンAPI機能:${err}`;
await logOutput(logLv, msg);
throw new error('処理が失敗しました');
}
}
Visit Topic to respond.
![]() |
Jerome.Saint-Marc
Genesys Employee
February 23 |
![]() |
Jerome.Saint-Marc
Genesys Employee
February 23 |
I assume you did not run a file with just this code extract in it. I cannot guess/try if you don't share more. I would need to see what's the rest of your code.
Also what version of nodejs are you using?
What are you using to run this test (I mean running this on your computer? is that lambda logs?)?
I would start with checking if you have not declared the hpagent import somewhere else in your code.
Also, if you declare a file with mjs extension, it means that you want to import using ECMAScript module approach (using "import").
Using import of modules using "require" is for CommonJS modules.
Regards,
![]() |
yonezawa
February 22 |
Thanks for the info, but I wrote below, but it gave me an error.
‐‐‐‐‐‐‐‐‐‐
const{HttpsProxyAgent}= require('hpagent');
const client = platformClient.ApiClient.instance;
agent = new HttpsProxyAgent({
proxy: proxyUrl,
});
client.setProxyAgent(agent);
‐‐‐‐‐‐‐‐‐‐
I would like to know how to solve this problem.
‐‐‐‐‐‐‐‐‐
2025-02-22T15:45:44.795Z undefined ERROR Uncaught Exception {
"errorType": "Runtime.UserCodeSyntaxError",
"errorMessage": "SyntaxError: Identifier 'HttpsProxyAgent' has already been declared",
"stack": [
"Runtime.UserCodeSyntaxError: SyntaxError: Identifier 'HttpsProxyAgent' has already been declared",
" at _loadUserApp (file:///var/runtime/index.mjs:1084:17)",
" at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)",
" at async start (file:///var/runtime/index.mjs:1282:23)",
" at async file:///var/runtime/index.mjs:1288:1"
]
}
‐‐‐‐‐‐‐‐‐
![]() |
Jerome.Saint-Marc
Genesys Employee
February 21 |
Hello,
const {HttpsProxyAgent} = require('hpagent')
const client = platformClient.ApiClient.instance;
agent = new HttpsProxyAgent({
proxy: proxyUrl,
});
client.setProxyAgent(agent)
new HttpsProxyAgent
and not new HttpProxyAgent
Regards,
![]() |
yonezawa
February 21 |
I am trying to create a function on AWS lambda to
retrieve GenesysCloud information.
However, I need to go through a proxy, and I am referring to the Using a Proxy (Node.js only) section of the following page as follows.
‐‐‐‐‐‐‐‐
const proxyUrl = process.env.HTTP_PROXY;
const client = platformClient.ApiClient.instance;
const agent = new HttpProxyAgent({
proxy: proxyUrl,
});
client.setProxyAgent(agent);
‐‐‐‐‐‐‐‐
I get the following error and do not know how to resolve it.
・TypeError [ERR_INVALID_PROTOCOL]: Protocol "https:" not supported. Expected "http:"
Visit Topic to respond.
You are receiving this because you enabled mailing list mode.
To unsubscribe from these emails, click here.