### Making a GET Request to the Product API (Ruby) Source: https://docs.diffbot.com/reference/product-intro This Ruby example shows how to retrieve product data from a URL using the Diffbot Product API. It employs the 'net/http' library to perform the GET request and parse the JSON response. ```ruby require 'net/http' require 'uri' require 'json' uri = URI.parse('https://api.diffbot.com/v3/product?url=https%3A%2F%2Fwww.microcenter.com%2Fproduct%2F628738%2Fevga-nvidia-geforce-rtx-3090-ftw3-ultra-triple-fan-24gb-gddr6x-pcie-40-graphics-card') request = Net::HTTP::Get.new(uri) request['accept'] = 'application/json' response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request(request) end if response.code == '200' puts JSON.parse(response.body) else puts "Error: #{response.code}" end ``` -------------------------------- ### Making a GET Request to the Product API (Shell) Source: https://docs.diffbot.com/reference/product-intro This example demonstrates how to make a basic GET request to the Diffbot Product API using cURL. It specifies the target URL for product extraction and sets the 'accept' header to 'application/json'. ```shell curl --request GET \ --url 'https://api.diffbot.com/v3/product?url=https%3A%2F%2Fwww.microcenter.com%2Fproduct%2F628738%2Fevga-nvidia-geforce-rtx-3090-ftw3-ultra-triple-fan-24gb-gddr6x-pcie-40-graphics-card' \ --header 'accept: application/json' ``` -------------------------------- ### Making a GET Request to the Product API (Python) Source: https://docs.diffbot.com/reference/product-intro This Python example illustrates how to interact with the Diffbot Product API to extract product information. It uses the 'requests' library to send a GET request and prints the JSON response. ```python import requests url = 'https://api.diffbot.com/v3/product?url=https%3A%2F%2Fwww.microcenter.com%2Fproduct%2F628738%2Fevga-nvidia-geforce-rtx-3090-ftw3-ultra-triple-fan-24gb-gddr6x-pcie-40-graphics-card' headers = { 'accept': 'application/json' } response = requests.get(url, headers=headers) if response.status_code == 200: print(response.json()) else: print(f'Error: {response.status_code}') ``` -------------------------------- ### Making a GET Request to the Product API (PHP) Source: https://docs.diffbot.com/reference/product-intro This PHP example demonstrates how to fetch product details from a URL using the Diffbot Product API. It uses cURL to make the HTTP request and decodes the JSON response. ```php ``` -------------------------------- ### Making a GET Request to the Product API (Node.js) Source: https://docs.diffbot.com/reference/product-intro This Node.js example shows how to fetch product data from a given URL using the Diffbot Product API. It utilizes the 'node-fetch' library to make the HTTP request and handles the JSON response. ```javascript const fetch = require('node-fetch'); const url = 'https://api.diffbot.com/v3/product?url=https%3A%2F%2Fwww.microcenter.com%2Fproduct%2F628738%2Fevga-nvidia-geforce-rtx-3090-ftw3-ultra-triple-fan-24gb-gddr6x-pcie-40-graphics-card'; fetch(url, { method: 'GET', headers: { 'accept': 'application/json' } }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error(error)); ``` -------------------------------- ### Customer Data Example Source: https://docs.diffbot.com/docs/ont-organization Provides an example of customer data, including their summary, image URL, types, name, Diffbot URI, and target Diffbot ID. This is useful for understanding how customer entities are represented. ```json { "customers": [ { "summary": "American multinational technology company, a subsidiary of Alphabet Inc.", "image": "https://kg.diffbot.com/image/api/get?fetch=yes&url=g%3Cj7P0St0DnBJf.x0KwLZrUn.%5B%3CR0Aa4Hh%3B%5Bv738ZqOr7U%3FcvBT%3El%5D%3BTo1YMa%7B%5DX%7BGmF.yZl", "types": [ "Organization", "Corporation", "Company", "OrganizationInvestor" ], "name": "Google", "diffbotUri": "http://diffbot.com/entity/EUFq-3WlpNsq0pvfUYWXOEA", "targetDiffbotId": "EUFq-3WlpNsq0pvfUYWXOEA", "type": "Organization" }, { "summary": "American multinational technology company based in Cupertino, California", "image": "https://kg.diffbot.com/image/api/get?fetch=yes&url=g%3Cj7P0St0DnBJf.x0KwLZrUn.%5B%3CR0Aa4Hh%3B%5Bv738ZqOr7U%3FGvvO%3Ef%5E%3CYh%7Bf%3AHi7%5B%7B9iB.yZl", "types": [ "Organization", "Corporation", "Company", "OrganizationInvestor" ], "name": "Apple Inc.", "diffbotUri": "http://diffbot.com/entity/EHb0_0NEcMwyY8b083taTTw", "targetDiffbotId": "EHb0_0NEcMwyY8b083taTTw", "type": "Organization" }, { "summary": "American multinational technology company", "image": "https://kg.diffbot.com/image/api/get?fetch=yes&url=g%3Cj7P0St0DnBJf.x0KwLZrUn.%5B%3CR0Aa4Hh%3B%5Bv738ZqOr7U%3FBvqw%3Ef%5B%7Dgr%3AY7PaG.2Nm", "types": [ "Organization", "Corporation", "Company", "OrganizationInvestor" ], "name": "Amazon", "diffbotUri": "http://diffbot.com/entity/EU2HJUnMcNoWE3nR1cGBcZg", "targetDiffbotId": "EU2HJUnMcNoWE3nR1cGBcZg", "type": "Organization" } ] } ``` -------------------------------- ### Example JSON for Entity Origins Source: https://docs.diffbot.com/docs/getting-started-with-diffbot-knowledge-graph This JSON snippet illustrates the 'origins' field of an organization entity in the Diffbot Knowledge Graph. It shows a list of URLs from which data for the entity was derived, demonstrating the provenance of the information. ```json { "origins": [ "seekingalpha.com/article/4501445-apple-losses-mount-in-a-big-money-pit#efficiens", "appleinsider.com/articles/22/02/28/qualcomm-promises-lossless-bluetooth-audio-with-new-chipset#efficiens", "lmd.lk/schoolchildren-in-china-work-overnight-to-produce-amazon-alexa-devices#efficiens", "guardian.co.uk/media/2010/nov/18/apple-iad-mobile-advertising#efficiens", "theguardian.com/world/2022/mar/13/china-shuts-down-business-centres-in-bid-to-halt-covid-outbreak#efficiens", ... ] } ``` -------------------------------- ### GET /v3/event - Example Request (cURL) Source: https://docs.diffbot.com/reference/event-intro Example cURL request to demonstrate how to use the Event API to extract content from a URL. ```APIDOC ## GET /v3/event (Example cURL) ### Description This is an example cURL request to fetch event data from a specific URL using the Diffbot Event API. ### Method GET ### Endpoint `/v3/event` ### Parameters #### Query Parameters - **url** (string) - Required - The target URL to extract content from. ### Request Example ```bash curl --request GET \ --url 'https://api.diffbot.com/v3/event?url=https%3A%2F%2Fwww.eventbrite.com%2Fe%2Fgraphql-summit-2018-tickets-46601841362' \ --header 'accept: application/json' ``` ### Response #### Success Response (200) - **response** (object) - The API response containing extracted content. #### Response Example ```json { "response": { "url": "https://www.eventbrite.com/e/graphql-summit-2018-tickets-46601841362", "status": "success", "data": { "type": "event", "title": "GraphQL Summit 2018", "venue": { "name": "The Design Center" } } } } ``` #### Error Response (500) - **error** (object) - Details about the internal server error. ``` -------------------------------- ### IPO Information Example Source: https://docs.diffbot.com/docs/ont-organization Demonstrates the structure for Initial Public Offering (IPO) information. It includes the IPO date and the stock exchange where the company is listed. ```json { "ipo": { "date": { "str": "d1978-01-13", "precision": 3, "timestamp": 253497600000 }, "stockExchange": "New York Stock Exchange (NYSE)" } } ``` -------------------------------- ### Simple Paths (AND Queries) Source: https://docs.diffbot.com/docs/simple-nested-paths Demonstrates how to perform AND queries by separating multiple field-value pairs with spaces. All conditions must match for an entity to be returned. ```APIDOC ## Simple Paths (AND Queries) ### Description Queries with multiple search clauses (fields) separated by spaces imply an AND operation. All specified conditions must be met for an entity to be returned. ### Method GET ### Endpoint /search/ ### Query Parameters - **query** (string) - Required - The DQL query string. ### Request Example ``` GET /search/?query=type:Organization locations.city.name:"San Francisco" nbEmployees>5000 ``` ### Response #### Success Response (200) - **results** (array) - A list of entities matching the query. - **total** (integer) - The total number of matching entities. #### Response Example ```json { "results": [ { "type": "Organization", "name": "Example Corp", "nbEmployees": 6000, "locations": [ { "city": { "name": "San Francisco" } } ] } ], "total": 1 } ``` ``` -------------------------------- ### Event API cURL Request Example Source: https://docs.diffbot.com/reference/event-intro This example shows a cURL command to make a GET request to the Diffbot Event API, specifying a target URL for content extraction. It includes the necessary URL and header for the request. ```Shell curl --request GET \ --url 'https://api.diffbot.com/v3/event?url=https%3A%2F%2Fwww.eventbrite.com%2Fe%2Fgraphql-summit-2018-tickets-46601841362' \ --header 'accept: application/json' ``` -------------------------------- ### Manually Run Python Price Tracker Source: https://docs.diffbot.com/docs/tutorial-a-tiny-zero-dependency-price-tracker This bash command demonstrates how to manually execute the Python price tracker script. It requires the 'python3' interpreter and specifies the product URL and the target price as command-line arguments. ```bash $ python3 dealer.py --url 'https://www.abercrombie.com/shop/us/p/camp-collar-cropped-summer-linen-blend-shirt-56703828?categoryId=12204&faceout=model&seq=01' --price 50 ``` -------------------------------- ### PHP Example for DQL Search Source: https://docs.diffbot.com/reference/dql-search This PHP example demonstrates how to make a GET request to the DQL search API using cURL. It sets the URL with query parameters and the 'accept' header. ```php ``` -------------------------------- ### Python Example for DQL Search Source: https://docs.diffbot.com/reference/dql-search This Python example utilizes the 'requests' library to perform a GET request to the DQL search API. It demonstrates how to pass query parameters and headers for the request. ```python import requests url = 'https://kg.diffbot.com/kg/v3/dql' params = { 'type': 'query', 'col': 'all', 'from': 0, 'size': 50, 'format': 'json', 'jsonmode': 'extended', 'nonCanonicalFacts': 'false', 'noDedupArticles': 'false', 'cluster': '', 'report': 'false' } headers = { 'accept': 'application/json' } response = requests.get(url, params=params, headers=headers) if response.status_code == 200: print(response.json()) else: print(f'Error: {response.status_code}') ``` -------------------------------- ### Create a CLI Price Tracker with Diffbot Extract (Python) Source: https://docs.diffbot.com/docs/tutorial-a-tiny-zero-dependency-price-tracker This Python script implements a command-line interface (CLI) for the price tracker. It uses the `argparse` module to accept a product URL and an optional target price as arguments. The script then fetches product details using Diffbot Extract, compares the price, and outputs the result. It relies on standard Python libraries and a Diffbot API token. ```python import urllib.parse import urllib.request import json import argparse # Parse CLI Arguments parser = argparse.ArgumentParser("deal") parser.add_argument("--url", help="Product page URL", required=True) parser.add_argument("--price", help="Price at or below which you'd like to target", type=int) args = parser.parse_args() TOKEN = "YOUR-DIFFBOT-TOKEN" product = args.url target_price = args.price or 99999 # Build Diffbot Extract Call url = f"https://api.diffbot.com/v3/product?token={TOKEN}&url={urllib.parse.quote(product)}" # Extract Product Pricing with urllib.request.urlopen(url) as response: data = json.load(response) extracted_product = data['objects'][0] title = extracted_product.get('title') offer_price = extracted_product.get('offerPriceDetails', {}).get('amount') offer_symbol = extracted_product.get('offerPriceDetails', {}).get('symbol') if offer_price < target_price: print(f"SALE: {offer_symbol}{offer_price} — {title}") else: print(f"{offer_symbol}{offer_price} — {title}") ``` -------------------------------- ### Extract Data using GET Request with Authentication Source: https://docs.diffbot.com/reference/authentication This example demonstrates how to authenticate a GET request to the Diffbot Analyze API. It requires a Diffbot API token and a URL to analyze. The response is returned in JSON format. ```curl curl --request GET \ --url 'https://api.diffbot.com/v3/analyze?token=YOURDIFFBOTTOKEN&url=https%3A%2F%2Fdocs.diffbot.com' \ --header 'accept: application/json' ``` -------------------------------- ### Tasks List Example (JSON) Source: https://docs.diffbot.com/docs/ont-jobpost This snippet shows the format for a list of tasks associated with a job post. Each task is a string describing a responsibility. ```json { "tasks": [ "Improve accuracy of our production machine learning systems by applying the latest published research, feature engineering, and tuning of model hyperparameters", "Own end-to-end accuracy and performance for our 60+ machine learning problems", "Be up to date on the latest research publications, and rapidly assess the latest results for production and scalability potential" ] } ``` -------------------------------- ### Example Request for Optional Fields using Curl Source: https://docs.diffbot.com/reference/extract-optional-fields This example demonstrates how to make a GET request to the Diffbot analyze API, specifying the 'links' field to retrieve hyperlinks from a given URL. It requires a valid API token. ```curl curl --request GET \ --url 'https://api.diffbot.com/v3/analyze?url=https%3A%2F%2Fwww.diffbot.com&fields=links&token=' --header 'Accept: application/json' ``` -------------------------------- ### Make a GET Request to Custom API (cURL) Source: https://docs.diffbot.com/docs/custom This snippet demonstrates how to make a GET request to the Diffbot Custom API using cURL. It specifies the API endpoint and includes a header for JSON response acceptance. This is a basic example for initiating an extraction. ```shell curl --request GET \ --url https://api.diffbot.com/v3/api \ --header 'accept: application/json' ``` -------------------------------- ### Get Organization Successors (JSON) Source: https://docs.diffbot.com/docs/ont-organization Retrieves a list of successor organizations formed through consolidation, merger, or amalgamation. The example shows the structure for this LinkedEntity type, though specific details may be empty. ```json { "successors": [ { "summary": "", "image": "", "images": [ { "classifications": "", "fingerprint": "", "title": "", "isCached": false, "url": "" } ], "types": "", "diffbotUri": "", "name": "" } ] } ``` -------------------------------- ### Search Products by Title, Price Range, and Pagination Source: https://docs.diffbot.com/reference/search This example demonstrates searching for the second page of 20 products with 'Nike' in the title, priced between $40 and $50, from the 'shoestores' collection. It utilizes 'type:product', 'title:nike', 'min:offerPrice:40', 'max:offerPrice:50', 'col:shoestores', and 'start:20'. ```text https://api.diffbot.com/v3/search?token=...&col=shoestores&start=20query=type%3Aproduct%20title%3Anike%20min%3AofferPrice%3A40%20max%3AofferPrice%3A50 ``` -------------------------------- ### Diffbot for Google Sheets Add-on Source: https://docs.diffbot.com/docs/google-sheets-integration This section details how to install and log in to the Diffbot for Google Sheets Add-on, and provides an example of using the DQL custom function. ```APIDOC ## Diffbot for Google Sheets Add-on ### Description Instantly populate your spreadsheet with data on people, organizations, articles and more from the Diffbot Knowledge Graph. The Diffbot for Google Sheets Add-on allows you to leverage the power of the Diffbot Knowledge Graph from within Google Sheets. ### Installation 1. Visit the [Diffbot for Sheets listing in the G Suite Marketplace](https://gsuite.google.com/marketplace/app/diffbot_for_sheets/457377215857). 2. Click 'Install', choose your Google account, and grant permissions. ### Quick Start 1. Open a blank Google Sheet. 2. Go to the Add-ons menu and select 'Diffbot for Sheets' > 'Login to Diffbot'. 3. Enter your Diffbot API token (obtainable from [https://app.diffbot.com/get-started](https://app.diffbot.com/get-started)). ### Using the DQL Custom Function #### Description The `DQL` custom function allows you to query the Diffbot Knowledge Graph using Diffbot Query Language (DQL). #### Syntax `=DQL("dql_query", "fields", [size])` - **dql_query** (string) - Required - The DQL query to search the Knowledge Graph. - **fields** (string) - Required - Comma-separated list of fields to retrieve. - **size** (integer) - Optional - The maximum number of entities to return. #### Example To find the homepage, location, and number of employees for an organization named 'Diffbot': ```excel =DQL("type:Organization name:'Diffbot'", "name,location,employees") ``` ### Response Example (for the above query) ```json { "objects": [ { "name": "Diffbot", "location": "San Francisco, California, United States", "employees": 50 } ] } ``` ``` -------------------------------- ### Free-text Search Examples in DQL Source: https://docs.diffbot.com/docs/search-a-crawlbulk-job Demonstrates how to perform free-text searches in DQL. These queries return objects where specified terms or phrases appear in any Diffbot-extracted fields. Exact phrase matching is supported. ```dql "computer vision" ``` ```dql "web page analysis" ``` -------------------------------- ### Regex Operator Usage Source: https://docs.diffbot.com/docs/regex-operator-1 This section details how to use the 're' operator to apply regular expressions for matching string field values. It includes an example of searching for Organization entities with names starting with 'Faceb'. ```APIDOC ## Regex Operator ### Description The **re** (regex) operator allows you to use regular expressions to match the value of a string field. Diffbot supports [ElasticSearch's regular expression syntax](https://www.elastic.co/guide/en/elasticsearch/reference/current/regexp-syntax.html). ### Method GET ### Endpoint /search ### Query Parameters - **query** (string) - Required - The search query string, which can include the regex operator. ### Request Example ``` GET /search?query=type:Organization re:name:"faceb.+" ``` ### Response #### Success Response (200) - **objects** (array) - A list of matching entities. - **next** (string) - A URL for the next page of results, if available. #### Response Example ```json { "objects": [ { "@type": "Organization", "name": "Facebook, Inc.", "diffbotUri": "http://www.facebook.com" }, { "@type": "Organization", "name": "Facebot", "diffbotUri": "http://example.com/facebot" } ], "next": "/search?query=type:Organization+re:name:\"faceb.+%2B%22&page=2" } ``` ``` -------------------------------- ### Company Stock Information Example Source: https://docs.diffbot.com/docs/ont-organization This example shows the JSON structure for company stock information, including the stock symbol, whether it's current, the exchange it's traded on, and the date it became available. ```json { "stock": { "symbol": "IBM", "isCurrent": true, "exchange": "New York Stock Exchange (NYSE)", "from": { "str": "d1962-01-02", "precision": 3, "timestamp": -252374400000 } } } ``` -------------------------------- ### Querying for Keywords Source: https://docs.diffbot.com/docs/creating-effective-queries This example shows how to build a query using keywords to find relevant articles, including options for title and text matching. ```APIDOC ## Querying for Keywords ### Description This endpoint allows you to search for articles based on specific keywords found in their title or text content. ### Method GET ### Endpoint /search/ ### Query Parameters - **query** (string) - Required - The search query string. For keyword queries, use the format `type:Article or(title:"", text:"") sortBy:date`. ### Request Example ``` https://app.diffbot.com/search/?query=type%3AArticle+or(title%3A%22robotic+process+automation%22%2C+text%3A%22robotic+process+automation%22)+sortBy%3Adate ``` ### Response #### Success Response (200) - **results** (array) - A list of articles matching the query. - **total** (integer) - The total number of results found. #### Response Example ```json { "results": [ { "title": "Another Example Article", "url": "http://example.com/another-article", "date": "2023-10-26T15:30:00Z" } ], "total": 150 } ``` ``` -------------------------------- ### Get nbOrigins Count (JSON) Source: https://docs.diffbot.com/docs/ont-all-entities Retrieves the total number of origins for a given entity. This field is only available in extended JSON mode. The example shows a JSON object with the nbOrigins field. ```json { "nbOrigins": 0 } ``` -------------------------------- ### Search Articles by Author, Site, and Date Order Source: https://docs.diffbot.com/reference/search This example demonstrates searching for 100 articles written by 'Bill Simmons' on 'Grantland.com' from the 'sports' collection, ordered by oldest first. It uses 'author:"Bill Simmons"', 'site:grandland.com', 'revsortby:date', and 'col:sports'. ```text https://api.diffbot.com/v3/search?token=...&num=100&col=sports&query=type%3Aarticle%20author%3A%22Bill%20Simmons%22%20site%3Agrandland.com%20revsortby%3Adate ``` -------------------------------- ### Product Diffbot URI Example (JSON) Source: https://docs.diffbot.com/docs/ont-product Shows an example of 'diffbotUri', a unique identifier for the entity within Diffbot's system, formatted as a URL. This field is a String. ```json { "diffbotUri": "http://diffbot.com/entity/PRD140579625275" } ``` -------------------------------- ### Define Date Facet Ranges (Week) Source: https://docs.diffbot.com/docs/facet-queries Specify time intervals for date field faceting using 'day', 'week', or 'month' specifiers. This example shows how to get a weekly breakdown of articles related to 'hacking'. ```diffbot type:Article title:"hacking" facet[week]:date ``` -------------------------------- ### GET /websites/diffbot/bulkjobs/{jobId} Source: https://docs.diffbot.com/reference/bulkjobstatus Retrieves the status of a specific bulkjob. This includes information such as submission time, start time, completion time, total results, file size, and a list of generated reports. ```APIDOC ## GET /websites/diffbot/bulkjobs/{jobId} ### Description Retrieves the status of a specific bulkjob. This endpoint provides details about the job's progress and any generated reports. ### Method GET ### Endpoint `/websites/diffbot/bulkjobs/{jobId}` ### Parameters #### Path Parameters - **jobId** (string) - Required - The unique identifier for the bulkjob. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **jobId** (integer) - The unique identifier for the bulkjob. - **submitTimeMs** (integer) - The timestamp when the bulkjob was submitted (in milliseconds). - **startTimeMs** (integer) - The timestamp when the bulkjob started processing (in milliseconds). - **completedTimeMs** (integer) - The timestamp when the bulkjob completed processing (in milliseconds). - **totalResults** (integer) - The total number of results generated by the bulkjob. - **fileSizeBytes** (integer) - The size of the download file in bytes. - **reports** (array) - An array of report objects generated for this bulkjob. - **reportId** (string) - The unique identifier for the report. - **status** (string) - The status of report generation. One of {NOT_STARTED, IN_PROCESS, EXPORTING, COMPLETE, COMPLETE_WITH_FAILURES, STOPPED, ERROR_FINALIZING, ERROR_SCHEDULING, UNKNOWN}. - **format** (string) - The export format of the report. - **spec** (string) - The export specification defining the columns for CSV, XLS, and XLSX formats. - **exportfile** (string) - The name of the exported file. - **exportSeparator** (string) - The separator used for multi-value fields in columnar exports. - **filter** (string) - A path filter to select specific data from the JSON response. - **onlyMatches** (boolean) - Indicates whether to return only records that have a match. #### Response Example ```json { "jobId": 12345, "submitTimeMs": 1678886400000, "startTimeMs": 1678886460000, "completedTimeMs": 1678887000000, "totalResults": 1000, "fileSizeBytes": 500000, "reports": [ { "reportId": "report-abc-123", "status": "COMPLETE", "format": "csv", "spec": "name;summary", "exportfile": "job_12345_report_abc_123.csv", "exportSeparator": ";", "filter": "$.name;$.summary", "onlyMatches": false } ] } ``` #### Error Response (401) - **description**: Token not specified or other client errors. - **content**: application/json - **schema**: StatusResponseError ``` -------------------------------- ### Example HTML Response for Product API Source: https://docs.diffbot.com/reference/normalized-html-fields This HTML snippet demonstrates a typical response from Diffbot's Product API, showcasing how product information is presented. It includes links to the API, Crawlbot, and contact information. ```html

