How can i call same target endpoint from different flows

How can i call same target end point from different flows. When i am calling with /ticker , It ok but when calling with /global, showing me below error.

Please help

{
    "fault": {
        "faultstring": "Invalid access token",
        "detail": {
            "errorcode": "oauth.v2.InvalidAccessToken"
        }
    }
}

Sample code below

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
    <Description/>
    <FaultRules/>
    <PreFlow name="PreFlow">
        <Request/>
        <Response/>
    </PreFlow>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <Flows/>
    <HTTPTargetConnection>
        <Properties/>
        <URL>https://api.xxxxxxxxxx.com/v1{targetpathsuffix}</URL>
    </HTTPTargetConnection>
</TargetEndpoint>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <Description/>
    <FaultRules/>
    <PreFlow name="PreFlow">
        <Request/>
        <Response/>
    </PreFlow>
    <PostFlow name="PostFlow">
        <Request>
            <Step>
                <Name>getendPoint</Name>
            </Step>
        </Request>
        <Response/>
    </PostFlow>
    <Flows>
        <Flow name="get /ticker/">
            <Description/>
            <Request/>
            <Response/>
            <Condition>(proxy.pathsuffix MatchesPath "/ticker/") and (request.verb = "GET")</Condition>
        </Flow>
        <Flow name="get /global/">
            <Description/>
            <Request/>
            <Response/>
            <Condition>(proxy.pathsuffix MatchesPath "/global/") and (request.verb = "GET")</Condition>
        </Flow>
    </Flows>
    <HTTPProxyConnection>
        <BasePath>/ticker</BasePath>
        <Properties/>
        <VirtualHost>secure</VirtualHost>
    </HTTPProxyConnection>
    <RouteRule name="default">
        <TargetEndpoint>default</TargetEndpoint>
    </RouteRule>
</ProxyEndpoint>		
Solved Solved
0 6 580
1 ACCEPTED SOLUTION

Not applicable

@Faij Ahmed , i have implemented a similar sampe in my local and it works as expected. Only difference i see is my "targetpathsuffix" variable is behind a "/" .

 <HTTPTargetConnection>
        <Properties/>
        <URL>http://XXXXXXX/{targetpath}</URL>
    </HTTPTargetConnection>

But otherwise , you can use "target.url" reference variable in the target flow and update your target endpoint. In our case , for a similar but a bit complex flow , we evaluate the target path in a Java script and assign it to the target.url variable in the target flow.

You can also refer to this article , which helps in building target url using variables

https://community.apigee.com/questions/33881/how-to-use-variables-in-target-endpoint-url.html

View solution in original post

6 REPLIES 6

@Faij Ahmad,

I don't see any issues with your ProxyEndpoint. It should be able to route the requests to the same target endpoint for all the flows.

However, the error that you are seeing Invalid access token indicates that you are passing an invalid access token to the API. So the VerifyAccessToken policy would be throwing this error. Can you please verify if the access token is valid ?

Thanks @AMAR DEVEGOWDA but there is not policy attached to any flows.

Not applicable

Hi @Faij Ahmad ... The code looks good as pointed out by Amar , and there is no reason for it to fail. Unless there are some restrictions on actual target. Can you validate if you are able to call both the endpoints from postman , without any security headers. And also can you share what does the policy "getendpoint" do. And also error suggests it has APIGEE OAuth policy some where , may be can you revalidate the code , if you are testing the proper revision.

I am appending "/" by to my target url using JavaScript Policy. Code is below

context.setVariable("targetpathsuffix", '/');

Not applicable

@Faij Ahmed , i have implemented a similar sampe in my local and it works as expected. Only difference i see is my "targetpathsuffix" variable is behind a "/" .

 <HTTPTargetConnection>
        <Properties/>
        <URL>http://XXXXXXX/{targetpath}</URL>
    </HTTPTargetConnection>

But otherwise , you can use "target.url" reference variable in the target flow and update your target endpoint. In our case , for a similar but a bit complex flow , we evaluate the target path in a Java script and assign it to the target.url variable in the target flow.

You can also refer to this article , which helps in building target url using variables

https://community.apigee.com/questions/33881/how-to-use-variables-in-target-endpoint-url.html

Thanks @Raghavendra Chamarthy for help. It working fine.