---
schema_version: "1"
id: 406a804dd1d893ff71d22db80e42a17a41e218e612238679d3167f5b61d63990
title: Set a SOAP Header
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/apikit/latest/apikit-4-set-header-task.md
canonical_url: https://docs.mulesoft.com/apikit/latest/apikit-4-set-header-task
source_site: docs.mulesoft.com
content_type: documentation
content_hash: c00db441376251e00f2d7ceb52cef6f66ff60598f068f6449f235c20ae5343bb
description: MuleSoft Documentation Site
release: 4.x
latest: true
---
---
product: APIkit
version: 4.x
is-latest-version: true
---

# Set a SOAP Header

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Add SOAP headers declared in your WSDL to outbound responses from an APIkit for SOAP application.
This walkthrough extends the `OrderTshirt` flow and DataWeave so the response includes header data
such as `APIUsageInformation`. Download `tshirt2.wsdl`, complete
[prerequisites for Using APIkit for SOAP](https://docs.mulesoft.com/apikit/latest/apikit-4-soap-prerequisites-task), and
[create an APIkit for SOAP project](https://docs.mulesoft.com/apikit/latest/apikit-4-soap-project-task) before you begin.

1.  In Anypoint Studio, open `tshirt2.wsdl` in `src/main/resources/api` and scroll to the
    `APIUsageInformation` element, which is the element expected by the contract.

2.  On the canvas, select `Transform Message` in the `OrderTshirt:/soapkit-config` flow.

    The following DataWeave code is available:

    ```linenums
    {
    	body : {
    		ns0#OrderTshirtResponse: {
    			orderId: "I got a request from "
    			++ payload.body.ns0#OrderTshirt.name
    			++ " using the following auth header "
    			++ (payload.headers["AuthenticationHeader"].ns0#AuthenticationHeader.apiKey default "")
    		}
    	} write "application/xml"
    }
    ```

3.  Add the following `APIUsageInformation` header declaration:

    ```linenums
    {
    	body : {
    		ns0#OrderTshirtResponse: {
    			orderId: "I got a request from "
    			++ payload.body.ns0#OrderTshirt.name
    			++ " using the following auth header "
    			++ (payload.headers["AuthenticationHeader"].ns0#AuthenticationHeader.apiKey default "")
    		}
    	} write "application/xml",

    	headers: { (1)
    		header: {
    			ns0#APIUsageInformation: {
    			}
    		} write "application/xml"
    	}

    }
    ```

    <table><tbody><tr><td><i data-value="1"></i><b>1</b></td><td>This DataWeave code adds headers to the output of the <code>Transform Message</code> component.</td></tr></tbody></table>

4.  Add the `apiCallsRemaining` header to the `APIUsageInformation` element:

    { body : { ns0#OrderTshirtResponse: { orderId: "I got a request from " ++
    payload.body.ns0#OrderTshirt.name ++ " using the following auth header " ++
    (payload.headers\["AuthenticationHeader"\].ns0#AuthenticationHeader.apiKey default "") } } write
    "application/xml",

        headers: {
        	header: {
        		ns0#APIUsageInformation: {
        			apiCallsRemaining: 10 **(1)**
        		}
        	} write "application/xml"
        }

    }

    <table><tbody><tr><td><i data-value="1"></i><b>1</b></td><td>Set <code>apiCallsRemaining</code> to <code>10</code>.</td></tr></tbody></table>

5.  Save and run the project again.

6.  In SoapUI, execute the `OrderTshirt` request again.

    The response envelope from APIkit for SOAP is:

```xml
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Header>
      <ns0:APIUsageInformation xmlns:ns0="http://mulesoft.org/tshirt-service">
         <apiCallsRemaining>10</apiCallsRemaining>
      </ns0:APIUsageInformation>
   </soap:Header>
   <soap:Body>
      <ns0:OrderTshirtResponse xmlns:ns0="http://mulesoft.org/tshirt-service">
         <orderId>I got a request from John, using the following auth header 987654321</orderId>
      </ns0:OrderTshirtResponse>
   </soap:Body>
</soap:Envelope>
```

## See Also

- [APIkit for SOAP Module Reference](https://docs.mulesoft.com/apikit/latest/apikit-for-soap-module-reference)
