Creating Chained Requests

It is possible to configure Postman to Chain Multiple Requests together in order to "Pass" Values from an earlier response into the Body of another call.


Note




  1. Configure your collection
  2. Perform any functions required to be performed on every single call as part of the collection
  3. Collection Configuration Script
    //Demonstrate a function call to confirm that the response is a 200 Response/ Successful response.
    pm.test("Status code is 200", function () {
        pm.response.to.have.status(200);
    });
    
    //All responseses are required to  be converted to JSON in Order to be read, and Passed through as values.
    //This is perfermed on an individual call level, but outputting this as a JSON Response in your developer tools will help identify the correct required variable
    var responseJson = xml2Json(responseBody);
    console.log(responseJson);
  4. Configure your Login Procedure and assign Variables required

  5. Login "Tests" Code
    //In Order to refer to the JSON Response the Variable must be declared on a Local Request Level.
    var responseJson = xml2Json(responseBody);
    
    
    //Set a Global Variable for Session Information.
    //Variables can also be declared on a Environment & Collection level
        //pm.environment.set
        //pm.collection.set
    
    //pm.globals.set("variable_key", "variable_value")
            //variable_value == variable.path.element
            //variable == responseJson['s:Envelope']['s:Body']
            //path == LoginResponse.LoginResult
            //element == AccountID
    
    pm.globals.set("AccountID",responseJson['s:Envelope']['s:Body'].LoginResponse.LoginResult.AccountID); 
    pm.globals.set("DistributorID",responseJson['s:Envelope']['s:Body'].LoginResponse.LoginResult.DistributorID); 
    pm.globals.set("Expires",responseJson['s:Envelope']['s:Body'].LoginResponse.LoginResult.Expires); 
    pm.globals.set("Key",responseJson['s:Envelope']['s:Body'].LoginResponse.LoginResult.Key); 
    pm.globals.set("UserID",responseJson['s:Envelope']['s:Body'].LoginResponse.LoginResult.UserID);
  6. Subsequent calls can now use information from the response and output this into subsequent calls

    1. Find Location Body
      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cha="http://www.opensys.com.au/ChainIT/4.0/ChainITDataServices">
         <soapenv:Header/>
         <soapenv:Body>
            <cha:FindLocation>
       
               <cha:session>
                  <cha:AccountID>{{AccountID}}</cha:AccountID>
                  <!--Mandatory:-->
                  <cha:DistributorID>{{DistributorID}}</cha:DistributorID>
                  <!--Mandatory:-->
                  <cha:Expires>{{Expires}}</cha:Expires>
                  <!--Mandatory:-->
                  <cha:Key>{{Key}}</cha:Key>
                  <!--Mandatory:-->
                  <cha:UserID>{{UserID}}</cha:UserID>
                  <!--Mandatory:-->
               </cha:session>
       
               <cha:countryCode>AU</cha:countryCode>
               <!--Mandatory:-->
               <cha:searchValue>3131</cha:searchValue>
               <!--Mandatory:-->
      
            </cha:FindLocation>
          </soapenv:Body>
      </soapenv:Envelope>
      ConsignmentTrackingSearch Body
      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cha="http://www.opensys.com.au/ChainIT/4.0/ChainITDataServices">
         <soapenv:Header/>
         <soapenv:Body>
             <cha:ConsignmentTrackingSearch>
      
               <cha:session>
                  <cha:AccountID>{{AccountID}}</cha:AccountID>
                  <!--Mandatory:-->
                  <cha:DistributorID>{{DistributorID}}</cha:DistributorID>
                  <!--Mandatory:-->
                  <cha:Expires>{{Expires}}</cha:Expires>
                  <!--Mandatory:-->
                  <cha:Key>{{Key}}</cha:Key>
                  <!--Mandatory:-->
                  <cha:UserID>{{UserID}}</cha:UserID>
                  <!--Mandatory:-->
               </cha:session>
               
      
               <cha:consignmentDate>28/11/2017</cha:consignmentDate>
               <!--Mandatory:-->
      
            </cha:ConsignmentTrackingSearch>
          </soapenv:Body>
      </soapenv:Envelope>
      GetQuote3
      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cha="http://www.opensys.com.au/ChainIT/4.0/ChainITDataServices">
      	<soapenv:Header/>
      	<soapenv:Body>      
      		<cha:GetChargeQuote3>
      			<cha:session>
      				<cha:AccountID>{{AccountID}}</cha:AccountID>
      				<!--Mandatory:-->
      				<cha:DistributorID>{{DistributorID}}</cha:DistributorID>
      				<!--Mandatory:-->
      				<cha:Expires>{{Expires}}</cha:Expires>
      				<!--Mandatory:-->
      				<cha:Key>{{Key}}</cha:Key>
      				<!--Mandatory:-->
      				<cha:UserID>{{UserID}}</cha:UserID>
      				<!--Mandatory:-->
      			</cha:session>
      			<cha:shipperID>117810</cha:shipperID>
      			<cha:effectiveDate>2018-08-27</cha:effectiveDate>
      			<cha:senderLocation>VILLAWOOD</cha:senderLocation>
      			<cha:senderPostcode>2163</cha:senderPostcode>
      			<cha:senderCountryCode>AU</cha:senderCountryCode>
      			<cha:senderIsResidential>0</cha:senderIsResidential>
      			<cha:receiverAddress1>1 Warehouse Road</cha:receiverAddress1>
      			<cha:receiverAddress2/>
      			<cha:receiverLocation>MELBOURNE</cha:receiverLocation>
      			<cha:receiverPostcode>3000</cha:receiverPostcode>
      			<cha:receiverCountryCode>AU</cha:receiverCountryCode>
      			<cha:receiverIsResidential>0</cha:receiverIsResidential>
      			<cha:items>1</cha:items>
      			<cha:weight>5</cha:weight>
      			<cha:volume>0.01</cha:volume>
      			<cha:time>0</cha:time>
      			<cha:distance>0</cha:distance>
      			<cha:serviceList/>
      			<cha:containsDGs>0</cha:containsDGs>
      		</cha:GetChargeQuote3>
      	</soapenv:Body>
      </soapenv:Envelope>
  1. GetQuote3 Pull Cheapest Quote
    //In Order to refer to the JSON Response the Variable must be declared on a Local Reuest Level.
    var responseJson = xml2Json(responseBody);
    
    
    //Set a Global Variable for Session Information.
    //Variables can also be declared on a Environment & Collection level
    //pm.environment.set
    //pm.collection.set
    //pm.globals.set("variable_key", "variable_value")
    
    //variable_value == variable.path.element
    //variable == responseJson['s:Envelope']['s:Body']
    //path == LoginResponse.LoginResult
    //element == AccountID
    postman.setGlobalVariable("CheapestCost", responseJson['s:Envelope']['s:Body'].GetChargeQuote3Response.GetChargeQuote3Result.ServicePricing['0'].TotalCharge); 
    postman.setGlobalVariable("CheapestService", responseJson['s:Envelope']['s:Body'].GetChargeQuote3Response.GetChargeQuote3Result.ServicePricing['0'].ShipperService); 
    
    
  1. SaveConsignment w/ Cheapest Quote
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://www.opensys.com.au/ChainIT/4.0/ChainITDataServices">
       <soapenv:Header/>
       <soapenv:Body>
          <SaveConsignment>
     
             <session>
                <AccountID>{{AccountID}}</AccountID>
                <DistributorID>{{DistributorID}}</DistributorID>
                <Expires>{{Expires}}</Expires>
                <Key>{{Key}}</Key>
                <UserID>{{UserID}}</UserID>
             </session>
    
             <consignment>
                <AccountID>{{AccountID}}</AccountID>
    
                <CloseAt>18:00</CloseAt>
                <ConsignmentDate>2019-07-31</ConsignmentDate>
    					<ConsignmentItems>
                    	<ConsignmentItem>
                            <Description>Truck Parts for & O'Connor</Description>
                            <Height>10</Height>
                            <ItemNo>1</ItemNo>
                            <ItemType>CRT</ItemType>
                            <Length>15</Length>
                            <NoItems>5</NoItems>
                            <ProductID>0</ProductID>
                       
              
                            <Reference>CNHD2D</Reference>
                            <Volume>1.10</Volume>
                            <Weight>20</Weight>
                            <Width>20</Width>
            	     	</ConsignmentItem>
                	</ConsignmentItems>
    			<ConsolidatedSus>	                  
    			</ConsolidatedSus>
    
                <DeliveryInstructions>None</DeliveryInstructions>
                <Description>Description</Description>
                <DistributorID>{{DistributorID}}</DistributorID>
    
                <ReadyAt>12:00</ReadyAt>
    
                <Receiver>
                   <AddressLocation>
                      <Locality>Nunawading</Locality>
                      <State>VIC</State>
                      <Postcode>3131</Postcode>
                      <CountryCode>AU</CountryCode>
                   </AddressLocation>
                   <ContactName>Peter Test</ContactName>
                   <Email>test@email.com</Email>
                   <Line1>113 Rooks Rd</Line1>
                   <LocationDetails>
                      <Locality>Nunawading</Locality>
                      <State>VIC</State>
                      <Postcode>3131</Postcode>
                      <CountryCode>AU</CountryCode>
                   </LocationDetails>
                   <Name>Steve</Name>
                   <Phone>0425814806</Phone>
                   <State>VIC</State>
                   <Suburb>Nunawading</Suburb>
                </Receiver>
               
                <Reference>Test</Reference>
                <References>
                   <!--Zero or more repetitions:-->
                   <Reference>
                      <ConsignmentReference>ConRefef1</ConsignmentReference>
                   </Reference>
                    <Reference>
                      <ConsignmentReference>ConsignRefee2</ConsignmentReference>
                   </Reference>
                </References>
                
                <Released>2019-08-02</Released>
                
                <Sender>
                   <AccountID>{{AccountID}}</AccountID>
                   <AddressLocation>
                      <Locality>Nunawading</Locality>
                      <State>VIC</State>
                      <Postcode>3131</Postcode>
                      <CountryCode>AU</CountryCode>
                   </AddressLocation>
                   <ContactName>Peter  & O"'"Connor</ContactName>
                   <Email>test@email.com</Email>
                   <Line1>113 Rooks Rd</Line1>
                   <LocationDetails>
                      <Locality>Nunawading</Locality>
                      <State>VIC</State>
                      <Postcode>3131</Postcode>
                      <CountryCode>AU</CountryCode>
                   </LocationDetails>
                   <Name>Steve</Name>
                   <Phone>0425814806</Phone>
                   <State>VIC</State>
                   <Suburb>Nunawading</Suburb>
                </Sender>
                
                
                <Service>{{CheapestService}}</Service>
                <SpecialInstructions>Deliver to the front door</SpecialInstructions>
             </consignment>
          </SaveConsignment>
       </soapenv:Body>
    </soapenv:Envelope>
  1. Store ConsignmentID
    //In Order to refer to the JSON Response the Variable must be declared on a Local Reuest Level.
    var responseJson = xml2Json(responseBody);
    
    
    //Set a Global Variable for Session Information.
    //Variables can also be declared on a Environment & Collection level
        //pm.environment.set
        //pm.collection.set
    //pm.globals.set("variable_key", "variable_value")
    
            //variable_value == variable.path.element
            //variable == responseJson['s:Envelope']['s:Body']
            //path == LoginResponse.LoginResult
            //element == AccountID
    postman.setGlobalVariable("ConsignmentID", responseJson['s:Envelope']['s:Body'].SaveConsignmentResponse.SaveConsignmentResult.ConsignmentID); 
  2. Generate Labels w/ ConID
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://www.opensys.com.au/ChainIT/4.0/ChainITDataServices">
       <soapenv:Header/>
       <soapenv:Body>
          <GenerateLabels>
             <session>
                <AccountID>{{AccountID}}</AccountID>
                <DistributorID>{{DistributorID}}</DistributorID>
                <Expires>{{Expires}}</Expires>
                <Key>{{Key}}</Key>
                <UserID>{{UserID}}</UserID>
             </session>
          
             <consignmentID>{{ConsignmentID}}</consignmentID>
          </GenerateLabels>
       </soapenv:Body>
    </soapenv:Envelope>