title: Bing search API limit and restricting to single page per domain
body: <p>I've used Bing Search API 7-day trial (Guest) to get search results based on a term.</p>
  <p>I'm using the same code as specified in <a href="https://docs.microsoft.com/en-us/azure/cognitive-services/bing-web-search/quickstarts/php" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/cognitive-services/bing-web-search/quickstarts/php</a> documentation.
  I've added a foreach loop so that I can get the search result for each pages. For my search term I got API search result count <strong>totalEstimatedMatches</strong> as 38500000.</p>
  <p>Below is my code:</p>
  <pre><code>function BingWebSearch ($url, $key, $query, $count=&quot;&quot;, $offset=&quot;&quot;) {
      $headers = &quot;Ocp-Apim-Subscription-Key: $key\r\n&quot;;
      $options = array ('http' =&gt; array (
                            'header' =&gt; $headers,
                             'method' =&gt; 'GET'));
  
      // Perform the request and get a JSON response.
      $context = stream_context_create($options);
      $queryString = &quot;?q=&quot; . urlencode($query);
      if ( strlen(trim($count)) &gt; 0 ) $queryString .= &quot;&amp;count=&quot;.$count;
      if ( strlen(trim($offset)) &gt; 0 ) $queryString .= &quot;&amp;offset=&quot;.$offset;
      $result = file_get_contents($url . $queryString , false, $context);
  
      // Extract Bing HTTP headers.
      $headers = array();
      foreach ($http_response_header as $k =&gt; $v) {
          $h = explode(&quot;:&quot;, $v, 2);
          if (isset($h[1]))
              if (preg_match(&quot;/^BingAPIs-/&quot;, $h[0]) || preg_match(&quot;/^X-MSEdge-/&quot;, $h[0]))
                  $headers[trim($h[0])] = trim($h[1]);
      }
      return array($headers, $result);
  }
  
  $accessKey = 'xxxxxxxxxxxxxxxx';
  $endpoint = 'https://api.cognitive.microsoft.com/bing/v7.0/search';
  $term = 'myserchterm';
  
  $searchOffset = 0;
  $offset = 0;
  $totalEstimatedMatchesCount = 38500000;
  $count = 5000;
  for ( $searchCount=0; $searchCount &lt;= $totalEstimatedMatchesCount; $searchCount = $searchCount+$searchOffset ) {
          $offset = $offset+$searchOffset;
          list($headers, $jsonPageResult) = BingWebSearch($endpoint, $accessKey, $term, $count, $offset);
          $bingSearchPageArray = json_decode($jsonPageResult);
          $searchOffset = count($bingSearchPageArray['webPages']['value']);
          // code to store result to database
          .....................................
  }
  </code></pre>
  <p>This code gave only <strong>930</strong> results and I got email as</p>
  <blockquote>
  <p>You are approaching the quota limit on you subscription to the Bing
  SearchV7 - Free product. This quota will be renewed on 04/09/2020.</p>
  <p>Below are details on quota usage for the subscription:</p>
  <p><strong>Quota Scope</strong>   <strong>Calls</strong>   <strong>Call Quota</strong>  <strong>Bandwidth</strong>   <strong>Bandwidth Quota</strong></p>
  <p>Subscription       2.26k          3.00k            58.48MB</p>
  </blockquote>
  <p>What is the maximum number of API calls I can make? How can I restrict the search only for webpages and only one page per domain(ie, I need to get index page only. I just need the domain based on my search, so no need of getting same domain pages again in the result)?</p>
  <p>Can anyone help me.</p>
  <p>Any help would be appreciated.</p>