How to get Query Params Values from Extract Variables in Node.js script in Apigee flow?

brinda
New Member

Hi,

I have a form on Apigee Edge Dev Portal. When I submit the form it calls a Node.js proxy flow that I created. The values come to the Node.js flow as query so I use ExtractVariable policy and store the values. I dont know how to use that values in node.js script. Does anyone have any document on that?

I tried something like this and it doesnt work:

var id : idFromExtractVariable

Solved Solved
0 5 1,264
1 ACCEPTED SOLUTION

The code you showed is not valid JavaScript. This line:

var id : idFromExtractVariable

.... that's not JavaScript.

You didn't tell me all the details, so I am guessing here. But It sounds to me that

  1. you have an Apigee (Drupal based) Dev Portal
  2. You have configured the "management server url" for that devportal to point to an API Proxy managed by Apigee Edge
  3. The API proxy in Apigee Edge is running a nodejs target
  4. You would like the nodejs target to be able to access a query parameter
  5. You are trying to use the ExtractVariables policy in some way, to get the query parameter into a context variable
  6. You want to pass the output of ExtractVariables - the context variable - to your nodejs script

Do I have that right?

If so, don't do that. Specifically steps 5 and 6 above are unnecessary. The nodejs script can retrieve query parameters easily, and there's no need for ExtractVariables for that purpose.

I suggest you read up on express-js; try some tutorials outside of Apigee Edge. Learn JavaScript and Nodejs. I have suggested this in answers I wrote to some of your other questions. I'm repeating the suggestion here because it's a good idea.

I think you may lack a clear understanding of how nodejs and express work, irrespective of Apigee Edge. That lack of understanding is a repeated obstacle to your ability to use nodejs within Edge effectively.

Put first things first. If you would like to use nodejs in Apigee Edge, first Learn Nodejs. Learn express. Then apply it within Edge.

If nodejs is new to you, you may benefit from adopting a new tool to help you. VSCode is a nice option. It's from Microsoft. It's free. Runs on Windows and OSX. Will help you edit nodejs code. I can recommend it. Microsoft has published tutorials about building nodejs/express apps using VSCode. Try it out!

View solution in original post

5 REPLIES 5

The code you showed is not valid JavaScript. This line:

var id : idFromExtractVariable

.... that's not JavaScript.

You didn't tell me all the details, so I am guessing here. But It sounds to me that

  1. you have an Apigee (Drupal based) Dev Portal
  2. You have configured the "management server url" for that devportal to point to an API Proxy managed by Apigee Edge
  3. The API proxy in Apigee Edge is running a nodejs target
  4. You would like the nodejs target to be able to access a query parameter
  5. You are trying to use the ExtractVariables policy in some way, to get the query parameter into a context variable
  6. You want to pass the output of ExtractVariables - the context variable - to your nodejs script

Do I have that right?

If so, don't do that. Specifically steps 5 and 6 above are unnecessary. The nodejs script can retrieve query parameters easily, and there's no need for ExtractVariables for that purpose.

I suggest you read up on express-js; try some tutorials outside of Apigee Edge. Learn JavaScript and Nodejs. I have suggested this in answers I wrote to some of your other questions. I'm repeating the suggestion here because it's a good idea.

I think you may lack a clear understanding of how nodejs and express work, irrespective of Apigee Edge. That lack of understanding is a repeated obstacle to your ability to use nodejs within Edge effectively.

Put first things first. If you would like to use nodejs in Apigee Edge, first Learn Nodejs. Learn express. Then apply it within Edge.

If nodejs is new to you, you may benefit from adopting a new tool to help you. VSCode is a nice option. It's from Microsoft. It's free. Runs on Windows and OSX. Will help you edit nodejs code. I can recommend it. Microsoft has published tutorials about building nodejs/express apps using VSCode. Try it out!

Hi @Dino

Yes I am trying to do step 5 and 6. I know node.js and have worked on it before but I am facing issues with Apigee as it is new for me. I have worked on express before but when I use the same code and same functions in Apigee nodejs, it doesnt work. I am good with node.js thats why I decided to write this flow in node.js.

Anyways thanks for your suggestion.

I know this is not a valid javascript. My bad, I meant I wanted to set the query-variable in var args thats an array.

var args =
    {
        projectID : 'XX',
        title : 'XXXX', 
        assignees : ['XXXX'] ,
        priorityNumber :'XX',
        status :'XXXX',
        description: 'XXXX',
        selectContact: idFromExtractVariable,
        projfields :
        {
            Request__bType : 'XXXX', 
            Service__bFamily : 'XXXX', 
            Service : 'XXXX', 
            Category : 'XXXX'
        }
    };

I wish there was a proper & more documentation on how to use Node.js on Apigee, then it would have been much easy to understand.

I'm sorry you have not found the documentation you seek. You seem to be stuck on a thing which is specific to nodejs - how to refer to a query parameter. This has nothing to do with Apigee Edge. The way to refer to a query parameter in nodejs+express is the same, whether the nodejs app is running in Apigee Edge or in node v8.

Here is how to do it when you use express.

var express = require('express');
var app = express();

app.get('/*', function(req, res){
  // req.query.id holds the query param 'id'
});

app.listen(3000);

You do not need to use ExtractVariables for this purpose. You should not use ExtractVariables for this purpose.

Hi @Dino

Express worked finally. Thank you for all your help.

I really appreciate it!!

Super! I'm glad to hear it!