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
👉Profiles - Search for Consumer - HeadersOpen Recipe
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
, multiplepofileId
made as it can be shared across profiles.
Launch Example Code
👉Profiles - Search for Consumer - Query ParametersOpen Recipe
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'sprofileId
.
- 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
👉Profiles - Search for Consumer - 200 OKOpen Recipe.
👉Profiles - Search for Consumer - 204 No ContentOpen Recipe.
👉Profiles - Search for Consumer - 400 Bad RequestOpen Recipe
4. You're done! Select the consumer profileId
and proceed to Retrieve a Consumer Transaction History API:
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
Field | Type | Required/Optional | Description |
---|---|---|---|
X-MG-ClientRequestId | String | Required | Client 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-ConsumerIPAddress | String | Optional | IP address of the system initiating the session. |
Query Parameters
Field | Type | Required/ Optional | Description |
---|---|---|---|
targetAudience | String | Optional | Tailors 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 |
agentPartnerId | String | Required | Unique agent or partner identifier. |
userLanguage | String | Required | Language used by the user/operator. |
rewardsNumber | String Max length: 20 | Optional | Unique code to apply Loyalty accrual/redemption (MoneyGram Plus Number) |
identificationType | String Max length: 3 | Optional | Type 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 |
identificationNumber | String Max length: 30 | Optional | Identification document number |
mobilePhone | String Min length: 5 Max length: 14 | Optional | Phone Number |
maxProfilesToReturn | String | Optional | The Maximum number of Consumer profiles to return per search request. |
pageNumber | String | Optional | Page number (cursor) returned with search result |
perPage | String | Optional | Number of results to return per page |
Response Fields
Field | Type | Required/ Optional | Description |
---|---|---|---|
profiles.name.firstName | String Min length: 1 Max length: 20 | Required | First Name |
profiles.name.middleName | String Min length: 1 Max length: 20 | Optional | Middle Name (if applicable) |
profiles.name.lastName | String Min length: 1 Max length: 30 | Required | Last Name |
profiles.name.secondLastName | String Min length: 1 Max length: 30 | Optional | Consumer's Second Last Name (if applicable) |
profiles.address.line1 | String Min length: 1 Max length: 30 | Required | Residence address line 1 |
profiles.address.line2 | String Min length: 1 Max length: 30 | Optional | Residence address line 2 (if applicable) |
profiles.address.line3 | String Min length: 1 Max length: 30 | Optional | Residence address line 3 (if applicable) |
profiles.address.city | String Min length: 1 Max length: 20 | Required | City of residence |
profiles.address.countrySubdivision | String Min length: 3 Max length: 3 | Optional | State/province of residence |
profiles.address.countryCode | String Min length: 1 Max length: 30 | Required | Country of residence (ISO Alpha-3 Code) |
profiles.address.postalCode | String Min length: 2 Max length: 10 | Optional | Postal code/ZIP of residence |
profiles.mobilePhone.number | String Min length: 5 Max length: 14 | Required | Phone Number |
profiles.mobilePhone.countryDialCode | String Min length: 1 Max length: 5 | Required | Country calling code NOTE: For country calling code see Reference Data API Module /countries endpoint phoneDialCodes |
profiles.rewardsNumber | String | Optional | Enroll in MoneyGram's Plus Rewards program |
profiles.datOfBirth | String | Required | Date of birth (YYYY-MM-DD |
profiles.profileId | String | Optional | Consumer's unique identifier |
paginationMetadata.totalItems | Number | Optional | Total number of items on all pages |
paginationMetadata.currentPage | Number | Optional | Current page number |
paginationMetadata.perPage | Number | Optional | Page size |
paginationMetadata.totalPages | Number | Optional | Total number of pages |
paginationMetadata.links.pageNumber | Number | Optional | Page number |
paginationMetadata.links.href | String Max Length: 255 | Optional | HATEOS links to data |
Updated 18 days ago