---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# RequestAuthAPI - Scoped

# RequestAuthAPI - Scoped {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 minutes to read

The RequestAuthAPI provides methods to apply a signature to a REST request.  
Generate outbound signing requests using these APIs in the following order:

1. HttpRequestData: Build the API request.
2. AuthCredential: Create a credential object or update an existing one. Use the credential to sign the request through the RequestAuthAPI class.
3. RequestAuthAPI: Sign the request and return an HttpRequestAuthedData object.
4. HttpRequestAuthedData: Get information about the signed request.
5. GlideHTTPRequest: Send the signed request.
{#RequestAuthAPI__ol_gvv_22t_tjb}

Before using these APIs, you must [configure an authentication
algorithm](https://www.servicenow.com/docs/access?context=configure-authentication-algorithm&version=xanadu&pubname=xanadu-platform-security&ft:locale=en-US) to sign the request and associate it with the credential used to authenticate the request.

Use this API in scoped scripts with the `sn_auth` namespace identifier.

## RequestAuthAPI - RequestAuthAPI(Object data, Object credential) {#ariaid-title2}

Instantiates a RequestAuthAPI object using a REST request and a credential.
{#RequestAuthAPI-RequestAuthAPI_O_O__table_htv_rvv_5jb__entry__3}

| Name | Type | Description |
|-|-|-|
| data | Object | HttpRequestData object that contains the unsigned REST request. Use the HttpRequestData class to build this object. See [HttpRequestData API](https://servicenow-prod.fluidtopics.net/VOR3tVFum9FRbdrwJPPlaQ#HttpRequestDataAPI "The HttpRequestData API provides methods to build and manipulate a REST request before applying a signature and sending it to an endpoint."). |
| credential | Object | Object that represents a record from the Credentials \[discovery_credentials\] table. Retrieve this object using the AuthCredential class. See [AuthCredential API](https://servicenow-prod.fluidtopics.net/DskVGXUCP6WX5TD~Q_ekbA#AuthCredentialAPI "The AuthCredential() API provides methods that enable you to build credentials for a REST request."). |
[Table 1. Parameters]

{#RequestAuthAPI-RequestAuthAPI_O_O__table_htv_rvv_5jb}  

    // Define the HttpRequestData object
    var endpoint= "https://third-party-endpoint";
    var httpRequestData = new sn_auth.HttpRequestData();
    httpRequestData.setEndpoint(endpoint);
    httpRequestData.setService('s3');
    httpRequestData.setRegion('us-east-1');
    httpRequestData.setHttpMethod("PUT");
    var content = "Action=SendMessage&MessageBody=This is a test message";
    httpRequestData.setContent(content);
    httpRequestData.addHeader('x-amz-acl' , 'public-read' );
     
     // Get a credential record
    var credential = new sn_cc.StandardCredentialsProvider().getAuthCredentialByID("88772d0d40990010f8772fdd9ebc8075");
     
    // Instantiate a RequestAuthAPI object
    var signingAPI = new sn_auth.RequestAuthAPI(httpRequestData, credential);

## RequestAuthAPI - generateAuth() {#ariaid-title3}

Signs the HttpRequestData object and returns an HttpRequestAuthedData object to use to
send in the REST request.
{#RequestAuthAPI-generateAuth__table_uhw_sy4_5jb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 2. Parameters]

{#RequestAuthAPI-generateAuth__table_uhw_sy4_5jb} {#RequestAuthAPI-generateAuth__table_vhw_sy4_5jb__entry__2}

| Type | Description |
|-|-|
| HttpRequestAuthedData | Object. Data to use to obtain information about the signed result. Use the methods in the HttpRequestAuthedData class to interact with the signed result. See [HttpRequestAuthedData API](https://servicenow-prod.fluidtopics.net/7eXYOzGaSe7dJE5dnisatw#HttpRequestAuthedDataAPI "The HttpRequestAuthedData() API provides methods to access and set values in a signed REST or SOAP request."). |
[Table 3. Returns]

{#RequestAuthAPI-generateAuth__table_vhw_sy4_5jb}  
This example creates a request and gets a credential record to pass to the
RequestAuthAPI API. The generateAuth() method then
signs the request.

    // Define the HttpRequestData object
    var endpoint= "https://third-party-endpoint";
    var httpRequestData = new sn_auth.HttpRequestData();
    httpRequestData.setEndpoint(endpoint);
    httpRequestData.setService('s3');
    httpRequestData.setRegion('us-east-1');
    httpRequestData.setHttpMethod("PUT");
    var content = "Action=SendMessage&MessageBody=This is a test message";
    httpRequestData.setContent(content);
    httpRequestData.addHeader('x-amz-acl' , 'public-read' );
     
    // Get a credential record
    gs.info( "date:" + httpRequestData.getDate() );
    var credential = new sn_cc.StandardCredentialsProvider().getAuthCredentialByID("5b61c16f73533300f662cff8faf6a74b");
     
    // Create the RequestAuthAPI object and sign the request
    var signingAPI = new sn_auth.RequestAuthAPI(httpRequestData, credential);
    var output = signingAPI.generateAuth();
     
## RequestAuthAPI - getAuthCredential() {#ariaid-title4}

Returns the credential record used to sign the request.
{#RequestAuthAPI-getAuthCredential__table_pfm_ny4_5jb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 4. Parameters]

{#RequestAuthAPI-getAuthCredential__table_pfm_ny4_5jb} {#RequestAuthAPI-getAuthCredential__table_qfm_ny4_5jb__entry__2}

| Type | Description |
|-|-|
| AuthCredential | Object. Data to use to obtain information about the credential record used to sign the request. Use the methods in the AuthCredential class to interact with the credential. See [AuthCredential API](https://servicenow-prod.fluidtopics.net/DskVGXUCP6WX5TD~Q_ekbA#AuthCredentialAPI "The AuthCredential() API provides methods that enable you to build credentials for a REST request."). |
[Table 5. Returns]

{#RequestAuthAPI-getAuthCredential__table_qfm_ny4_5jb}  

    // Define the HttpRequestData object
    var endpoint= "https://third-party-endpoint";
    var httpRequestData = new sn_auth.HttpRequestData();
    httpRequestData.setEndpoint(endpoint);
    httpRequestData.setService('s3');
    httpRequestData.setRegion('us-east-1');
    httpRequestData.setHttpMethod("PUT");
    var content = "Action=SendMessage&MessageBody=This is a test message";
    httpRequestData.setContent(content);
    httpRequestData.addHeader('x-amz-acl' , 'public-read' );
     
    // Get a credential record
    var credential = new sn_cc.StandardCredentialsProvider().getAuthCredentialByID("5b61c16f73533300f662cff8faf6a74b");
     
    // Return the AuthCredential object
    var signingAPI = new sn_auth.RequestAuthAPI(httpRequestData, credential);
    var signingCredential = signingAPI.getAuthCredential();

## RequestAuthAPI - getHttpRequestData() {#ariaid-title5}

Returns the HttpRequestData object that was used to instantiate the
RequestAuthAPI class.
{#RequestAuthAPI-getHttpRequestData__table_hp2_ly4_5jb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 6. Parameters]

{#RequestAuthAPI-getHttpRequestData__table_hp2_ly4_5jb} {#RequestAuthAPI-getHttpRequestData__table_ip2_ly4_5jb__entry__2}

| Type | Description |
|-|-|
| HttpRequestData | Object. Contains the unsigned REST request. Use the methods in the HttpRequestData class to interact with the request. See [HttpRequestData API](https://servicenow-prod.fluidtopics.net/VOR3tVFum9FRbdrwJPPlaQ#HttpRequestDataAPI "The HttpRequestData API provides methods to build and manipulate a REST request before applying a signature and sending it to an endpoint."). |
[Table 7. Returns]

{#RequestAuthAPI-getHttpRequestData__table_ip2_ly4_5jb}  

    // Define the HttpRequestData object
    var endpoint= "https://third-party-endpoint";
    var httpRequestData = new sn_auth.HttpRequestData();
    httpRequestData.setEndpoint(endpoint);
    httpRequestData.setService('s3');
    httpRequestData.setRegion('us-east-1');
    httpRequestData.setHttpMethod("PUT");
    var content = "Action=SendMessage&MessageBody=This is a test message";
    httpRequestData.setContent(content);
    httpRequestData.addHeader('x-amz-acl' , 'public-read' );
     
     // Get a credential record
    var credential = new sn_cc.StandardCredentialsProvider().getAuthCredentialByID("88772d0d40990010f8772fdd9ebc8075");
     
    // Return the HttpRequestData object
    var signingAPI = new sn_auth.RequestAuthAPI(httpRequestData, credential);
    var unsignedRequest = signingAPI.getHttpRequestData();
     
    gs.info("Endpoint is: " + unsignedRequest.getEndpoint());

Output:

    Endpoint is: https://third-party-endpoint

## RequestAuthAPI - resetAuthCredential() {#ariaid-title6}

Generates a temporary, limited privilege token that you can use to provide trusted
users with temporary security credentials to control third-party resources.
To use this method, the third-party service must include an API or SDK that processes and
manages limited access tokens.
{#RequestAuthAPI-resetAuthCredential__table_rxd_qy4_5jb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 8. Parameters]

{#RequestAuthAPI-resetAuthCredential__table_rxd_qy4_5jb} {#RequestAuthAPI-resetAuthCredential__table_sxd_qy4_5jb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 9. Returns]

{#RequestAuthAPI-resetAuthCredential__table_sxd_qy4_5jb}  

    // Creates a temporary token 
    function(authAPI) {​
        var requestData = authAPI.getHttpRequestData();​
        var credential= authAPI.getAuthCredential();​
        credential.setAttribute('Action', 'aws_sessionToken');​  
        authAPI.resetAuthCredential();	

        //Returns status information
        var status = credential.getAttribute('credential_reset_status'); ​
    }


