Step 3A: Preparing the Request

All requests to the API have to use HTTP GET. No other HTTP methods are supported and will result in a HTTP Error 404. You provide Fyber with the needed information to send you all offers available to your user with this request.

Offer Type Filter (offer_types)

This parameter allows the filtering of offers based on their type, so that only offers matching one or more of the specified categories will be returned. This parameter is optional. More than one offer type can be given as a parameter, concatenated with a comma. For filtering, they will be combined using logical OR.

Request Result
...&offer_types=112&... The Response will contain all offers marked as ‘Free’.
...&offer_types=101,112&... Response will contain all offers marked as ‘Download’ or marked as ‘Free’.

Note

If you want to request all offers except one or more categories (blacklisting), please use the filter configuration in the Fyber Publisher Control Panel.

A list of all available offer_type IDs to use in the request filter is found below.

Offers sorted by the fact that it costs the user something:

offer_type_id Readable Description
112 Free Free offers
103 Sale Shopping offers

Offer sorted by user action:

offer_type_id Readable Description
100 Mobile Mobile subscription offers
101 Download Download offers (from Apple Store)
102 Trial Trial subscription offers
104 Registration Information request offers
105 Registration Registration offers
108 Registration Data Generation offers
110 Surveys Survey offers
111 Dating Dating offers
113 Video Video offers
114 Rewarded Action Rewarded action offers

Download offers sorted by gaming category (if applicable):

offer_type_id Readable Description
106 Games Gaming offers
107 Games Gambling offers
109 Games Skill Game offers

Note

One offer will match multiple categories, e.g. one offer can be an app to download from the Apple Store as well as a free skill game.

Hashkey Calculation

This hash key must be generated by the device itself and must follow strict rules:

  1. Get all request parameters and their values (except hashkey).
  2. Order theses pairs alphabetically by parameter name.
  3. Concatenate all pairs using = between key and value and & between the pairs.
  4. Concatenate the resulting string with & and the API Key given to you by Fyber.
  5. Hash the whole resulting string, using SHA1. The resulting hashkey is then appended to the request as a separate parameter.

If some parameters must be url-encoded, the entire hash calculation has to be done before this encoding. 

Example

Here's an example of the process:

  1. Gather all request parameters, except the hashkey.

  2. Gather all request parameters:

    • appid = 157
    • google_ad_id=a0b0c0d0-a0b0-c0d0-e0f0-a0b0c0d0e0f0
    • google_ad_id_limited_tracking_enabled=true
    • ip = 212.45.111.17
    • locale = de
    • page = 2
    • pub0 = campaign2
    • timestamp = 1312553361
    • uid = player1
  3. Concatenate all request parameters.

  • Result Step 3
appid=157&google_ad_id=a0b0c0d0-a0b0-c0d0-e0f0-a0b0c0d0e0f0&google_ad_id_limited_tracking_enabled=true&ip=212.45.111.17&locale=de&page=2&pub0=campaign2&timestamp=1312553361&uid=player1
  1. Concatenate the resulting string with your API Key.

Using your API Key: e95a21621a1865bcbae3bee89c4d4f84

  • Result Step 4
appid=157&google_ad_id=a0b0c0d0-a0b0-c0d0-e0f0-a0b0c0d0e0f0&google_ad_id_limited_tracking_enabled=true&ip=212.45.111.17&locale=de&page=2&pub0=campaign2&timestamp=1312553361&uid=player1&e95a21621a1865bcbae3bee89c4d4f84
  1. Hash the resulting string using SHA1.
  • Result Step 5
68fc8e87db598e2149b4f72379fc2efd69309787

Note

The Mobile Offer API expects the hashkey to be in lower case.

The complete request URL to Fyber’s Mobile Offer API for these parameters would then look like this:

  • FINAL RESULT
http://api.fyber.com/feed/v1/offers.json?appid=157&google_ad_id=a0b0c0d0-a0b0-c0d0-e0f0-a0b0c0d0e0f0&google_ad_id_limited_tracking_enabled=true&ip=212.45.111.17&locale=de&page=2&pub0=campaign2&timestamp=1585187676&uid=player1&hashkey=68fc8e87db598e2149b4f72379fc2efd69309787

Example implementation of the code in Ruby

  • Ruby
require 'digest/sha1'

api_key = 'e95a21621a1865bcbae3bee89c4d4f84' # your Fyber API key for the application
params = 'appid=157&google_ad_id=a0b0c0d0-a0b0-c0d0-e0f0-a0b0c0d0e0f0&google_ad_id_limited_tracking_enabled=true&ip=212.45.111.17&locale=de&pub0=campaign2&timestamp=1312553361&uid=player1' # request params
page = 2

params = params.split('&').each_with_object({}) do |item, memo|
  key, value = item.split('=')
  memo[key] = value
end

def to_query(hash)
  hash.to_a.map { |item| item.join('=') }.join('&')
end

params.delete('hashkey')
params['timestamp'] = Time.now.to_i.to_s
params['page'] = page

params = params.sort.to_h # sort by key name
hashkey = Digest::SHA1.hexdigest("#{to_query(params)}&#{api_key}")

url = "http://api.fyber.com/feed/v1/offers.json?#{to_query(params)}&hashkey=#{hashkey}"

 

Note

To avoid displaying potentially expired offers to the user, please try to keep requests as close to realtime as possible.

Improving Response Times

To optimize the communication between servers, dramatically reduce response times and improve the user experience, we recommend the following:

  • Enable Keep-Alive for all requests.
  • Enable compression of the response using Accept-Encoding: gzip headers.

Let's continue to Preparing the Response.