POST Create Target Account Profile

POST /receiver-account/v1/targetAccountProfiles

Development Guide

The Receiver-Accounts API allows the application to create a profile for a receiver's bank or wallet account and returns a targetAccountProfileId.



1. Prepare headers & authentication:

Call the 'Create a target account profile' endpoint with a POST HTTP method, providing the OAuth access_token in the header and all other required header values


Note: MoneyGram uses the OAuth 2.0 framework. The application must use their OAuth client credentials to generate an accessToken by calling the Get access token endpoint. The token is valid for 1 hour and must be passed as a header value in all subsequent API HTTP calls. Learn More


🚀

Launch Code Example:




2. Provide sender, receiver & targetAccount information to the request body:

The application at a minimum must provide the following fields: destinationCountryCode , receiveCurrencyCode, serviceOptionCode, serviceOptionRoutingCode, sender.name.firstName, sender.name.lastName, sender.mobilePhone.number, sender.mobilePhone.countryDialCode, receiver.name.firstName, receiver.name.lastName, receiver.address.line1, receiver.address.city, receiver.address.countryCode, receiver.mobilePhone.number, receiver.mobilePhone.countryDialCode and the targetAccount.


Note:

  • The application can use the 'Retrieve Account Deposit Fields for Registration' to understand the necessary beneficiary account fields required to for the bank, wallet or card deposit serviceOption. This endpoint returns an array of service options and keys. The keys are account fields that need to be collected from the consumer to transfer funds to the corresponding bank, wallet or card. Learn More
  • The 'Create a target account profile' API uses ISO Standards for country values. MoneyGram provide Reference Data APIs which can be queried to understand the supported values and associated metadata.

🚀

Launch Code Example:




3. Make the request and handle the response:

The application will call the 'Retrieve Account Deposit Fields for Registration' endpoint with a GET HTTP method. The 'Retrieve Countries' API will generate a response with an array of supported values and metadata for all countries. The application must build to handle the following response scenarios.


  • Success | Parse the Response | 200 OK HTTP Status | "targetAccountCheckedCode": "ACCOUNT_CHECKED
    When the 'Create a Target Account Profile' endpoint responds with a 200 HTTP Status, a targetAccountProfileId is created and the "targetAccountCheckedCode": "Account_Checked" indicating the target account details have been validated. The application can continue.

  • Success | Parse the Response | 200 OK HTTP Status | "targetAccountCheckedCode": "ACCOUNT_NOT_CHECKED
    When the 'Create a Target Account Profile' endpoint responds with a 200 HTTP Status, a targetAccountProfileId is created and the "targetAccountCheckedCode": "Account_Not_Checked" indicating the target account details have failed validation. The application must correct details and resubmit the request.

  • Success | Parse the Response | 200 OK HTTP Status | "targetAccountCheckedCode": "ACCOUNT_NOT_AVAILABLE
    When the 'Create a Target Account Profile' endpoint responds with a 200 HTTP Status, a targetAccountProfileId is created and the "targetAccountCheckedCode": "ACCOUNT_NOT_AVAILABLE" indicating the destination country and clearing system do not offer validation of account details. The application can continue.

  • Failed | Handle the Error | 400 Bad Request HTTP Status
    When the 'Create a Target Account Profile' endpoint responds with 400 HTTP Status, specific error code/s will be returned with an array of offending fields. The application will need to resolve these errors and resubmit request.

🚀

Launch Code Example:

.

.

.




4. You're Done! Proceed to Transfer API Module

Once the account data has been validated and the application can continue to make a transaction.




Code Examples


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

const createAccountProfile = 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 = "sandboxapi.moneygram.com";
    const url = 'https://' + host + '/receiver-account/v1/targetAccountProfiles';

    // 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",
        receiveCurrencyCode: "USD",
        destinationCountrySubdivisionCode: "US-TX",
        serviceOptionCode: "BANK_DEPOSIT",
        serviceOptionRoutingCode: "74261037",

        sender: {
            name: {
                firstName: "John",
                middleName: "",
                lastName: "Doe",
                secondLastName: ""
            },
            address: {
                line1: "100 Main ST",
                line2: "",
                line3: "",
                city: "Dallas",
                countrySubdivisionCode: "US-TX",
                countryCode: "USA",
                postalCode: "75001"
            },
            mobilePhone: {
                number: "555551234",
                countryDialCode: "1"
            },
        },
        receiver: {
            name: {
                firstName: "Jane",
                middleName: "",
                lastName: "Doe",
                secondLastName: ""
            },
            address: {
                line1: "200 Second ST",
                line2: "",
                line3: "",
                city: "Dallas",
                countrySubdivisionCode: "US-MN",
                countryCode: "USA",
                postalCode: "55111"
            },
            mobilePhone: {
                number: "555121234",
                countryDialCode: "1"
            },
            dateOfBirth: "1998-10-01",
        },
        targetAccount: {
            accountType: "22",
            accountNumber: "987654321",
            accountNumberVerification: "987654321",
            bankCode: "123456789"
        }
    }
}
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
            // Verify readyForCommit is true, if yes, transaction is ready to commit
            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);
};

