Get Subgraph

Returns a subgraph based on a set of nodes that you provide.

The Get Subgraph API returns a subgraph based on a set of nodes that you provide, including all the edges that occur between these nodes in the main graph.

Quick Start

The following example returns the subgraph for the pages 'Germany' and 'France'.

POST /1/api/[async|sync]/getsubgraph/v1?node_names=Germany,France

The API returns the nodes from the query, and the edges that exist between them in the main graph. Note that the node ids in the subgraph are different to their ids in the main graph.

{
  "nodes": [
    {
      "id": 0,
      "attributes": {
        "name": "Germany"
      }
    },
    {
      "id": 1,
      "attributes": {
        "name": "France"
      }
    }
  ],
  "edges": [
    {
      "source": 0,
      "target": 1,
      "attributes": {
        "weight": 0.0178170726
      }
    },
    {
      "source": 1,
      "target": 0,
      "attributes": {
        "weight": 0.0178170726
      }
    }
  ]
}
Synchronous
https://api.havenondemand.com/1/api/sync/getsubgraph/v1
Asynchronous
https://api.havenondemand.com/1/api/async/getsubgraph/v1
Authentication

This API requires an authentication token to be supplied in the following parameter:

Parameter Description
apikey The API key to use to authenticate the API request.
Parameters

This API accepts the following parameters:

Optional
Name Type Description
graph
enum The graph you want to query. Default value: wiki_eng.
node_ids
array<number> The IDs of the nodes to return the subgraph for.
node_names
array<string> The names of nodes to return the subgraph for. You must percent-encode the node names.
Enumeration Types

This API's parameters use the enumerations described below:

graph
The graph you want to query.
wiki_eng English Wikipedia
Graph where the nodes come from English Wikipedia pages

This API returns a JSON response that is described by the model below. This single model is presented both as an easy to read abstract definition and as the formal JSON schema.

Asynchronous Use

Additional requests are required to get the result if this API is invoked asynchronously.

You can use /1/job/status/<job-id> to get the status of the job, including results if the job is finished.

You can also use /1/job/result/<job-id>, which waits until the job has finished and then returns the result.

Model
This is an abstract definition of the response that describes each of the properties that might be returned.
Get Subgraph Response {
edges ( array[Edges] , optional)
nodes ( array[Nodes] , optional)
}
Get Subgraph Response:Edges {
attributes ( Attributes )
source ( integer ) Source node ID.
target ( integer ) Target node ID.
}
Get Subgraph Response:Edges:Attributes {
weight ( number , optional) The weight of the edge.
}
Get Subgraph Response:Nodes {
attributes ( Attributes )
id ( integer ) Node ID
}
Get Subgraph Response:Nodes:Attributes {
name ( string ) The name of the node
}
Model Schema
This is a JSON schema that describes the syntax of the response. See json-schema.org for a complete reference.
{
    "properties": {
        "edges": {
            "items": {
                "properties": {
                    "attributes": {
                        "properties": {
                            "weight": {
                                "type": "number"
                            }
                        },
                        "type": "object"
                    },
                    "source": {
                        "type": "integer"
                    },
                    "target": {
                        "type": "integer"
                    }
                },
                "required": [
                    "source",
                    "target",
                    "attributes"
                ],
                "type": "object"
            },
            "type": "array"
        },
        "nodes": {
            "items": {
                "properties": {
                    "attributes": {
                        "properties": {
                            "name": {
                                "type": "string"
                            }
                        },
                        "required": [
                            "name"
                        ],
                        "type": "object"
                    },
                    "id": {
                        "type": "integer"
                    }
                },
                "required": [
                    "id",
                    "attributes"
                ],
                "type": "object"
            },
            "type": "array"
        }
    },
    "type": "object"
}
https://api.havenondemand.com/1/api/sync/getsubgraph/v1
/api/api-example/1/api/sync/getsubgraph/v1
Examples
See this API for yourself - select one of our examples below.
Get Subgraph
Show subgraph consisting of links between several countries
Parameters
Optional
Name Type Value
graph
enum
node_ids
array
Add another value
node_names
array
Add another value


ASync – Response An error occurred making the API request
Response Code:
Response Body

	
Making API Request…
Checking result of job

To try this API with your own data and use it in your own applications, you need an API Key. You can create an API Key from your account page - API Keys.

Output Refresh An error occurred making the API request View Input
Rendered RawHtml Response
Result Display
Response Code:
Response Body:

			
Make this call with curl


If you would like to provide us with more information then please use the box below:

We will use your submission to help improve our product.