Diffbot's human wranglers are proud today to announce the release of our newest product: an API for... products!

The Product API can be used for extracting clean, structured data from any e-commerce product page. It automatically makes available all the product data you'd expect: price, discount/savings amount, shipping cost, product description, any relevant product images, SKU and/or other product IDs.

Even cooler: pair the Product API with Crawlbot, our intelligent site-spidering tool, and let Diffbot determine which pages are products, then automatically structure the entire catalog. Here's a quick demonstration of Crawlbot at work:

We've developed the Product API over the course of two years, building upon our core vision technology that's extracted structured data from billions of web pages, and training our machine learning systems using data from tens of thousands of unique shopping sites. We can't wait for you to try it out.

What are you waiting for? Check out the Product API and dive on in! Get a trial token here.

Questions? Hit us up at support@diffbot.com.

``` -------------------------------- ### Compare Product Price to Target Price using Diffbot Extract (Python) Source: https://docs.diffbot.com/docs/tutorial-a-tiny-zero-dependency-price-tracker This Python code snippet extends the previous example by extracting the product title and offer price from the Diffbot API response. It then compares the extracted offer price against a predefined target price and prints a message indicating whether a 'SALE' is active or not. This requires a Diffbot token, product URL, and a target price. ```python import urllib.parse import urllib.request import json TOKEN = "YOUR-DIFFBOT-TOKEN" product = "https://www.abercrombie.com/shop/us/p/camp-collar-cropped-summer-linen-blend-shirt-56703828?categoryId=12204&faceout=model&seq=01" target_price = 25 url = f"https://api.diffbot.com/v3/product?token={TOKEN}&url={urllib.parse.quote(product)}" with urllib.request.urlopen(url) as response: data = json.load(response) extracted_product = data['objects'][0] title = extracted_product.get('title') offer_price = extracted_product.get('offerPriceDetails', {}).get('amount') offer_symbol = extracted_product.get('offerPriceDetails', {}).get('symbol') if offer_price < target_price: print(f"SALE: {offer_symbol}{offer_price} — {title}") else: print(f"No Deal: {offer_symbol}{offer_price} — {title}") ``` -------------------------------- ### Product Availability Example (JSON) Source: https://docs.diffbot.com/docs/ont-product Demonstrates the 'availability' field for a product entity, indicating whether the product is currently available. This is a boolean field. ```json { "availability": false } ``` -------------------------------- ### Ruby Example for DQL Search Source: https://docs.diffbot.com/reference/dql-search This Ruby snippet shows how to make a GET request to the DQL search API using the 'net/http' library. It constructs the URL with parameters and sets the necessary headers. ```ruby require 'net/http' require 'uri' uri = URI.parse('https://kg.diffbot.com/kg/v3/dql') params = { 'type' => 'query', 'col' => 'all', 'from' => '0', 'size' => '50', 'format' => 'json', 'jsonmode' => 'extended', 'nonCanonicalFacts' => 'false', 'noDedupArticles' => 'false', 'cluster' => '', 'report' => 'false' } uri.query = URI.encode_www_form(params) request = Net::HTTP::Get.new(uri.request_uri) request['accept'] = 'application/json' response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http| http.request(request) end puts response.body ``` -------------------------------- ### Product GTIN Example (JSON) Source: https://docs.diffbot.com/docs/ont-product Shows an example of the 'gtin' field, representing the Global Trade Item Number for the product. This field is a String. ```json { "gtin": "" } ``` -------------------------------- ### Combine Person/Organization Record (Ruby) Source: https://docs.diffbot.com/reference/combine This Ruby example utilizes the 'httparty' gem to perform a GET request to the Diffbot Combine API. It demonstrates setting up the request URL and headers for entity enhancement. ```ruby require 'httparty' response = HTTParty.get('https://kg.diffbot.com/kg/v3/enhance/combine', headers: { 'accept' => 'application/json' }) puts response.body ``` -------------------------------- ### Get nbIncomingEdges Count (JSON) Source: https://docs.diffbot.com/docs/ont-all-entities Retrieves the count of incoming edges for an entity in the Knowledge Graph. This represents the number of connections pointing to the entity from other entities. The example shows a JSON object with the nbIncomingEdges field. ```json { "nbIncomingEdges": 0 } ```