---
updatedAt: 2025-10-23T05:33:17.000Z
---

# Transfer APIs - Quote a transaction

```java Java
package com.transfer;

import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.json.JsonWriter;
import java.io.StringWriter;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Base64;
import java.util.UUID;

public class FeeQuote {

    public static void main(String[] args) {
        // Step 1: Read configuration values with upmost security
        String token = "your_access_token_from_oauth_response";

        // For production - api.moneygram.com & For test - sandboxapi.moneygram.com
        String host = "api.moneygram.com";
        String tokenEndpoint = "https://" + host + "/transfer/v1/transactions/quote";

        // Step 2: Create the POST request headers & body
        // Create a JSON object
        JsonObjectBuilder sendAmountBuilder =  Json.createObjectBuilder()
                .add("currencyCode", "USD")
                .add("value", 500);
        JsonObjectBuilder requestBuilder =  Json.createObjectBuilder()
                .add("agentPartnerId", "your_partner_id")
                .add("targetAudience", "AGENT_FACING")
                .add("userLanguage", "en-US")
                .add("destinationCountryCode", "USA" )
                .add("destinationCountrySubdivisionCode", "US-MN" )
                .add("serviceOptionCode", "WILL_CALL" )
                .add("sendAmount", sendAmountBuilder)
                .add("receiveCurrencyCode", "USD" );

        JsonObject jsonObject = requestBuilder.build();
        // Create a StringWriter to write the JSON string
        StringWriter stringWriter = new StringWriter();
        try (JsonWriter jsonWriter = Json.createWriter(stringWriter)) {
            jsonWriter.writeObject(jsonObject);
        }
        // Get the JSON string from the StringWriter
        String jsonString = stringWriter.toString();

        HttpClient httpClient = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(tokenEndpoint))
                .POST(HttpRequest.BodyPublishers.ofString(jsonString))
                .setHeader("Authorization", "Bearer " + token)
                .setHeader("X-MG-ClientRequestId", String.valueOf(UUID.randomUUID()))
                .build();

        try {
            // Step 3: Send the request and obtain the response
            HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());

            // Retrieve the status code and body from the response
            int statusCode = response.statusCode();

            // Step 4: Parse the success response and process further
            if (statusCode == 200) {
                String responseBody = response.body();
                System.out.println(responseBody);
            }else{
                // Step 5: Parse the error response and handle the errors
                String responseBody = response.body();
                System.out.println(responseBody);
            }
        } catch (Exception e) {
            e.printStackTrace();
            // TODO: handle exception
        }
    }
}

```

```python Python
import requests
import uuid
import json

# Step 1: Read configuration values with upmost security
token = "your_access_token_from_oauth_response"
# For production - api.moneygram.com & For test - sandboxapi.moneygram.com
host = "api.moneygram.com";
url = 'https://' + host + '/transfers/v1/transactions/quote';

# Step 2: Create the POST request headers & body
headers = {
    'Content-Type': 'application/json',
    'X-MG-ClientRequestId': str(uuid.uuid4()), # New UUID for each request tracing
    'Authorization': 'Bearer ' + token,
}
request = {
    'agentPartnerId': 'your_partner_id',
    'targetAudience': 'AGENT_FACING',
    'userLanguage': 'en-US',
    'destinationCountryCode': 'USA',
    'destinationCountrySubdivisionCode': 'US-MN',
    'serviceOptionCode': 'WILL_CALL',
    'sendAmount': {
        'currencyCode': 'USD',
        'value': 500
    },
    'receiveCurrencyCode': 'USD',
}

try:
    # Step 3: Send the request and obtain the response
    response = requests.post(url, json=request, headers=headers)

    # Step 4: Parse the success response and process further
    if response.status_code == 200:
        parsed_response = json.dumps(json.loads(response.text), indent=2)
        print(parsed_response)
    else:
        # Print the error message if request fails
        # TODO: handle exception
        print("Request failed with status code:", response.status_code)
        print(json.loads(json.dumps(response.text, indent=4)))

except requests.exceptions.RequestException as e:
    # Print any error that occurred during the request
    # TODO: handle exception
    print("An error occurred:", e)

```

```node Node
const axios = require('axios');
const { v4: uuidv4 } = require('uuid');

const feequote = async () => {

    // Step 1: Read configuration values with upmost security
    const token = "your_access_token_from_oauth_response"
    // For production - api.moneygram.com & For test - sandboxapi.moneygram.com
    const host = "api.moneygram.com";
    const url = 'https://' + host + '/transfer/v1/transactions/quote';

    // Step 2: Create the POST request headers & body
    const headers = {
        'Content-Type': 'application/json',
        'X-MG-ClientRequestId': uuidv4(), // New UUID for each request tracing
        'Authorization': 'Bearer ' + token,
    };
    const request = {
        agentPartnerId: "your_partner_id",
        targetAudience: "AGENT_FACING",
        userLanguage: "en-US",
        destinationCountryCode: "USA",
        destinationCountrySubdivisionCode: "US-MN",
        serviceOptionCode: "WILL_CALL",
        sendAmount: {
            currencyCode: "USD",
            value: 500
        },
        receiveCurrencyCode: "USD",
    }

    try {
        // Step 3: Send the request and obtain the response
        axios.post(url, request, { headers })
            .then(function (response) {
                // Step 4: Parse the success response and process further
                console.log(JSON.stringify(response.data, null, 2))
            })
            .catch(function (error) {
                // Step 5: Parse the error response and handle the errors
                if (error.response) {
                    console.log('Response status:', error.response.status);
                    console.log('Response body:', error.response.data);
                } else {
                    // TODO: handle generic errors
                    console.error('Error:', error.message);
                }
            });
    } catch (error) {
        // TODO: handle exception
        console.error('Error:', error.message);
    }
};

feequote();

```

```json Response Example
{
  "transactions": [
    {
      "transactionId": "6d33f3fe-19d4-a584-a120-50fb313e57bf",
      "serviceOptionCode": "WILL_CALL",
      "serviceOptionName": "10 Minute Service",
      "sendAmount": {
        "amount": {
          "value": 500,
          "currencyCode": "USD"
        },
        "fees": {
          "value": 5.5,
          "currencyCode": "USD"
        },
        "taxes": {
          "value": 0,
          "currencyCode": "USD"
        },
        "total": {
          "value": 505.5,
          "currencyCode": "USD"
        }
      },
      "receiveAmount": {
        "amount": {
          "value": 500,
          "currencyCode": "USD"
        },
        "fees": {
          "value": 0,
          "currencyCode": "USD"
        },
        "taxes": {
          "value": 0,
          "currencyCode": "USD"
        },
        "total": {
          "value": 500,
          "currencyCode": "USD"
        },
        "fxRate": 1,
        "fxRateEstimated": false
      }
    }
  ]
}
```

# Read configuration values with upmost security

<!-- java@19 -->
<!-- python@6,8,9 -->
<!-- node@7-10 -->

Environments:
Production: api.moneygram.com & 
Test: sandboxapi.moneygram.com

# Create the POST request headers & body

<!-- java@27-45 -->
<!-- python@12-29 -->
<!-- node@13-30 -->



# Send the request and obtain the response

<!-- java@59 -->
<!-- python@33 -->
<!-- node@34-38 -->



# Parse the success response and process further

<!-- java@65-68 -->
<!-- python@36,38 -->
<!-- node@37-29 -->



# Parse the error response and handle the errors

<!-- java@70-78 -->
<!-- python@39-48 -->
<!-- node@41-44 -->