# Send a Batch Request
source: https://developer.mastercard.com/mastercard-gateway/documentation/integrations-types/hosted-batch/integrate-hosted-batch/send-batch-request/index.md

There are several steps needed to make sure the transaction request body is sent securely to the Mastercard Gateway. This section goes through the essential concepts and functions that you may need to use in your integration.

## Uploading the batch request {#uploading-the-batch-request}

The batch file is submitted through HTTP over the Secure Socket Layer (SSL) protocol using the HTTP PUT method. This section contains sample code snippets written in the shell scripting language.

### Connection URL {#connection-url}

The connection URL contains information identifying the Batch version (same as API version), merchant identifier, and batch name.

`{{host}}/batch/version/<versionNum>/merchant/<merchantId>/batch/<batchName>`

Where:

* `<versionNum>` is the version of Batch
* `<merchantId>` is your Merchant identifier
* `<batchName>` is your unique name for the batch

#### Configuration: Batch application {#configuration-batch-application}

```bash
# Configuration: Batch application
VERSION_NUM=100
HB_HOST="https://gateway.mastercard.com/batch"

# Configuration: Merchant
MERCHANT_ID="merchant12345"
MERCHANT_PASSWORD="s3cr3tP@ssw0rd"

CONNECT_URL="$HB_HOST/version/$VERSION_NUM/merchant/$MERCHANT_ID/batch/"
```

If you submit a batch request to an incorrectly formatted URL, you will be redirected to a landing page displaying information on how the request should be formatted.

### Authentication data {#authentication-data}

The Mastercard Gateway requires every batch request to be authenticated successfully. The snippet covers how to provide authentication data (Merchant ID and API Password) with each batch request.

This code snippet shows how to set credentials in the program.

```bash
# Configuration: Batch application
VERSION_NUM=100
HB_HOST="https://mtf.gateway.mastercard.com/batch"

# Configuration: Merchant
MERCHANT_ID="<YOUR_MERCHANT_ID>"
MERCHANT_PASSWORD="<YOUR_MERCHANT_PASSWORD>"

# Configuration: Advanced
CONNECT_URL="$HB_HOST/version/$VERSION_NUM/merchant/$MERCHANT_ID/batch"

# Generate Base64-encoded credentials for Basic Auth
AUTH_HEADER="Authorization: Basic $(echo -n ":$MERCHANT_PASSWORD" | base64)"

# Set content type
CONTENT_TYPE_HEADER="Content-Type: text/plain; charset=UTF-8"

# Combine headers
HTTP_HEADERS="$AUTH_HEADER"$'\n'"$CONTENT_TYPE_HEADER"
```

### HTTP headers {#http-headers}

HTTP Headers provide metadata information about the batch request being sent to the Mastercard Gateway. This snippet demonstrates the mandatory HTTP Headers that must be set for every batch request (the headers listed here must be set in addition to any authentication headers mentioned under Authentication Data, where applicable).

The character encoding of your request must include only ISO-8859-1(Latin1), or UTF-8 formats. See [Ensure Character Encoding](https://developer.mastercard.com/mastercard-gateway/documentation/integrations-types/hosted-batch/integrate-hosted-batch/create-batch-request/index.md#ensure-correct-character-encoding).

This code snippet shows how to set HTTP headers in the program.

```bash
HTTP_HEADERS=$(
  echo -n "Authorization: Basic $(echo -n ":$MERCHANT_PASSWORD" | base64)"
  echo "Content-Type: text/plain; charset=UTF-8"
)
```

## Uploading the message integrity code {#uploading-the-message-integrity-code}

Batch requires you to confirm the integrity of the batches you upload by providing a Message Integrity Code (MIC) for validation. The MIC must be calculated by creating a SHA-1 digest of the complete upload request body that contains the CSV NVP batch data and must be HEX encoded.
Alert: Supplying the MIC for validation is mandatory.

The MIC upload works as follows:

1. Upload a batch to the Batch service.

Warning: Ensure that the batch status is UPLOADED before you supply the MIC. See [retrieving the batch status](https://developer.mastercard.com/mastercard-gateway/documentation/integrations-types/hosted-batch/integrate-hosted-batch/retrieve-batch-status/index.md).

2. Upload the MIC to the Batch service by sending an HTTPS POST request to the following URL with the MIC HEX encoded in the request body. `{{host}}/batch/version/<versionNum>/merchant/<merchantId>/batch/<batchName>/validate`

Where:

* `<versionNum>` is the version of Batch
* `<merchantId>` is your Merchant identifier
* `<batchName>` is your unique name for the batch

Warning: The batch status remains in the UPLOADED state until the MIC has been verified.

3. Batch validates the supplied MIC against the uploaded batch, and if it matches, the batch will be accepted for processing. If the MIC does not match it is assumed the batch is corrupted. The batch will be deleted and will need to be uploaded again.

Warning: The next step is [retrieving the batch status](https://developer.mastercard.com/mastercard-gateway/documentation/integrations-types/hosted-batch/integrate-hosted-batch/retrieve-batch-status/index.md).