createAccountProfile();
import requests
import uuid
import json


def create_account_profile():

    # 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 = "sandboxapi.moneygram.com"
    url = "https://" + host + "/receiver-account/v1/targetAccountProfiles"

    # 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",
        "receiveCurrencyCode": "USD",
        "destinationCountrySubdivisionCode": "US-TX",
        "serviceOptionCode": "BANK_DEPOSIT",
        "serviceOptionRoutingCode": "74261037",
        "sender": {
            "name": {
                "firstName": "John",
                "middleName": "",
                "lastName": "Doe",
                "secondLastName": "",
            },
            "address": {
                "line1": "100 Main St",
                "city": "Dallas",
                "countrySubdivisionCode": "US-TX",
                "countryCode": "USA",
                "postalCode": "75001",
            },
            "mobilePhone": {"number": "555551234", "countryDialCode": "1"},
        },
        "receiver": {
            "name": {
                "firstName": "Jane",
                "middleName": "",
                "lastName": "Doe",
                "secondLastName": "",
            },
            "address": {
                "line1": "line 1 of address",
                "city": "Dallas",
                "countrySubdivisionCode": "US-TX",
                "countryCode": "USA",
                "postalCode": "75001",
            },
            "mobilePhone": {"number": "555551234", "countryDialCode": "1"},
            "dateOfBirth": "1998-10-01",
        },
        "targetAccount": {
            "accountType": "22",
            "accountNumber": "987654321",
            "accountNumberVerification": "987654321",
            "bankCode": "123456789",
        },
    }

    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:
            # Step 5: Parse the error response and handle the errors
            print("Request failed with status code:", response.status_code)
            print(json.dumps(json.loads(response.text), indent=2))

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


create_account_profile()

package receiveraccount;

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.UUID;

public class CreateAccountProfile {

    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 = "sandboxapi.moneygram.com";
        String tokenEndpoint = "https://" + host + "/receiver-account/v1/targetAccountProfiles";

        // Step 2: Create the POST request headers & body
        // Create a JSON object
        JsonObjectBuilder senderBuilder = Json.createObjectBuilder()
                .add("name", Json.createObjectBuilder().add("firstName", "firstName").add("lastName", "lastName"))
                .add("mobilePhone", Json.createObjectBuilder().add("number", "6123456789").add("countryDialCode", "1"));
        JsonObjectBuilder receiverBuilder = Json.createObjectBuilder()
                .add("name", Json.createObjectBuilder().add("firstName", "firstName").add("lastName", "lastName"))
                .add("address", Json.createObjectBuilder().add("line1", "line1 of address").add("city", "Dallas")
                .add("countryCode", "USA").add("countrySubdivisionCode", "US-TX").add("postalCode", "75001"))
                .add("mobilePhone", Json.createObjectBuilder().add("number", "6123456789").add("countryDialCode", "1"))
                .add("dateOfBirth", "1980-01-15");
        JsonObjectBuilder targetAccountBuilder = Json.createObjectBuilder()
                .add("targetAccount", Json.createObjectBuilder().add("accountType", "22").add("accountNumber", "987654321")
                .add("accountNumberVerification", "987654321").add("bankCode", "123456789"));       
        JsonObjectBuilder requestBuilder = Json.createObjectBuilder()
                .add("agentPartnerId", "your_partner_id")
                .add("targetAudience", "AGENT_FACING")
                .add("userLanguage", "en-US")
                .add("destinationCountryCode", "USA")
                .add("destinationCountrySubdivisionCode", "US-TX")
                .add("serviceOptionCode", "BANK_DEPOSIT")
                .add("serviceOptionRoutingCode", "74261037")
                .add("sender", senderBuilder)
                .add("receiver", receiverBuilder);
                .add("targetAccount", targetAccountBuilder);

        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
        }
    }
}



API Structure


Header Parameters

FieldTypeRequired
/Optional
Description
X-MG-ClientRequestIdStringRequiredClient Request Id that can be passed by the client application. Client request Id must be unique within a single session for unique requests. This attribute can be used for ensuring idempotent request processing for some APIs. MoneyGram recommends using a UUID for the value of this field.
X-MG-ConsumerIPAddressStringOptionalIP Address of the system initiating the session




Request Body Fields

FieldTypeRequired
/Optional
Description
targetAudienceStringOptionalTailors MoneyGram’s error messages and field metadata to an in-store, digital or crypto customer. (Enumerated value)

NOTE: For a full list of accepted target audience values. See the TARGET_AUDIENCE enumeration from the Reference Data Enumerations endpoint
agentPartnerIdStringRequiredUnique identifier for the agent or partner
userLanguageStringOptionalLanguage used by the user/operator
destinationCountryCodeString
Max Length: 3
RequiredTransaction Destination Country (ISO alpha-3 code)

NOTE: For a full list of accepted destination Countries and supported destinationCountrySubdivisionCode see Reference Data API Module: Retrieve Countries ISO3 endpoint
serviceOptionCodeString
Max length: 21
RequiredUnique category code to identify the transaction method

