How to use response body as a request body for next call

Hi everybody,
How can I use first call’s response body in my next endpoint as a request body(raw)?
I have set first call’s response body in my environment, after which I have no idea how can I get and use it as a request body in my next endpoint.
Thanks in advance.

@bpricilla please help :slight_smile:

could anyone help me, please?

Simply put {{signResponse}} in the raw body (of JSON type) of the next request:

Hi,
thanks for your reply.
It doesn’t work, because next request body should be raw(xml).
I have done JSON.parse then have converted from json to xml, but again doesn’t work.


request body should be like this

Put the converted signResponse to XML value into a local variable, then specify this new local variable into the raw (XML) body.

Pre-request Script:

// get the signResponse environment variable value initialized
// in a previous request and convert the string to a json object
let inputJSON = JSON.parse(pm.environment.get('signResponse'));
// convert the json object into a XML string
let output = OBJtoXML(inputJSON);
// set the XML string into the signResponseXML local variable
pm.variables.set('signResponseXML', output);

Body raw (XML):

{{signResponseXML}}

Thanks @jfbriere your promt response. I have tried it, but get an error - wrong xml.
I think the problem is in the convert function. After converting to XML I don’t have proper structure. Let me show result of converting:

<MortgageRequest><RequestReference><RefNum>999995578</RefNum><OperationDate>13/12/2021 12:12:12</OperationDate></RequestReference><Loans><LoanContract><ContractNumber>61</ContractNumber><ContractDate>13/12/2021</ContractDate><MonthInfo><InterestPaymentDate>04/07/2020</InterestPaymentDate><InterestPaymentValue>123.03</InterestPaymentValue><InterestPaid>0000000000.00</InterestPaid></MonthInfo><MonthInfo><InterestPaymentDate>05/07/2020</InterestPaymentDate><InterestPaymentValue>123.45</InterestPaymentValue><InterestPaid>0.0</InterestPaid></MonthInfo><MonthInfo><InterestPaymentDate>06/07/2020</InterestPaymentDate><InterestPaymentValue>123.45</InterestPaymentValue><InterestPaid>0.0</InterestPaid></MonthInfo><QuarterInfo><PaymentYear>2018</PaymentYear><PaymentQuarter>1</PaymentQuarter><QuarterPaidInterest>8.00</QuarterPaidInterest></QuarterInfo><Borrower><ssn>3808970359</ssn><tin>00651800</tin><FirstName>Հայկ</FirstName><LastName>Սարհատյան</LastName></Borrower><Co_Borrowers><Co_Borrower><ssn>3808970359</ssn><tin>00651800</tin><FirstName>Հայկ</FirstName><LastName>Սարհատյան</LastName></Co_Borrower><Co_Borrower><ssn>3808970359</ssn><tin>00651800</tin><FirstName>Հայկ</FirstName><LastName>Սարհատյան</LastName></Co_Borrower></Co_Borrowers></LoanContract><LoanContract><ContractNumber>61</ContractNumber><ContractDate>13/12/2021</ContractDate><MonthInfo><InterestPaymentDate>04/07/2020</InterestPaymentDate><InterestPaymentValue>123.03</InterestPaymentValue><InterestPaid>0000000000.00</InterestPaid></MonthInfo><MonthInfo><InterestPaymentDate>05/07/2020</InterestPaymentDate><InterestPaymentValue>123.45</InterestPaymentValue><InterestPaid>0.0</InterestPaid></MonthInfo><MonthInfo><InterestPaymentDate>06/07/2020</InterestPaymentDate><InterestPaymentValue>123.45</InterestPaymentValue><InterestPaid>0.0</InterestPaid></MonthInfo><QuarterInfo><PaymentYear>2018</PaymentYear><PaymentQuarter>1</PaymentQuarter><QuarterPaidInterest>8.00</QuarterPaidInterest></QuarterInfo><Borrower><ssn>3808970359</ssn><tin>00651800</tin><FirstName>Հայկ</FirstName><LastName>Սարհատյան</LastName></Borrower><Co_Borrowers><Co_Borrower><ssn>3808970359</ssn><tin>00651800</tin><FirstName>Հայկ</FirstName><LastName>Սարհատյան</LastName></Co_Borrower><Co_Borrower><ssn>3808970359</ssn><tin>00651800</tin><FirstName>Հայկ</FirstName><LastName>Սարհատյան</LastName></Co_Borrower></Co_Borrowers></LoanContract><LoanContract><ContractNumber>61</ContractNumber><ContractDate>13/12/2021</ContractDate><MonthInfo><InterestPaymentDate>04/07/2020</InterestPaymentDate><InterestPaymentValue>123.03</InterestPaymentValue><InterestPaid>0000000000.00</InterestPaid></MonthInfo><MonthInfo><InterestPaymentDate>05/07/2020</InterestPaymentDate><InterestPaymentValue>123.45</InterestPaymentValue><InterestPaid>0.0</InterestPaid></MonthInfo><MonthInfo><InterestPaymentDate>06/07/2020</InterestPaymentDate><InterestPaymentValue>123.45</InterestPaymentValue><InterestPaid>0.0</InterestPaid></MonthInfo><QuarterInfo><PaymentYear>2018</PaymentYear><PaymentQuarter>1</PaymentQuarter><QuarterPaidInterest>8.00</QuarterPaidInterest></QuarterInfo><Borrower><ssn>3808970359</ssn><tin>00651800</tin><FirstName>Հայկ</FirstName><LastName>Սարհատյան</LastName></Borrower><Co_Borrowers><Co_Borrower><ssn>3808970359</ssn><tin>00651800</tin><FirstName>Հայկ</FirstName><LastName>Սարհատյան</LastName></Co_Borrower><Co_Borrower><ssn>3808970359</ssn><tin>00651800</tin><FirstName>Հայկ</FirstName><LastName>Սարհատյան</LastName></Co_Borrower></Co_Borrowers></LoanContract><LoanContract><ContractNumber>61</ContractNumber><ContractDate>13/12/2021</ContractDate><MonthInfo><InterestPaymentDate>04/07/2020</InterestPaymentDate><InterestPaymentValue>123.03</InterestPaymentValue><InterestPaid>0000000000.00</InterestPaid></MonthInfo><MonthInfo><InterestPaymentDate>05/07/2020</InterestPaymentDate><InterestPaymentValue>123.45</InterestPaymentValue><InterestPaid>0.0</InterestPaid></MonthInfo><MonthInfo><InterestPaymentDate>06/07/2020</InterestPaymentDate><InterestPaymentValue>123.45</InterestPaymentValue><InterestPaid>0.0</InterestPaid></MonthInfo><QuarterInfo><PaymentYear>2018</PaymentYear><PaymentQuarter>1</PaymentQuarter><QuarterPaidInterest>8.00</QuarterPaidInterest></QuarterInfo><Borrower><ssn>3808970359</ssn><tin>00651800</tin><FirstName>Հայկ</FirstName><LastName>Սարհատյան</LastName></Borrower><Co_Borrowers><Co_Borrower><ssn>3808970359</ssn><tin>00651800</tin><FirstName>Հայկ</FirstName><LastName>Սարհատյան</LastName></Co_Borrower><Co_Borrower><ssn>3808970359</ssn><tin>00651800</tin><FirstName>Հայկ</FirstName><LastName>Սարհատյան</LastName></Co_Borrower></Co_Borrowers></LoanContract><LoanContract><ContractNumber>61</ContractNumber><ContractDate>13/12/2021</ContractDate><MonthInfo><InterestPaymentDate>04/07/2020</InterestPaymentDate><InterestPaymentValue>123.03</InterestPaymentValue><InterestPaid>0000000000.00</InterestPaid></MonthInfo><MonthInfo><InterestPaymentDate>05/07/2020</InterestPaymentDate><InterestPaymentValue>123.45</InterestPaymentValue><InterestPaid>0.0</InterestPaid></MonthInfo><MonthInfo><InterestPaymentDate>06/07/2020</InterestPaymentDate><InterestPaymentValue>123.45</InterestPaymentValue><InterestPaid>0.0</InterestPaid></MonthInfo><QuarterInfo><PaymentYear>2018</PaymentYear><PaymentQuarter>1</PaymentQuarter><QuarterPaidInterest>8.00</QuarterPaidInterest></QuarterInfo><Borrower><ssn>3808970359</ssn><tin>00651800</tin><FirstName>Հայկ</FirstName><LastName>Սարհատյան</LastName></Borrower><Co_Borrowers><Co_Borrower><ssn>3808970359</ssn><tin>00651800</tin><FirstName>Հայկ</FirstName><LastName>Սարհատյան</LastName></Co_Borrower><Co_Borrower><ssn>3808970359</ssn><tin>00651800</tin><FirstName>Հայկ</FirstName><LastName>Սարհատյան</LastName></Co_Borrower></Co_Borrowers></LoanContract></Loans><Signature><$><xmlns>http://www.w3.org/2000/09/xmldsig#</xmlns></$><SignedInfo><CanonicalizationMethod><$><Algorithm>http://www.w3.org/TR/2001/REC-xml-c14n-20010315</Algorithm></$></CanonicalizationMethod><SignatureMethod><$><Algorithm>http://www.w3.org/2001/04/xmldsig-more#rsa-sha512</Algorithm></$></SignatureMethod><Reference><$><URI></URI></$><Transforms><Transform><$><Algorithm>http://www.w3.org/2000/09/xmldsig#enveloped-signature</Algorithm></$></Transform></Transforms><DigestMethod><$><Algorithm>http://www.w3.org/2001/04/xmlenc#sha512</Algorithm></$></DigestMethod><DigestValue>5KUQzVj4rI0Q+ZY2myn4EQQozIkM6OgyGtsr63rZiZNPf8Ug1XEY/vOSXGDR5Xu0SK26W3FeS5Ip9/IPaUyWVQ==</DigestValue></Reference></SignedInfo><SignatureValue>P9HsIyNgzCRyaCtkL8yRgWbC0TlJC9e9X9cd3dU9WLMU3oYKyNzloRKkFZUfhW8y2vhxyje1DgBdGkBALuRufn6ULlz+Mbzrav4GCpDJoxkMTvGcUp+9QgXKIY7xzLmy+2TiYFZs4RkruNAxKdVfMBl93hoWgXjNUUEn5oAbeWXg90WIkZyHvITbpGnSBjYkPHFjei6JAmUM3KJniEX1z1jdXZtX3od+7qpqvvwdSqyBS61kPVU+chOrTwL9n8WYnyX78gLtUGiQy8b3fW+d8R9eKhQQbcXrSkgqucuoqB22/BBWNtvmLJVPxV0GCqizGfsoZwAH3b2KHgvi9WDcOA==</SignatureValue><KeyInfo><KeyValue><RSAKeyValue><Modulus>pd0UTDf72nh0dBWlpqM8Aci1iwUgkmuvYmXgobxuF4tXVYENJzUU83E1L+TuHI6N1FtYY3ALhHTPHssklrS0b4rDvMxzDDi0KZQGZyge74q6jlkEgIFq/+ltHt9g4uTzuxsjHpmyW8rODNpmP6eMG9DL0+NXLDlN8sR6gDUC6XW1D5ri6PdsAedkXQ055X+gmA/PdOqxG3fXTDapVBBlsWxOhbb96nll3YOWQQz3jEoMsu5z/qPn6uNAiBechyzzyzNsdic3pJcNPsoB9j2CP/uOMWq40O3XsSArQULYaTt73dUaEN+kff+YIKZYObaPcN/ekK5tgj4F4jlNP/VFjQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue></KeyValue></KeyInfo></Signature></MortgageRequest>

