Restricting backend API methods / response transformation

Not applicable

Hi there,

I have a backend API with rich functionality and I want to create a proxied API with just a single call.

In my example, the backend offers a method "GET /user?email=foo@bar.org" which returns a full user object with all user data.

I want to have a single call "/userphone?email=foo@bar.org" in my proxied API which only returns the users phone number.

What I understood so far is, that I have to add a conditional flow "GET /userphone", but I currently do not have a clue how to:

- ensure, that the clients sends in a valid mail address (regex?)

- translate the /userphone to the corresponding call in the backend

- remove all data but the phone number from the backend answer

In addition, I want the proxied API to only acceppt this single method "GET /userphone" everything else should be answered by an 404-error or something similar.

Can someone gve me a basic example of how to do this?

Thanks,

Michael

1 2 244
2 REPLIES 2

@Michael Schramm , Regarding restricting unknown resources, take a look at similar article here in community.

@Michael Schramm ,

Great Questions, Please find answers inline,

I want to have a single call "/userphone?email=foo@bar.org" in my proxied API which only returns the users phone number.

  • Extract the data needed from response using " Extract Variables Policy". See sample policy that extracts from json response using json path.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables-1">
    <DisplayName>EV-ExtractCustom Attribute Phone Number</DisplayName>
    <Properties/>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <JSONPayload>
        <Variable name="phoneNumber">
            <JSONPath>$.custom_attributes.phone_number</JSONPath>
        </Variable>
    </JSONPayload>
    <Source clearPayload="false">response</Source>
    <VariablePrefix>intercom</VariablePrefix>
</ExtractVariables>
  • Use Assign Message Policy to construct new response, See sample below,
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-1">
    <DisplayName>AM-UpdateGetUserByEmailResponse</DisplayName>
    <Properties/>
    <Set>
        <Payload contentType="application/json" variablePrefix="@" variableSuffix="#">
        {"phone":"@intercom.phoneNumber#"}
    </Payload>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</AssignMessage>

How to ensure, that the clients sends in a valid mail address (regex?) ?


How to translate the /userphone to the corresponding call in the backend ?


  • See similar article here that explains how to remove path suffix being forwarded to target.
  • See similar question here that explains how to change path between proxy & target endpoints.

How to remove all data but the phone number from the backend answer ?

  • Answered above, Use Extract Variable Policy & Assign Message Policy.

In addition, I want the proxied API to only accept this single method "GET /userphone" everything else should be answered by an 404-error or something similar. ?

  • Take a look at article here in community that explains same.

Hope it helps. Keep us posted if any.