Function Data Actions - How to use Function Credentials

Hi,

I created a function and would like to send it the credentials to generate the token.

I have configured the Request Body Template as below:

{
"headers": {
"id": $encoding.base64("${credentials.clientId}:${credentials.clientSecret}")
},
"requestTemplate": ${input.rawRequest}
}

When testing this it returns the following error:

Resolve request body template: Processing the Request Body Template resulted in invalid JSON.
Unrecognized token 'Y2U5M2UzZDEtYTM1NS00YjA0LWFmYWUtYzkxOWU3MTA3NzcyOjlHYmRyeDVUMkRuTGRxQUFIUWdpNVpYUi1sWXhJNFRRZHFwazFTRG82YzA': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false') at [Source: REDACTED (StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION disabled); line: 3, column: 118]

I would like to know if there is a better way to pass credentials to the function?

Regards,

I would guess that you are having a quoting problem. Based on the example here:

it probably needs to be something like this:
"id": "$encoding.base64(\"${credentials.clientId}:${credentials.clientSecret}\")"

I'm tending to do it in Function Data Actions, I think it should be a little different from web services data actions.

I adjusted the request as informed.

{
"headers": {
"id": "$encoding.base64("${credentials.clientId}:${credentials.clientSecret}")"
},
"requestTemplate": "${input.rawRequest}"
}

However, the error still persists.

  • Action failed validation. Errors: [Template validation failed for 'config.request.requestTemplate'. Details: Lexical error, Encountered: """ (34), after : "\" at unset[line 3, column 42]]

The request is like this:

image

Hello,

When you configure your Request/Response Configurations, select the "JSON" switch (toggle from Simple to JSON display) first.
You can then copy the content that Jason gave you.
By copying while in Simple display, the UI will try to escape characters (that were already escaped).

Try something like this (while in JSON display):

{
  "requestType": "POST",
  "headers": {
    "id": "$encoding.base64(\"${credentials.clientId}:${credentials.clientSecret}\")"
  },
  "requestTemplate": "${input.rawRequest}"
}

Regards,

Hi,

ran without json errors.

However, the credential values ​​are appearing with ""

{
"id": [
"OjlHYmRyeDVUMkRuTGRxQUFIUWdpNVpYUi1sWXhJNFRRZHFwazFTRG82YzA="
],
"url": [
""
]
}

image

I inserted the attributes (clientId, clientSecret and loginUrl) in the credentials of the Function Data Actions.

But apparently it is not working.

A bit vague. That's probably a problem with your function code.

Regards,

Hi,

I'm seeing what's being sent in the header regarding the credentials (even before reaching the function).
From what I've seen, only the clientSecret variable is working.
The loginUrl and clientId variables are returning "REDACTED"

image

I have this request:

What is defined as credentials attributes (in your Function Integration) will appear as in logging. So people can't read clientId and clientSecret or else when testing a data action.

Regards,

You're right!

But how do I pass these variables to the function?

I did some tests and got this result:

Request Header

When testing in the Header the values ​​appear as REDACTED.

I am returning the values ​​of the function in the execution and the content is REDACTED too.

I need to receive the credential values ​​to obtain the token from within the function.

How can I do this?

<REDACTED>OjlHYmRyeDVUMkRuTGRxQUFIUWdpNVpYUi1sWXhJNFRRZHFwazFTRG82YzA="

On the side of the function apparently only converting the clientSecret to base64 the clientId is as <REDACTED>

Regards,

As I explained, the REDACTED is to hide these values in LOGS/TRACES appearing in the Test Data Action when you test from the Genesys UI.
Your function is receiving the real values.

I am off for several days. So that's my last answer on this.

Regards,

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.