GET Search for a Consumer Profile

GET /consumer/v2/profiles/search

Development Guide:

The 'Search for a Consumer Profile' endpoint is used for a in store you case and allows the application to query a consumer profile by phone number, identification type/number or MoneyGram Rewards number. The endpoint will return a list consumer profiles that match the lookup query.



1. Prepare headers & authentication:

The application must call the Search for consumer endpoint with a GET 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 Example Code




2. Provide the query parameters:

The application must provide one of the query parameters to the API:


  • mobilePhone The application can provide the consumer mobile number, without country code. This will return all profile that match the phone number.

  • identificationType +identificationNumber. The application can provide the consumer unique identification Type and number. This will return the consumer's unique profile.

  • rewardsNumber The application can provide the consumer's unique total rewards number. This will return the consumer's unique profile.

Note: When the application queries a consumer profile by mobilePhone, multiple pofileId made as it can be shared across profiles.


🚀

Launch Example Code




3. Make the request and handle the response:

The application will call the 'Consumer Search' endpoint with a GET HTTP method. The 'Consumer Search' will respond with an array of consumers based on the query parameters. The application must build to handle the following response scenarios:


  • Success | Parse the Response | 200 OK HTTP Status
    When the 'Consumer Search' endpoint responds with a 200 HTTP Status. An array of the consumers will be returned, including the consumer profile data and the consumer's profileId.

  • Success | Consumer search has no content | 204 No Content HTTP Status
    When the 'Consumer Search' endpoint responds with 204 HTTP Status. The 'Consumer Search' endpoint will return a message of "204 No Content" message.

  • Failed | Handle the Error | 400 Bad Request HTTP Status
    When the 'Consumer Search' endpoint responds with 400 HTTP Status, a "missing field " error will be returned. This will generally be due to not providing a search query parameter for the consumer. The application will need to resolve the error and resubmit the request.

🚀

Launch Example Code

.

.




4. You're done! Select the consumer profileId and proceed to Retrieve a Consumer Transaction History API:

The application can use the consumer profileId to call the 'Retrieve a Consumer's Transaction History' endpoint.






Code Examples

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

const consumerSearch = 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 + '/consumer/v2/profiles/search';

    // Step 2: Create the GET request headers & params
    const headers = {
        'Content-Type': 'application/json',
        'X-MG-ClientRequestId': uuidv4(), // New UUID for each request tracing
        'Authorization': 'Bearer ' + token,
    };

    const params = {
        'targetAudience': 'AGENT_FACING',
        'agentPartnerId': 'your_partner_id',
        'userLanguage': 'en-US',
        'mobilePhone': '5551231234',
        'maxProfilesToReturn': '5',
        'pageNumber': '1',
        'perPage': '20'
    }

    try {
        // Step 3: Send the request and obtain the response
        axios.get(url, { params, 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);
    }
};

consumerSearch();

import requests
import uuid
import json

def consumer_search():

    # 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 + '/consumer/v2/profiles/search'

    # Step 2: Create the GET request headers & params
    headers = {
        'Content-Type': 'application/json',
        'X-MG-ClientRequestId': str(uuid.uuid4()), # New UUID for each request tracing
        'Authorization': 'Bearer ' + token,
    }

    params = {
        'targetAudience': 'AGENT_FACING',
        'agentPartnerId': 'your_partner_id',    
        'userLanguage': 'en-US',
        'mobilePhone': '5551231234',
        'maxProfilesToReturn': '5',
        'pageNumber': '1',
        'perPage': '20'
    }

    try:
        # Step 3: Send the request and obtain the response
        response = requests.get(url, params=params, 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)

