How to properly use queryparams and variables by extracting/assigning

Not applicable

Hi guys,

I'm new to Apigee, and I'm working on a travel-planning startup. We just got the permission to use Transavia's api, which is awesome but we have tried to get the right set-up several days now and ended nowhere.

We got a api with the following data:

.anyType">"anyType": {

  • .anyType.type">"type": "d1p1:RoutesResponse",
  • .anyType.Data">"Data": {.anyType.Data.Route">"Route": [
  • {
    • .anyType.Data.Route[0].Destination">"Destination": {
      • .anyType.Data.Route[0].Destination.AirportLink">"AirportLink": {
        • .anyType.Data.Route[0].Destination.AirportLink.nil">"nil": "true"

        },

      • .anyType.Data.Route[0].Destination.LocationCode">"LocationCode": "AMS"

      },

    • .anyType.Data.Route[0].Origin">"Origin": {
      • .anyType.Data.Route[0].Origin.AirportLink">"AirportLink": {
        • .anyType.Data.Route[0].Origin.AirportLink.nil">"nil": "true"

        },

      • .anyType.Data.Route[0].Origin.LocationCode">"LocationCode": "ACE"

      }

    },

  • this is an example of a Get request:

    GET /v2/routes?origin=ams&destination=bcn HTTP/1.1

    The things we have done now is adding an apikey, so we can load the whole script. And we have added a xml to json converter. Now we want to order all data by setting the rights settings.

    We want to fill in an origin and destination in IATA code (like ams) and then get the values that are aligned with that request. Instead of getting all the data and then sorting things out in Java.

    Could someone, please please please help us out?

    0 9 729
    9 REPLIES 9

    Hi Sando,

    I'm not quite clear on what you're asking. Are you asking how to build a client that parses JSON? OR are you asking how you might use Apigee Edge to build a proxy in front of Transavia's APIs and then transform the responses in the API Proxy? Or... something else?

    From the title of the post, it seems that you want to Extract variables... from the inbound querystring? That's pretty straightforward; it is described here.

    also - the code? you posted is sort of garbled. It looks like there's been a problem with the formatting of the paste. Is that JSON ? Not clear what to make of it.

    @sando , Welcome to Apigee Community.

    Please help us understand your query better, Above description is not very clear. Please answer queries below to understand better.

    • Are you building a proxy in Apigee & Have an issue ?
    • What do you mean "we tried to get the right set-up several days now and ended nowhere" ?
      • What exactly you are trying to setup ?
    • Where did you add the API key - "The things we have done now is adding an apikey" ?
    • "so we can load the whole script " - What do you mean whole script ?
    • "We got a api with the following data:" - Is it public API ? Can you post complete details ?
    • "And we have added a xml to json converter." Why are you converting xml to json ? I don't see any xml reference in above query.
    • Regarding "We want to fill in a origin and destination in IATA code (like ams) and then get the values that a aligned with that request."
      • What values ?
      • What request ?
      • Where are you filling orgin & destination ?

    What exactly you are trying to achieve with Transavia APIs ?

    Not applicable

    Wow, that's fast! Thank you both. Sorry, I'll try make myself more clear.

    In the picture below, is the json code we are able to retrieve now from the api of transavia.

    3627-code.png

    I'm working with someone who is a really good front end developper, but using api's is new for us. To practise our skills we want to be able search through the variables 'origin and destination' fromout the frontend. Instead of collecting all the data from the picture we want to have it sorted before it comes in. Like saying in the front end give routes between amsterdam ('origin' with the iata code:AMS) and Paris ('destination' with the iata code PRS).


    • Are you building a proxy in Apigee & Have an issue ?

    Yes, we are building our own proxy.

    • What do you mean "we tried to get the right set-up several days now and ended nowhere" ?
      • What exactly you are trying to setup ?
      • **we tried to set-up the proxy with the goal which is stated above.
    • Where did you add the API key - "The things we have done now is adding an apikey"

    With the assign message policy. at the target end preflow.

    • "so we can load the whole script " - What do you mean whole script ?

    We were able to get all data in json, because of the API.

    • "We got a api with the following data:" - Is it public API ? Can you post complete details ?

    It's an open api, but you need a personal apikey. (

    https://developer.transavia.com/routes/apis/get/v2/routes)

    • "And we have added a xml to json converter." Why are you converting xml to json ? I don't see any xml reference in above query.
    • Regarding "We want to fill in a origin and destination in IATA code (like ams) and then get the values that a aligned with that request."
      • What values ?
      • What request ?
      • Where are you filling orgin & destination ?
      • *** this is the problem, we don't now all these questions.

    What exactly you are trying to achieve with Transavia APIs ?

    see statement above

    In short we want to retrieve data which is relevant, instead of retrieving all data and then sorting it on our own host.

    If I'm still not clear enough, please let me know. You already made our day by giving a reply this fast!

    @sando , What I understand from above, you are trying to retrieve part of the response from original API response. For that reason, you have built a proxy in Apigee Edge.

    Can you please post,

    • Can you please share Orginal Request you are sending / Response you are getting from transavia ?
    • Request / Response that you ideally want from proxy you are building ?

    Not applicable

    hi @Anil Sagar surely true!

    The response i'm sending now is just a request with a api key as an asigned message. The response I'm getting is the whole script in the picture above.

    What would be ideal is that we would make a request with an url or something similiar that would only retrieve the data we ask. Like if we ask for data of AMS routes, that we only get AMS routes not the whole database. So maybe we have to define the variables; origin & destination for that.

    Not sure how i can explain it any better, do you get what I'm saying?

    Thanks so much already!

    @sando , Would you like to filter the data by origin & destination codes in the proxy instead of full response ? Original API does support that , See sample CURL below, Update API key in below curl call to use it,

    curl -X GET -H "apikey: XXXXXXXXX" "https://api.transavia.com/v2/routes?origin=AMS&destination=BCN" -k
    <br>

    3647-screen-shot-2016-10-03-at-30057-pm.png

    @sando ,

    If you mean why your proxy doesn't filter the data,

    Reason is you have AssignMessage Policy where you are stripping query params in Target PreFlow. So, Query Params is not sent to target & you are receiving the full response.

    3648-helmsando-apigee.png

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-1">
        <DisplayName>Assign Message-1</DisplayName>
        <Properties/>
        <Copy source="request">
            <Headers/>
            <QueryParams/>
            <FormParams/>
            <Payload/>
            <Verb/>
            <StatusCode/>
            <ReasonPhrase/>
            <Path/>
        </Copy>
        <Remove>
            <Headers>
                <Header name="h1"/>
            </Headers>
            <QueryParams>
                <QueryParam name="destination">destination</QueryParam>
                <QueryParam name="origin">origin</QueryParam>
            </QueryParams>
            <FormParams>
                <FormParam name="f1"/>
            </FormParams>
            <Payload/>
        </Remove>
        <Add>
            <Headers/>
            <QueryParams/>
            <FormParams/>
        </Add>
        <Set>
            <Headers/>
            <QueryParams/>
            <FormParams/>
            <!-- <Verb>GET</Verb> -->
            <Path/>
        </Set>
        <AssignVariable>
            <Name>name</Name>
            <Value/>
            <Ref/>
        </AssignVariable>
        <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
        <AssignTo createNew="false" transport="http" type="request"/>
    </AssignMessage>
    

    I have removed above assign message policy, You can now see the filtered response. Check API here. Hope it helps.

    @Anil Sagar

    Thank you so much for your help! Some things have come between,

    I'll discuss it with my collegeas this week. Although this seems to be the right outcome in my eyes, great!

    @sando , Glad issue is resolved. Also, If you think your query has been answered please click on Accept link below answer. Please use comments for feedback. Answers are strictly for answers.