Passing environment variables to cloud function extension

dgoyal
Participant I

Hi,

I have created KVM in m test environment with keys "projectId" and "region".
A "key value map" operation reads KVM and assigns values to variables "region" and "projectId". I can see the variables using trace.

Next step is a call to Cloud Function extension where I am setting input and output tags as
<Input><![CDATA[ { "region" : {region}, "projectId" : {projectId}, "functionName" : "PostReader_GetPost", "method" : "POST", "payload" : {response.content} } ]]></Input>

<Output parsed="false"> function.response </Output>

I am getting an error "{"error":"SyntaxError: Unexpected token u in JSON at position 35"}"

Please advise what should be correct syntax to be used.

PS: Following input and output values for cloud function extension work fine

<Input><![CDATA[ { "region" : "RRRRRRR", "projectId" : "xxxxxxxx", "functionName" : "PostReader_GetPost", "method" : "POST", "payload" : {response.content} } ]]></Input> <Output parsed="false"> function.response </Output>

Solved Solved
0 3 282
2 ACCEPTED SOLUTIONS

Not applicable

You need to put all the variables in double quotes.

Example: {response.content} to

"{response.content}"

View solution in original post

dgoyal
Participant I

Final update - solved.
I had to use quotes around "{region}" and ""{projectId}" and remove quotes around "{response.content}".

Following worked

    <Action>invoke</Action>
    <Input><![CDATA[
         {
            "region" : "{region}",
            "projectId" : "{projectId}",
            "functionName" : "PostReader_GetPost",
            "method" : "POST",
            "payload" : {response.content}
         }
     ]]></Input>
    <Output parsed="false">
        function.response
    </Output>

View solution in original post

3 REPLIES 3

Not applicable

You need to put all the variables in double quotes.

Example: {response.content} to

"{response.content}"

dgoyal
Participant I

@Priyadarshi Ajitav Jena,

Thank you for the suggestion

I tried that too. If I use double quote and configure CloudFunctionExtension as

<Connector>CloudFunctionExtension</Connector><Action>invoke</Action><Input><![CDATA[
         {
            "region" : "{region}",
            "projectId" : "{projectId}",
            "functionName" : "PostReader_GetPost",
            "method" : "POST",
            "payload" : "{response.content}"
         }
     ]]></Input><Outputparsed="false">
        function.response
    </Output>

Connector call out function response changes to

{"error":"SyntaxError: Unexpected token p in JSON at position 204"}

As noted earlier, hardcoded region and projectId works without any error

<Connector>CloudFunctionExtension</Connector><Action>invoke</Action><Input><![CDATA[
         {
            "region" : "us-east1",
            "projectId" : "steam-form-NNNNN",
            "functionName" : "PostReader_GetPost",
            "method" : "POST",
            "payload" : {response.content}
         }
     ]]></Input><Outputparsed="false">
        function.response
    </Output>

Any new suggestions will be highly appreciated.

dgoyal
Participant I

Final update - solved.
I had to use quotes around "{region}" and ""{projectId}" and remove quotes around "{response.content}".

Following worked

    <Action>invoke</Action>
    <Input><![CDATA[
         {
            "region" : "{region}",
            "projectId" : "{projectId}",
            "functionName" : "PostReader_GetPost",
            "method" : "POST",
            "payload" : {response.content}
         }
     ]]></Input>
    <Output parsed="false">
        function.response
    </Output>