{ Community }
  • Academy
  • Docs
  • Developers
  • Resources
    • Community Articles
    • Apigee on GitHub
    • Code Samples
    • Videos & eBooks
    • Accelerator Methodology
  • Support
  • Ask a Question
  • Spaces
    • General
    • Edge/API Management
    • Developer Portal
    • API Design
    • APIM on Istio
    • Extensions
    • Business of APIs
    • Academy/Certification
    • Analytics
    • Events
    • Integration (AWS, PCF, Etc.)
    • Microgateway
    • Monetization
    • Private Cloud Deployment
    • Insights
    • IoT Apigee Link
    • BaaS/Usergrid
    • BaaS Transition/Migration
    • Apigee-127
    • New Customers
    • Topics
    • Questions
    • Articles
    • Ideas
    • Leaderboard
    • Badges
  • Log in
  • Sign up

Get answers, ideas, and support from the Apigee Community

  • Home /
  • General /
avatar image
1
Question by santosh_ghalsasi · Apr 11, 2016 at 01:06 PM · 9.9k Views query parameter

Best way to accept multiple values in a query parameter

I want to know the best way we can have in API to accept multiple values for a query parameter.

For example if I want to pass multiple values for a query parameter name then I can do it like -

1. <API URL>?name=a,b,c- Use some logic to from an array and take this ahead for processing.

2. <API URL>?name=a&name=b&name=c - Use some logic to from an array and take this ahead for processing.

Above are just examples and there might be more possible ways to do that.

I want to know what is the best way we can use to make use of API simpler.

Thanks,

Santosh

Comment
Add comment Show 1
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Anil Sagar @ Google ♦♦   · Apr 11, 2016 at 01:08 PM 0
Link

@santosh_ghalsasi , Great question. See similar discussion in S.O here.

Close

1 Answer

· Add your answer
  • Sort: 
avatar image
0
Best Answer

Answer by Alex Koo   · Apr 11, 2016 at 05:34 PM

Hi Santosh,

Great question. As I'm sure you are aware, RFC 3986 (Uniform Resource Identifier (URI): Generic Syntax) doesn't cover this aspect of query parameters in section 3.4. You've identified the 2 most common ways to pass in multiple values for a query parameter.

From an Apigee Edge perspective, the main difference is that request.queryparam.<queryParamName>.values.count will be 1 for #1 and 3 for #2. To access the values in case #1, you can use request.queryparam.name directly, and in case #2 you will need to use request.queryparam.name.values. In both cases, you'll likely need to do some massaging to manipulate the data.

Aside from that, you may want to consider what is easier for your client to send to Apigee.

Comment
Add comment Show 3 · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Karthick Vankayala · Jul 15, 2016 at 03:44 AM 0
Link

Hi @Alex Koo,

Here if I consider #2 way of sending information from client. Could I know how we can access each value in this query param?

Thanks in advance!

avatar image Alex Koo ♦♦ Karthick Vankayala   · Jul 15, 2016 at 04:09 AM 0
Link

Hi Karthick,

The variable request.queryparam.<QPName>.values is an array.

You can slice and dice the array as you'd like in a script callout, e.g., javascript callout:

 arr = context.getVariable('request.queryparam.qp1.values');
 context.setVariable('newName',arr[1]);

Feel free to upvote my original answer if you found this useful :-)

avatar image Dino ♦♦ Alex Koo ♦♦   · Feb 28, 2018 at 09:47 PM 1
Link

This suggestion no longer works, because of new restrictions on the code that runs within a JavaScript callout. Instead you need to coerce the resulting value to a string, and then parse the string.

Example

var arr = context.getVariable('request.queryparam.qp1.values');
arr = arr + ''; //coerce the array to a string 
var parts = arr.slice(1,-1).map(function(x) { return x.trim(); });
context.setVariable('newName',parts[1]);

Your answer

Hint: You can notify a user about this post by typing @username

Up to 5 attachments (including images) can be used with a maximum of 5.0 MB each and 25.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to insert query parameters while converting soap to rest. 2 Answers

How to Parse a Query string Array Parameter using a SOAP proxy 2 Answers

call different target connections based on query param 2 Answers

How to use query parameter in dimension? 1 Answer

Remove All Query params from request 2 Answers

  • Products
    • Edge - APIs
    • Insights - Big Data
    • Plans
  • Developers
    • Overview
    • Documentation
  • Resources
    • Overview
    • Blog
    • Apigee Institute
    • Academy
    • Documentation
  • Company
    • Overview
    • Press
    • Customers
    • Partners
    • Team
    • Events
    • Careers
    • Contact Us
  • Support
    • Support Overview
    • Documentation
    • Status
    • Edge Support Portal
    • Privacy Policy
    • Terms & Conditions
© 2019 Apigee Corp. All rights reserved. - Apigee Community Terms of Use - Powered by AnswerHub
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Post an idea
  • Spaces
  • General
  • Edge/API Management
  • Developer Portal
  • API Design
  • APIM on Istio
  • Extensions
  • Business of APIs
  • Academy/Certification
  • Analytics
  • Events
  • Integration (AWS, PCF, Etc.)
  • Microgateway
  • Monetization
  • Private Cloud Deployment
  • Insights
  • IoT Apigee Link
  • BaaS/Usergrid
  • BaaS Transition/Migration
  • Apigee-127
  • New Customers
  • Explore
  • Topics
  • Questions
  • Articles
  • Ideas
  • Members
  • Badges