API:Contain
From HasOffers
When passed in, the contain parameter allows you to bind additional objects to the current element(s) in the result set. For example, when retrieving an advertiser and their associated account manager, you may use contain to bind the account manager to the advertiser.
Contents |
Parameters
- filters [optional] - Conditional requirements to filter the results.
- Values: (array)
- fields [optional] - Fields of each object to include in the results.
- Values: (array)
Basic Usage Example
<?php $base = 'https://api.hasoffers.com/Api?'; $params = array( 'Format' => 'json' ,'Target' => 'Advertiser' ,'Method' => 'findById' ,'Service' => 'HasOffers' ,'Version' => 2 ,'NetworkId' => 'my-network-id' ,'NetworkToken' => 'my-api-key' ,'contain' => array( 'AccountManager' ) ,'id' => 9 ); $url = $base . http_build_query( $params ); $result = file_get_contents( $url ); echo '<pre>'; print_r( json_decode( $result ) ); echo '</pre>'; ?>
Response
response: {
status: 1
data: {
Advertiser: {
id: "9"
source_brand_id: "20"
company: "Acme, Inc"
address1: "123 Main ST"
address2: "St 106"
city: "Seattle"
region: "WA"
country: "US"
other: null
zipcode: "9105"
phone: "425-555-9876"
fax: null
website: null
date_added: "2010-04-07 20:30:59"
modified: 1271690152
signup_ip: "69.232.55.87"
status: "active"
wants_alerts: "1"
account_manager_id: "3"
network_map_id: null
method: null
payment_terms: null
account_id: "75800"
}
AccountManager: {
id: "3"
email: "demo@hasoffers.com"
first_name: "John"
last_name: "Smith"
phone: "206.555.1234"
cell_phone: "206.508.1318"
title: "Senior Consultant"
aim: null
photo: null
join_date: "2010-03-26 11:43:56"
last_login: null
permissions: "2359264"
modified: 1273635169
wants_alerts: "1"
status: "active"
user_id: "1"
access: [
"Brand"
"Brand.stats"
"Brand.billing"
"Brand.offer_management"
"Brand.affiliate_management"
"Brand.lead_management"
"Brand.global_management"
"Brand.brand_management"
"Brand.virtual_user"
"Brand.file_management"
"Brand.dne_management"
"Brand.employee_management"
"Brand.advertiser_management"
]
is_creator: false
}
}
}
In addition to using contain, you may also specify which fields should be included in the result set of the associated object, as well as conditional filters to limit the results. If we look at our previous example, we can slim down the result object for the account manager by adding the fields parameter inside of the contain parameter.
Advanced Usage Example
<?php $base = 'https://api.hasoffers.com/Api?'; $params = array( 'Format' => 'json' ,'Target' => 'Advertiser' ,'Method' => 'findById' ,'Service' => 'HasOffers' ,'Version' => 2 ,'NetworkId' => 'my-network-id' ,'NetworkToken' => 'my-api-key' ,'contain' => array( 'AccountManager' => array( 'fields' => array( 'first_name', 'last_name' ) ,'filters' => array( 'status' => 'active' ) ) ) ,'id' => 9 ); $url = $base . http_build_query( $params ); $result = file_get_contents( $url ); echo '<pre>'; print_r( json_decode( $result ) ); echo '</pre>'; ?>
Response
response: {
status: 1
data: {
Advertiser: {
id: "9"
source_brand_id: "20"
company: "Acme, Inc"
address1: "123 Main ST"
address2: "St 106"
city: "Seattle"
region: "WA"
country: "US"
other: null
zipcode: "9105"
phone: "425-555-9876"
fax: null
website: null
date_added: "2010-04-07 20:30:59"
modified: 1271690152
signup_ip: "69.232.55.87"
status: "active"
wants_alerts: "1"
account_manager_id: "3"
network_map_id: null
method: null
payment_terms: null
account_id: "75800"
}
AccountManager: {
id: "3"
first_name: "John"
last_name: "Smith"
}
}
}
Email this page to a friend or co-worker