Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Extract variable from Response Cookie using XML

I need to extract the SESSION id from the Set-Cookie. I want to use the XML method for variable extraction. This is the RAW text from the response that I need to extract the SESSION id:

HTTP/1.1 302 Found
Date: Mon, 04 Jun 2018 23:28:41 GMT
Content-Length: 0
Connection: close
Server: Apache-Coyote/1.1
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
X-Frame-Options: SAMEORIGIN
Set-Cookie: SESSION=28912d6b-4d75-42bf-8bc6-8f19f56cd7b0; Path=/linkos/; Secure; HttpOnly
Location: somewhere.com

This is the flow we are trying to produce:

/scantoprint (virtual proxy endpoint)

We need to collect 5 things, place them in the formData of the virtual endpoint:

  • {Username}
  • {Password}
  • {Printer SN}
  • {LabelCode}
  • {Data}
  1. After receiving this request
  2. Parse out all 5 into some session variables
  3. Use the Username and Password
  4. Place them in the body of the /{PPME_API_Access_proxy}/login
  5. Send the POST
  6. Retrieve the Response
  7. Capture the {Session id} from the cookie
  8. Add it to the API header
  9. Populate the FormData with {Data) and {LabelCode}
  10. Insert the printer {Printer SN} into the path of the second target /{PPME_API_Access_proxy}/devices/{Printer SN}/sendRawData
  11. Send the POST to print the barcode label.

Individually, using Postman, it works using our PPME proxy endpoints. We use both printer endpoints, and manually copy the session id from one cookie to the header of the other. However we need to be able to do this in APIGEE as a proof of concept

Solved Solved
1 7 2,755
1 ACCEPTED SOLUTION

Hi @Dino Gregorich

Welcome to the community !! I am assuming you are referring to the Extract Variable policy. If yes, then the policy code can be something like this

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Cookie">
    <DisplayName>Extract-Cookie</DisplayName>
    <Properties/>
    <Header name="Set-Cookie">
        <Pattern ignoreCase="false">SESSION={cookie};*</Pattern>
    </Header>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <Source clearPayload="false">response</Source>
    <VariablePrefix>respPrefix</VariablePrefix>
</ExtractVariables>

Once this is executed, the session ID should be available in a variable called "respPrefix.cookie"

Let me know if this works

View solution in original post

7 REPLIES 7