NOTE: For a full list of accepted service option codes per destination country see the Reference Data API Module: service-options endpoint
serviceOptionRoutingCodeString
Max length: 21
RequiredUnique identifier of the individual banking, wallet, or card provider for the service option.

NOTE: For a full list of accepted service option codes per destination country see the Reference Data API Module: service-options endpoint
sender.name.firstNameString
Min length: 1
Max length: 20
RequiredFirst Name
sender.name.middleNameString
Min length: 1
Max length: 20
OptionalMiddle Name (if applicable)
sender.name.lastNameString
Min length: 1
Max length: 30
RequiredLast Name
sender.name.secondLastNameString
Min length: 1
Max length: 30
OptionalSecond Last Name
sender.mobilePhone.numberString
Min length: 5
Max length: 14
RequiredPhone number
sender.mobilePhone.countryDialCodeString
Min length: 1
Max length: 3
RequiredCountry dial code

NOTE: For country calling code see Reference Data API Module /countries endpoint phoneDialCodes
receiver.name.firstNameString
Min length: 1
Max length: 20
RequiredFirst Name
receiver.name.middleNameString
Min length: 1
Max length: 20
OptionalMiddle Name (if applicable)
receiver.name.lastNameString
Min length: 1
Max length: 30
RequiredLast Name
receiver.name.secondLastNameString
Min length: 1
Max length: 30
OptionalSecond Last Name (if applicable)
receiver.address.line1String
Min length: 1
Max length: 80
RequiredResidence address line 1
receiver.address.line2String
Min length: 1
Max length: 80
OptionalResidence address line 2 (if applicable)
receiver.address.line3String
Min length: 1
Max length: 80
OptionalResidence address line 3 (if applicable)
receiver.address.cityString
Min length: 1
Max length: 40
RequiredCity of residence
receiver.address.countrySubdivisionCodeString
Max length: 6
OptionalState/province of residence.

NOTE: For a full list of accepted countries and supported destination country subdivision codes see Reference Data API Module: Retrieve Countries ISO3 endpoint
receiver.address.countryCodeString
Max length: 3
RequiredCountry of residence. (ISO alpha-3 code)

NOTE: For a full list of accepted countries and supported destination country subdivision codes see Reference Data API Module: Retrieve Countries ISO3 endpoint
receiver.address.postalCodeString
Min length: 2
Max length: 6
OptionalPostal code/ZIP of residence
receiver.mobilePhone.numberString
Min length: 5
Max length: 14
OptionalPhone number
receiver.mobilePhone.countryDialCodeString
Min length: 1
Max length: 3
OptionalCountry dial code

Target Account Fields

FieldTypeRequired
/Optional
Description
targetAccount.accountTypeStringOptionalBank account type
targetAccount.accountNumberStringOptionalA unique string of numbers, letters, or other characters which identify a specific bank account
targetAccount.accountNumberVerificationStringOptionalA unique string of numbers, letters, or other characters which identify a specific bank account
targetAccount.bankIdentifierStringOptionalBank Identifier Code (BIC) an 8 to 11-character code that is used to identify a specific bank when you make an international transaction
targetAccount.bankIdentifierWithLookupStringOptionalFor collecting the Indian Financial System Code (IFSC) or routing number for Bangladesh, with a lookup feature for these countries
targetAccount.bankNameStringOptionalBank's name
targetAccount.bankNameTextStringOptionalManually entered bank name if not provided in the bank name list
targetAccount.bankBranchNameStringOptionalManually entered bank branch name
targetAccount.bankCodeStringOptionalBank's routing number
targetAccount.bankBranchCodeStringOptionalManually entered receiver bank branch code
targetAccount.benefIdNumberStringOptionalReceiver identification number
targetAccount.accountExpirationMonthStringOptionalExpiration month of the account
targetAccount.accountExpirationMonthStringOptionalExpiration year of the account
targetAccount.receiverPurposeOfTransactionEmigrationFlagStringOptionalFlag to indicate if the purpose of transaction is for emigration
targetAccount.sendPurposeOfTransactionPartnerFieldStringOptionalExplanation or reason of the transferring funds (Enumerated Values)
targetAccount.receiverAccountIssueStatePartnerFieldStringOptionalState/province of the receiver (Enumerated Values)
targetAccount.additionalDetailsDynamic OptionalDynamic field key/values for the target account
targetAccount.additionalDetailsDynamicOptionalDynamic field key/values for the transaction

Additional Details

FieldTypeRequired
/Optional
Description
additionalDetailsDynamicOptionalDynamic field key/values for the transaction


Response Fields

FieldTypeRequired
/Optional
Description
targetAccountProfileIdStringRequiredUnique identifier for the target account profile
targetAccountCheckedCodeStringRequiredCode to indicate the target account details are confirmed with the downstream partner, or if account checking is not available for the downstream partner.
(Enumerated Value)
ACCOUNT_CHECKED, ACCOUNT_CHECK_NOT_AVAILABLE, ACCOUNT_CHECK_FAILED.
additionalDetailsDynamicOptionalDynamic field key/values for the transaction