Hi.
I'm am a newbie to Botpress (although no stranger to programming).
First up, I trust I am in the correct section to post such questions?
I would like some pointers please in running an action that retrieves an OAuth token from an external server via a POST command.
Question 1:
-----
Part of the Action JS reads thus:
const payload = {
"username": "api_user",
"password": "pswdsecret",
"APIKey": "ABABABAB-CDCD-EFEF-ABAB-ABCDABCDABCD"
};
I have setup some Workflow variables (Im not sure if this is the right scope or not, and I have replaced the value of "api_user" with {{api_variable}} which it seems to accept on the first line only, however, the other two variables below it have a red line underneath it. I'm thinking the variables work because I can change the order of these three lines and the first one always seems right.
const payload = {
"username": {{api_user}},
"password": {{api_pswd}},
"APIKey": {{api_key}}
};
What is it in my code here that needs to be changed? Remove the commas? I presume that it is a better approach to use variables here rather than have the credentials hard-coded into the action itself?
Question 2:
-----
When this first section runs successfully (as a version of it works fine in Postman), I need to then use the retrieved token into a variable - which I have also declared at the Workflow scope level. The returned data is JSON which I need to extract my token from.
Do I need to set anything in the Output Schema to prepare for returned data, and if so, how? I only get the options of None and Array (which doesn't expand to anything) to choose from.
What am I missing here please?
Any help would be appreciated. Has anybody got a script or example that does this same task?
Thanks,
Greg