title: How to write generic function to set token and cookies received from one GET API to test other APIs using Rest Assured
body: <p>Below code is working for APIs written in one test but I want to use authentication in other test classes. Please help me with that I am using JAVA</p>
  <p>@Test(priority = 01, groups = { &quot;API&quot;, &quot;API Testing&quot; }, description = &quot;Validate &quot;)
  public void defaultAndSizeSolutionAPI() throws IOException {</p>
  <pre><code>    FileInputStream fis= new FileInputStream(new File(userDir +&quot;payload.json&quot;));
      
      //to get the csrf token and cookies
          Response response = RestAssured.given()
                      .headers(headers.defaultHeaders())
                      .get(&quot;https://c9w22348.itcs.hpe.com/Services/SizingEngine/Gettoken&quot;);
              
              Log.info(&quot; API Status Code : &quot;+ response.getStatusCode());
              Log.info(&quot;CSRF Token  : &quot;+ response.getHeader(&quot;AfToken&quot;));
              Log.info(&quot;Cookies  : &quot;+ response.getCookies()); 
              
      //To set csrf Token and cookies and get ezmeralSizer Default 
      
          RestAssured.given()
              .headers(headers.defaultHeaders())
              .header(&quot;CSRFToken&quot;, response.getHeader(&quot;AfToken&quot;))
              .cookies(response.getCookies())
              
              
              //For Solution Api (Actual Test)
          Response solution= RestAssured.given()
                      .headers(headers.defaultHeaders())
                      .header(&quot;CSRFToken&quot;,response.getHeader(&quot;AfToken&quot;))
                      .cookies(response.getCookies())
                      .body(IOUtils.toString(fis, &quot;UTF-8&quot;))
                      .post(&quot;XXXXXXXXXXXXX/Endpoints&quot;);
               
                      Log.info(&quot;Solution API Status Code : &quot;+ solution= .getStatusCode());
                  Log.info(&quot;Solution response body : &quot;+ solution= .getBody().jsonPath().prettify());
                  softAssert.assertEquals(200, solution= .getStatusCode());
                  softAssert.assertAll();
                  
  }
  </code></pre>