request body raw should be like this:

<MortgageRequest>
  <RequestReference>
    <RefNum>999995578</RefNum>
    <OperationDate>13/12/2021 12:12:12</OperationDate>
  </RequestReference>
  <Loans>
    <LoanContract>
      <ContractNumber>61</ContractNumber>
      <ContractDate>13/12/2021</ContractDate>
      <MonthInfo>
		  <InterestPaymentDate>04/07/2020</InterestPaymentDate>
		  <InterestPaymentValue>123.03</InterestPaymentValue>
		  <InterestPaid>0000000000.00</InterestPaid>
	  </MonthInfo>
      <MonthInfo>
		  <InterestPaymentDate>05/07/2020</InterestPaymentDate>
		  <InterestPaymentValue>123.45</InterestPaymentValue>
		  <InterestPaid>0.0</InterestPaid>
	  </MonthInfo>
      <MonthInfo>
		  <InterestPaymentDate>06/07/2020</InterestPaymentDate>
		  <InterestPaymentValue>123.45</InterestPaymentValue>
		  <InterestPaid>0.0</InterestPaid>
	  </MonthInfo>
      <QuarterInfo>
        <PaymentYear>2018</PaymentYear>
        <PaymentQuarter>1</PaymentQuarter>
        <QuarterPaidInterest>8.00</QuarterPaidInterest>
      </QuarterInfo>
      <Borrower>
        <ssn>3808970359</ssn>
        <tin>00651800</tin>
          <FirstName>Հայկ</FirstName>
          <LastName>Սարհատյան</LastName>
      </Borrower>
      <Co_Borrowers>
        <Co_Borrower>
          <ssn>3808970359</ssn>
          <tin>00651800</tin>
          <FirstName>Հայկ</FirstName>
          <LastName>Սարհատյան</LastName>
        </Co_Borrower>
        <Co_Borrower>
          <ssn>3808970359</ssn>
          <tin>00651800</tin>
          <FirstName>Հայկ</FirstName>
          <LastName>Սարհատյան</LastName>
        </Co_Borrower>
      </Co_Borrowers>
    </LoanContract>
    <LoanContract>
      <ContractNumber>61</ContractNumber>
      <ContractDate>13/12/2021</ContractDate>
      <MonthInfo>
		  <InterestPaymentDate>04/07/2020</InterestPaymentDate>
		  <InterestPaymentValue>123.03</InterestPaymentValue>
		  <InterestPaid>0000000000.00</InterestPaid>
	  </MonthInfo>
      <MonthInfo>
		  <InterestPaymentDate>05/07/2020</InterestPaymentDate>
		  <InterestPaymentValue>123.45</InterestPaymentValue>
		  <InterestPaid>0.0</InterestPaid>
	  </MonthInfo>
      <MonthInfo>
		  <InterestPaymentDate>06/07/2020</InterestPaymentDate>
		  <InterestPaymentValue>123.45</InterestPaymentValue>
		  <InterestPaid>0.0</InterestPaid>
	  </MonthInfo>
      <QuarterInfo>
        <PaymentYear>2018</PaymentYear>
        <PaymentQuarter>1</PaymentQuarter>
        <QuarterPaidInterest>8.00</QuarterPaidInterest>
      </QuarterInfo>
      <Borrower>
        <ssn>3808970359</ssn>
        <tin>00651800</tin>
          <FirstName>Հայկ</FirstName>
          <LastName>Սարհատյան</LastName>
      </Borrower>
      <Co_Borrowers>
        <Co_Borrower>
          <ssn>3808970359</ssn>
          <tin>00651800</tin>
          <FirstName>Հայկ</FirstName>
          <LastName>Սարհատյան</LastName>
        </Co_Borrower>
        <Co_Borrower>
          <ssn>3808970359</ssn>
          <tin>00651800</tin>
          <FirstName>Հայկ</FirstName>
          <LastName>Սարհատյան</LastName>
        </Co_Borrower>
      </Co_Borrowers>
    </LoanContract>
    <LoanContract>
      <ContractNumber>61</ContractNumber>
      <ContractDate>13/12/2021</ContractDate>
      <MonthInfo>
		  <InterestPaymentDate>04/07/2020</InterestPaymentDate>
		  <InterestPaymentValue>123.03</InterestPaymentValue>
		  <InterestPaid>0000000000.00</InterestPaid>
	  </MonthInfo>
      <MonthInfo>
		  <InterestPaymentDate>05/07/2020</InterestPaymentDate>
		  <InterestPaymentValue>123.45</InterestPaymentValue>
		  <InterestPaid>0.0</InterestPaid>
	  </MonthInfo>
      <MonthInfo>
		  <InterestPaymentDate>06/07/2020</InterestPaymentDate>
		  <InterestPaymentValue>123.45</InterestPaymentValue>
		  <InterestPaid>0.0</InterestPaid>
	  </MonthInfo>
      <QuarterInfo>
        <PaymentYear>2018</PaymentYear>
        <PaymentQuarter>1</PaymentQuarter>
        <QuarterPaidInterest>8.00</QuarterPaidInterest>
      </QuarterInfo>
      <Borrower>
        <ssn>3808970359</ssn>
        <tin>00651800</tin>
          <FirstName>Հայկ</FirstName>
          <LastName>Սարհատյան</LastName>
      </Borrower>
      <Co_Borrowers>
        <Co_Borrower>
          <ssn>3808970359</ssn>
          <tin>00651800</tin>
          <FirstName>Հայկ</FirstName>
          <LastName>Սարհատյան</LastName>
        </Co_Borrower>
        <Co_Borrower>
          <ssn>3808970359</ssn>
          <tin>00651800</tin>
          <FirstName>Հայկ</FirstName>
          <LastName>Սարհատյան</LastName>
        </Co_Borrower>
      </Co_Borrowers>
    </LoanContract>
    <LoanContract>
      <ContractNumber>61</ContractNumber>
      <ContractDate>13/12/2021</ContractDate>
      <MonthInfo>
		  <InterestPaymentDate>04/07/2020</InterestPaymentDate>
		  <InterestPaymentValue>123.03</InterestPaymentValue>
		  <InterestPaid>0000000000.00</InterestPaid>
	  </MonthInfo>
      <MonthInfo>
		  <InterestPaymentDate>05/07/2020</InterestPaymentDate>
		  <InterestPaymentValue>123.45</InterestPaymentValue>
		  <InterestPaid>0.0</InterestPaid>
	  </MonthInfo>
      <MonthInfo>
		  <InterestPaymentDate>06/07/2020</InterestPaymentDate>
		  <InterestPaymentValue>123.45</InterestPaymentValue>
		  <InterestPaid>0.0</InterestPaid>
	  </MonthInfo>
      <QuarterInfo>
        <PaymentYear>2018</PaymentYear>
        <PaymentQuarter>1</PaymentQuarter>
        <QuarterPaidInterest>8.00</QuarterPaidInterest>
      </QuarterInfo>
      <Borrower>
        <ssn>3808970359</ssn>
        <tin>00651800</tin>
          <FirstName>Հայկ</FirstName>
          <LastName>Սարհատյան</LastName>
      </Borrower>
      <Co_Borrowers>
        <Co_Borrower>
          <ssn>3808970359</ssn>
          <tin>00651800</tin>
          <FirstName>Հայկ</FirstName>
          <LastName>Սարհատյան</LastName>
        </Co_Borrower>
        <Co_Borrower>
          <ssn>3808970359</ssn>
          <tin>00651800</tin>
          <FirstName>Հայկ</FirstName>
          <LastName>Սարհատյան</LastName>
        </Co_Borrower>
      </Co_Borrowers>
    </LoanContract>
    <LoanContract>
      <ContractNumber>61</ContractNumber>
      <ContractDate>13/12/2021</ContractDate>
      <MonthInfo>
		  <InterestPaymentDate>04/07/2020</InterestPaymentDate>
		  <InterestPaymentValue>123.03</InterestPaymentValue>
		  <InterestPaid>0000000000.00</InterestPaid>
	  </MonthInfo>
      <MonthInfo>
		  <InterestPaymentDate>05/07/2020</InterestPaymentDate>
		  <InterestPaymentValue>123.45</InterestPaymentValue>
		  <InterestPaid>0.0</InterestPaid>
	  </MonthInfo>
      <MonthInfo>
		  <InterestPaymentDate>06/07/2020</InterestPaymentDate>
		  <InterestPaymentValue>123.45</InterestPaymentValue>
		  <InterestPaid>0.0</InterestPaid>
	  </MonthInfo>
      <QuarterInfo>
        <PaymentYear>2018</PaymentYear>
        <PaymentQuarter>1</PaymentQuarter>
        <QuarterPaidInterest>8.00</QuarterPaidInterest>
      </QuarterInfo>
      <Borrower>
        <ssn>3808970359</ssn>
        <tin>00651800</tin>
          <FirstName>Հայկ</FirstName>
          <LastName>Սարհատյան</LastName>
      </Borrower>
      <Co_Borrowers>
        <Co_Borrower>
          <ssn>3808970359</ssn>
          <tin>00651800</tin>
          <FirstName>Հայկ</FirstName>
          <LastName>Սարհատյան</LastName>
        </Co_Borrower>
        <Co_Borrower>
          <ssn>3808970359</ssn>
          <tin>00651800</tin>
          <FirstName>Հայկ</FirstName>
          <LastName>Սարհատյան</LastName>
        </Co_Borrower>
      </Co_Borrowers>
    </LoanContract>
  </Loans>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/><SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha512"/><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/></Transforms><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha512"/><DigestValue>5KUQzVj4rI0Q+ZY2myn4EQQozIkM6OgyGtsr63rZiZNPf8Ug1XEY/vOSXGDR5Xu0SK26W3FeS5Ip9/IPaUyWVQ==</DigestValue></Reference></SignedInfo><SignatureValue>P9HsIyNgzCRyaCtkL8yRgWbC0TlJC9e9X9cd3dU9WLMU3oYKyNzloRKkFZUfhW8y2vhxyje1DgBdGkBALuRufn6ULlz+Mbzrav4GCpDJoxkMTvGcUp+9QgXKIY7xzLmy+2TiYFZs4RkruNAxKdVfMBl93hoWgXjNUUEn5oAbeWXg90WIkZyHvITbpGnSBjYkPHFjei6JAmUM3KJniEX1z1jdXZtX3od+7qpqvvwdSqyBS61kPVU+chOrTwL9n8WYnyX78gLtUGiQy8b3fW+d8R9eKhQQbcXrSkgqucuoqB22/BBWNtvmLJVPxV0GCqizGfsoZwAH3b2KHgvi9WDcOA==</SignatureValue><KeyInfo><KeyValue><RSAKeyValue><Modulus>pd0UTDf72nh0dBWlpqM8Aci1iwUgkmuvYmXgobxuF4tXVYENJzUU83E1L+TuHI6N1FtYY3ALhHTPHssklrS0b4rDvMxzDDi0KZQGZyge74q6jlkEgIFq/+ltHt9g4uTzuxsjHpmyW8rODNpmP6eMG9DL0+NXLDlN8sR6gDUC6XW1D5ri6PdsAedkXQ055X+gmA/PdOqxG3fXTDapVBBlsWxOhbb96nll3YOWQQz3jEoMsu5z/qPn6uNAiBechyzzyzNsdic3pJcNPsoB9j2CP/uOMWq40O3XsSArQULYaTt73dUaEN+kff+YIKZYObaPcN/ekK5tgj4F4jlNP/VFjQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue></KeyValue></KeyInfo></Signature></MortgageRequest>

What is the error, specifically?

I don’t think that this is a Postman error because the XML you provided is well constructed.

I think the error comes from your service.
The reason for the error is impossible for me to know, but it might be because your XML does not conform to the appropriate XML schema of your service.

Thank you @jfbriere .
Yes, is possible that the error comes from our service. I will check it.
Maybe after converting function need to write special function for getting appropriate XML schema? Is it possible?

Yes, you are right. The error comes from our service. Need to build appropriate XML schema then send. But I don’t know how?

Hey dear friends,
I want to say that I have found the soultion. It was very easy :slightly_smiling_face:.
First of all, there is no need to convert response from XML to JSON Object, consequently there is no need to do JSON.stringify before setting in environment.
Just set environment variable as it is

Tests:

if (pm.response.code == 200 ) {
pm.test("contract is signed successful", () => {
   pm.environment.set("signResponse", responseBody);

Then in the next request I have simply got the signResponse environment variable value initialized in a previous request

Pre-request Script:

let signedContract = pm.environment.get("signResponse");
pm.variables.set('signResponseXML', signedContract);

At the end I have used signResponseXML variable in my request body.

Body raw (XML):

{{signResponseXML}}

Many thanks @jfbriere , @bpricilla
I hope this can help someone else :slightly_smiling_face:.