Trying to match on an inbound path pattern, not working?

Unable to bring status 404 for Raising a Fault if I enter an alphanumeric ID.

Take an Example:-

ID =c43c1e3f-94a8-49a8-98ba-af497f0be488

Lets say this is my API:

{{some_API}}/sampleTicket/c43c1e3f-94a8-49a8-98ba-af497f0be488

Now coming to the design of my Raise Fault Policy:

<RaiseFault name="Raise-Fault-InvalidID">
  <DisplayName>Raise Fault-InvalidID</DisplayName>
  <Properties/>
  <FaultResponse>
    <Set>
      <Headers>
        <Header name="Content-Type">application/json</Header>
      </Headers>
      <Payload contentType="application/json">
        { "errors":[
        {
        "code": "404",
        "userMessage": "This ID had never existed in the server",
        "systemMessage": "Not Found" }
        ]
        }
      </Payload>
      <StatusCode>404</StatusCode>
      <ReasonPhrase>Not Found</ReasonPhrase>
    </Set>
  </FaultResponse>
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</RaiseFault>

And this is how i write my condition on the flow of GetSampleTicketAPI:-

  <Flow name="GetSampleTicket">
    <Request>
      <Step>
        <Name>Assign_message_GetTroubleTicket</Name>
      </Step>
      <Step>
        <Name>Raise-Fault-InvalidID</Name>
        <Condition>(id=c43c1e3f-94a8-49a8-98ba-af497f0be488)</Condition>
      </Step>
      <Step>
        <Name>EV-JSONVariables</Name>
      </Step>
    </Request>
    <Response/>
    <Condition>(proxy.pathsuffix MatchesPath "/v3/SampleTicket/{ticketNumber") and (request.verb = "GET")
    </Condition>
  </Flow>

Please assist me where I could go wrong.I have highlighted some conditional flow statement.

It doesn't work for 404.

Thanks
Harkaran

0 1 62
1 REPLY 1

I have some feedback and suggestions.

1. The MatchesPath operator takes a path expression.

This is not a valid path expression:

"/v3/SampleTicket/{ticketNumber" 

I think maybe what you want to do there is extract the path segment and place it into a context variable "ticketNumber". That would be neat and handy, but that's not how Apigee Conditions work.

You need a Condition expression like this:

(proxy.pathsuffix MatchesPath "/v3/SampleTicket/*") and (request.verb = "GET")

Check the documentation for MatchesPath for more information and examples.

2. To get the actual value of the path segment, you need to use ExtractVariables policy.

<ExtractVariables name='EV-ExtractTicket'>
   <DisplayName>Extract a portion of the url path</DisplayName>
   <Source>request</Source>
   <VariablePrefix>extracted</VariablePrefix>
   <URIPath>
      <!-- the extracted value into extracted.id -->
      <Pattern ignoreCase='true'>/v3/SampleTicket/{ticketNumber}</Pattern>
   </URIPath>
   <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</ExtractVariables>

This will give you a context variable "extracted.ticketNumber". The policy must be placed in the request element of your flow.

  <Flow name="GetSampleTicket">
    <Request>
      <Step>
        <Name>EV-ExtractTicket</Name>
      </Step>
     ...
 

3. Your Condition elements must use quoted strings. This is invalid:

        <Condition>(id=c43c1e3f-94a8-49a8-98ba-af497f0be488)</Condition>

If you use the ExtractVariables policy I showed above, your condition should be like this:

        <Condition>extracted.ticketNumber="c43c1e3f-94a8-49a8-98ba-af497f0be488"</Condition>

4. I think it's a bit odd that you are special-casing a single ticket number within the API Proxy. But that's just my opinion.

Summing up, your flow should look like this:

  <Flow name="GetSampleTicket">
    <Request>
      <Step>
        <Name>EV-ExtractTicket</Name>
      </Step>
      <Step>
        <Name>Raise-Fault-InvalidID</Name>
        <Condition>extracted.tickwetNumber="c43c1e3f-94a8-49a8-98ba-af497f0be488"</Condition>
      </Step>
         ...
    </Request>
    <Response/>
    <Condition>(proxy.pathsuffix MatchesPath "/v3/SampleTicket/*") and (request.verb = "GET")
    </Condition>
  </Flow>


Good luck!