consumer_search()
package consumer;

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 ConsumerSearch {

    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";

        // Step 2: Create the GET request headers & params
        // Mandatory Query params
        String agentPartnerId = "your_partner_id";
        String userLanguage = "en-US";

        // Optional Query params
        String targetAudience = "AGENT_FACING";
        String mobilePhone = "5551231234";
        Integer maxProfilesToReturn = 20;
        Integer pageNumber = 1;
        Integer perPage = 20;

        String uri = "https://" + host + "/consumer/v2/profiles/search?"
                + "agentPartnerId=" + agentPartnerId
                + "&userLanguage=" + userLanguage
                + "mobilePhone=" + mobilePhone
                + (targetAudience.isBlank() ? "" : "&targetAudience=" + targetAudience)
                + (maxProfilesToReturn == null ? "" : "&maxProfilesToReturn=" + maxProfilesToReturn)
                + (pageNumber == null ? "" : "&pageNumber=" + pageNumber)
                + (perPage == null ? "" : "&perPage=" + perPage);

        HttpClient httpClient = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(uri))
                .GET()
                .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/OptionalDescription
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.



Query Parameters


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 agent or partner identifier.
userLanguageStringRequiredLanguage used by the user/operator.
rewardsNumberString
Max length: 20
OptionalUnique code to apply Loyalty accrual/redemption (MoneyGram Plus Number)
identificationTypeString
Max length: 3
OptionalType of identification provided by the consumer (Enumerated value)
NOTE: See the PERSONAL_ID1_TYPE and PERSONAL_ID2_TYPE enumerations from the Reference Data Enumerations endpoint
identificationNumberString
Max length: 30
OptionalIdentification document number
mobilePhoneString
Min length: 5
Max length: 14
OptionalPhone Number
maxProfilesToReturnStringOptionalThe Maximum number of Consumer profiles to return per search request.
pageNumberStringOptionalPage number (cursor) returned with search result
perPageStringOptionalNumber of results to return per page



Response Fields

FieldTypeRequired/
Optional
Description
profiles.name.firstNameString
Min length: 1
Max length: 20
RequiredFirst Name
profiles.name.middleNameString
Min length: 1
Max length: 20
OptionalMiddle Name (if applicable)
profiles.name.lastNameString
Min length: 1
Max length: 30
RequiredLast Name
profiles.name.secondLastNameString
Min length: 1
Max length: 30
OptionalConsumer's Second Last Name (if applicable)
profiles.address.line1String
Min length: 1
Max length: 30
RequiredResidence address line 1
profiles.address.line2String
Min length: 1
Max length: 30
OptionalResidence address line 2 (if applicable)
profiles.address.line3String
Min length: 1
Max length: 30
OptionalResidence address line 3 (if applicable)
profiles.address.cityString
Min length: 1
Max length: 20
RequiredCity of residence
profiles.address.countrySubdivisionString
Min length: 3
Max length: 3
OptionalState/province of residence
profiles.address.countryCodeString
Min length: 1
Max length: 30
RequiredCountry of residence (ISO Alpha-3 Code)
profiles.address.postalCodeString
Min length: 2
Max length: 10
OptionalPostal code/ZIP of residence
profiles.mobilePhone.numberString
Min length: 5
Max length: 14
RequiredPhone Number
profiles.mobilePhone.countryDialCodeString
Min length: 1
Max length: 5
RequiredCountry calling code

NOTE: For country calling code see Reference Data API Module /countries endpoint phoneDialCodes
profiles.rewardsNumberStringOptionalEnroll in MoneyGram's Plus Rewards program
profiles.datOfBirthStringRequiredDate of birth (YYYY-MM-DD
profiles.profileIdStringOptionalConsumer's unique identifier
paginationMetadata.totalItemsNumberOptionalTotal number of items on all pages
paginationMetadata.currentPageNumberOptionalCurrent page number
paginationMetadata.perPageNumberOptionalPage size
paginationMetadata.totalPagesNumberOptionalTotal number of pages
paginationMetadata.links.pageNumberNumberOptionalPage number
paginationMetadata.links.hrefString
Max Length: 255
OptionalHATEOS links to data