Graph API
Overview
The Graph API is the primary way to get data into and out of the Facebook platform. It's an HTTP-based API that apps can use to programmatically query data, post new stories, manage ads, upload photos, and perform a wide variety of other tasks.
The Graph API is named after the idea of a "social graph" — a representation of the information on Facebook. It's composed of nodes, edges, and fields. Typically you use nodes to get data about a specific object, use edges to get collections of objects on a single object, and use fields to get data about a single object or each object in a collection. Throughout our documentation, we may refer to both a node and edge as an "endpoint". For example, "send a GET
request to the User endpoint".
HTTP
All data transfers conform to HTTP/1.1, and all endpoints require HTTPS. Because the Graph API is HTTP-based, it works with any language that has an HTTP library, such as cURL and urllib. This means you can use the Graph API directly in your browser. For example, requesting this URL in your browser...
https://graph.facebook.com/facebook/picture?redirect=false
... is equivalent to performing this cURL request:
We have also enabled the includeSubdomains
HSTS directive on facebook.com
, but this should not adversely affect your Graph API calls.
Host URL
Almost all requests are passed to the graph.facebook.com
host URL. The single exception is video uploads, which use graph-video.facebook.com
.
Access Tokens
Access tokens allow your app to access the Graph API. Almost all Graph API endpoints require an access token of some kind, so each time you access an endpoint, your request may require one. They typically perform two functions:
They allow your app to access a User's information without requiring the User's password. For example, your app needs a User's email to perform a function. If the User agrees to allow your app to retrieve their email address from Facebook, the User will not need to enter their Facebook password for your app to get their email address.
They allow us to identify your app, the User who is using your app, and the type of data the User has permitted your app to access.
Visit our access token documentation to learn more.
Nodes
A node is an individual object with a unique ID. For example, there are many User node objects, each with a unique ID representing a person on Facebook. Pages, Groups, Posts, Photos, and Comments are just some of the nodes of the Facebook Social Graph.
The following cURL example represents a call to the User node.
This request would return the following data by default, formatted using JSON:
Node Metadata
You can get a list of all fields, including the field name, description, and data type, of a node object, such as a User, Page, or Photo. Send a GET
request to an object ID and include the metadata=1
parameter:
The resulting JSON response will include the metadata
property that lists all the supported fields for the given node:
/me
The /me
node is a special endpoint that translates to the object ID of the person or Page whose access token is currently being used to make the API calls. If you had a User access token, you could retrieve a User's name and ID by using:
Edges
An edge is a connection between two nodes. For example, a User node can have photos connected to it, and a Photo node can have comments connected to it. The following cURL example will return a list of photos a person has published to Facebook.
Each ID returned represents a Photo node and when it was uploaded to Facebook.
Fields
Fields are node properties. When you query a node, or an edge, it returns a set of fields by default, as the examples above show. However, you can specify which fields you want returned by using the fields
parameter and listing each field. This overrides the defaults and returns only the fields you specify, and the ID of the object, which is always returned.
The following cURL request includes the fields
parameter and the User's name, email, and profile picture.
Data Returned
Complex Parameters
Most parameter types are straightforward primitives such as bool
, string
and int
, but there are also list
and object
types that can be specified in the request.
The list
type is specified in JSON syntax, for example: ["firstitem", "seconditem", "thirditem"]
The object
type is also specified in JSON syntax, for example: {"firstkey": "firstvalue", "secondKey": 123}
Publishing, Updating, and Deleting
Visit our Facebook Sharing guide to learn how to publish to a User's Facebook or our Pages API documentation to publish to a Page's Facebook feed.
Some nodes allow you to update fields with POST
operations. For example, you could update your email
field like this:
Read-After-Write
For create and update endpoints, the Graph API can immediately read a successfully published or updated object and return any fields supported by the corresponding read endpoint.
By default, an ID of the object created or updated will be returned. To include more information in the response, include the fields
parameter in your request and list the fields you want returned. For example, to publish the message “Hello” to a Page's feed, you could make the following request:
The above code example is formatted for readability.
This would return the specified fields as a JSON-formatted response, like this:
Refer to each endpoint's reference documentation to see if it supports read-after-write and what fields are available.
Errors
If the read fails for any reason (for example, requesting a non-existent field), the Graph API will respond with a standard error response. Visit our Handling Errors guide for more information.
You can usually delete a node, such as a Post or Photo node, by performing a DELETE operation on the object ID:
Usually you can only delete nodes that you created, but check each node's reference guide to see requirements for delete operations.
Versions
The Graph API has multiple versions with quarterly releases. You can specify the version in your calls by adding "v" and the version number to the start of the request path. For example, here's a call to version 4.0:
If you do not include a version number we will default to the oldest available version, so it's recommended to include the version number in your requests.
You can read more about versions in our Versioning guide and learn about all available versions in the Graph API Changelog.
Facebook APIs, SDKs, and Platforms
Connect interfaces and develop across platforms using Facebook's various APIs, SDKs, and platforms.
Next Steps
Get Started with Graph API – Let's explore the Facebook Social Graph using the Graph Explorer tool and run a couple requests to get data.
Guides
Various Guides for how to use the Facebook Graph API to send and receive data to the Facebook Social Graph.
Batch Requests
The Batch Requests guide describes how to make multiple Graph API requests in one call.
Debugging
The Debug Requests guide describes how to enable Debug Mode to view Graph API responses that may contain additional fields that explain potential issues with an API call.
Error Handling
The Handling Errors guide describes the recovery tactics and provides a list of error values with a map to the most common recovery tactic to use.
Graph Explorer Guide
The Graph API Explorer guide describes how to use the Graph Explorer tool](/tools/explorer). This tool allows you to construct, test, and debug queries and see their responses for any apps on which you have an admin, developer, or tester role.
Upload Files
The Upload Files guide describes how to upload photos and videos to the Facebook Social Graph that can then be shared in User, Group, or Page posts.
Graph API Reference
Graph API Root Nodes
This is a full list of the Graph API root nodes. The main difference between a root node and a non-root node is that root nodes can be queried directly, while non-root nodes can be queried via root nodes or edges. If you want to learn how to use the Graph API, read our Using Graph API guide, and if you want to know which APIs can solve some frequent issues, try our Common Scenarios guide.
An individual app request received by someone, sent by an app or another person
A Facebook app
Represents an async job request to Graph API
An Atlas AdSet
An Atlas Campaign
Conversion Event Node
An Atlas Publisher
An Atlas Report
An Atlas ReportRun
An Atlas ReportSchedule
An Ad Platform Tracking Connection
Represents a group of certain types of Business objects in a Business. Will be used by Measurement Hub initially with more usage coming later on.
Returns a recommendation of a single retailer for a specific brand. This endpoint returns a retailer-brand pair and an advertiser who can advertise on behalf of the producer.
This endpoint is mainly for Facebook’s Marketing Partners using Collaborative Ads.
A collaboration request is a partnership request coming from a brand or agency to a retailer or marketing partner. Used for Collaborative Ads.
A domain name that has been issued new certificates.
A canvas document
A button inside the canvas
A carousel inside a canvas
A footer of the canvas
A header inside the canvas.
A photo inside a canvas
A product list inside the canvas
A product set inside the canvas
A store locator inside the canvas
Text element of the canvas
A video inside canvas
Directory of retailers that use Collaborative Ads. This endpoint must be used in conjunction with the collaborative_ads_merchants
field below.
A comment can be made on various types of content on Facebook. Most Graph API nodes have a /comments edge that lists all the comments on that object. The /comment node returns a single comment.
Commerce Merchant Settings object
Represents an order placed directly on Facebook or Instagram
Graph API Reference Conversation /conversation
Represents a destination in a catalog
A Document
Get fields and edges on an Event.
Represents a flight in a catalog
This represents a user's friend list on Facebook
A Facebook group.
Graph API Reference Group Doc /group-doc
GroupMessage
Represents a copyright on an image asset.
InstagramOembed
A lead ad form
A link shared on a wall.
Get fields and edges on a LiveEncoder.
Get fields and edges on a LiveVideo.
An ingest stream for a live video
A mailing address object
Media fingerprint
An individual message in the Facebook messaging system.
Graph API Reference Milestone /milestone
A native offer
represents an Offer on Facebook. The /{offer_id}
node returns a single native offer
. Each native offer
requires a view
to be rendered to users.
This reference describes the /comments
edge that is common to multiple Graph API nodes. The structure and operations are the same for each node.
This reference describes the /likes
edge that is common to multiple Graph API nodes. The structure and operations are the same for each node.
Private replies for an object
First revision to publish
Graph API Reference /object/sharedposts
OembedPage
OembedPost
OembedVideo
A Data Set for Offline Conversions object
A subset of Offline Event Data Set
Get groups a Page is a member of.
Page's call-to-action
A Facebook feed story
Notification of page upcoming changes.
This object represents a single Insights metric that is tied to another particular Graph API object (Page, App, Post, etc.).
Graph API Reference Payment /payment
This represents a Photo on Facebook.
A place
The category of a place Page
A Facebook Feed story
Graph API Reference Profile /profile
A dynamically generated Post, used for Dynamic Ad Creatives
Graph API Reference Request /request
Represents settings specific to local inventory of a product catalog
Graph API Reference Test User /test-user
Graph API Reference Thread /thread
Get fields and edges on a User.
A Video
A video copyright
A video copyright rules
A playlist for videos
Embedded video poll
Represents a single poll option that may be selected by the user
Returns the account information of a WhatsApp Business Account
Returns information about a specific phone number.
Retrieves information about the message template
Graph API Root Edges
Root edges are edges that can be queried directly. They allow you to access collections of nodes that are not on a parent node.
Returns archived ads based on your search. By default we only return all ads that are eligible for delivery and that have the ACTIVE
status.
DebugToken
Last updated