# TrustedRequest for bamboo REST call returns 401 error code

**URL:** <https://community.developer.atlassian.com/t/trustedrequest-for-bamboo-rest-call-returns-401-error-code/39287>\
**Category:** Bamboo Development\
**Tags:** bamboo, rest-api\
**Created:** [June 19, 2020, 5:37pm UTC](https://community.developer.atlassian.com/t/trustedrequest-for-bamboo-rest-call-returns-401-error-code/39287 "2020-06-19T17:37:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnilKumar](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@AnilKumar](https://community.developer.atlassian.com/u/AnilKumar)\
**Post date:** [June 19, 2020, 5:37pm UTC](https://community.developer.atlassian.com/t/trustedrequest-for-bamboo-rest-call-returns-401-error-code/39287/1 "2020-06-19T17:37:23Z")

</div>

I am trying to execute a bamboo REST call to clone a plan via TrustedRequest for a bamboo plugin, but I get 401 status code.

Is TrustedRequest not supported by Bamboo ?

Following is the code I am working with

```auto
final String baseUrl = applicationProperties.getBaseUrl(UrlMode.CANONICAL) ;
     final String url = baseUrl+
           "/rest/api/latest/clone/"+"P1-PLAN1:P1CLONE-PLAN1";

     String hostString = "localhost";
     try {
        URL hostUrl = new URL(baseUrl);
        hostString = hostUrl.getHost();
     } catch (MalformedURLException e) {
        LOG.error("Error trying to get host from the base url.\n\n" + e);
     }

     try {
        //here requestFactory is referencing the instance of com.atlassian.sal.bamboo.trusted.BambooHttpClientTrustedRequestFactory@7cb03893
        //and request is referencing the instance of com.atlassian.sal.core.net.HttpClientTrustedRequest@271a6774
        TrustedRequest request =
           requestFactory.createTrustedRequest(MethodType.PUT, url);
        // add machine name
        request.addTrustedTokenAuthentication(hostString);

        request.execute(new ResponseHandler<Response>() {

           @Override
           public void handle(
              final Response response) throws ResponseException {
              if (response.getStatusCode() != HttpStatus.SC_OK) {
                 LOG.info("REST call " + url + " response text - " +
                       response.getResponseBodyAsString());
              }
           }
        });
     } catch (ResponseException e) {
        LOG.error("Exception calling bamboo plan clone REST API:", e);
     }

```

The response body text I receive is

```auto
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<status>
  <status-code>401</status-code>
         <message>Client must be authenticated to access this resource.
         </message>
  </status>"

```

I am using Atlassian SDK 6.2.14 with AMPS version 6.2.11. The bamboo version I am working with is 6.5.1
