DevHub API Documentation
  • Introduction
  • Authentication
  • Errors
  • Getting started guides
    • Business-focused Sites
    • Location-focused Sites
    • Location pages and store locator with custom theme
    • Site publishing with site builder access
  • Code examples
    • Python
    • PHP
    • Perl
  • Best practices
    • Our unique IDs, versus yours
    • State and country codes
  • Core Resources
    • Sites
    • Businesses
    • Locations
    • Domains
    • Proxies
  • Content Resources
    • Pages
    • Content
    • Images
    • Files
    • Modules
    • Plugins
    • Themes
  • Logging and analytics
    • Analytics
    • Contact Logs
  • Single Sign On (SSO)
    • Introduction
    • Assigning a site's user
  • Live Preview API
    • What is the Live Preview API?
  • Advanced
    • Domain aliases
    • Language codes
    • Projects
    • Site Check
    • Traces
    • Webmail
  • Local Storage API
    • What is the Local Storage API?
  • Headless CMS
    • Locations search
  • Visitor Localization SDK
    • Visitor Localization SDK
Powered by GitBook
On this page
  • Python 3
  • Base oauth client
  • GET request
  • POST request
  • Python 2
  • GET request
  • POST request

Was this helpful?

  1. Code examples

Python

Python 3

Example using requests_oauthlib package

Base oauth client

import json
from requests_oauthlib import OAuth1Session

client = OAuth1Session('PROVIDEDKEYHERE',
                       client_secret='PROVIDEDSECRETHERE')
base_url = 'https://yourbrand.cloudfrontend.net/api/v2/'

GET request

Example fetching a list of Sites.

response = client.get(
    '{}sites/'.format(base_url),
    params={
        'deleted': 0,
    })
content = response.json()

POST request

Creating a new site using a JSON object containing the payload.

payload = {
    'formatted_domain': 'www.somebusinessname.com',
    ...
}
response = client.post(
    '{}sites/'.format(base_url),
    json=payload)
content = response.json()

Python 2

Example using oauth2 library

GET request

import json
import oauth2 as oauth

consumer = oauth.Consumer('PROVIDEDKEYHERE', 'PROVIDEDSECRETHERE')
client = oauth.Client(consumer, None)
response, content = client.request('/api/v2/sites/', 'GET', headers={
    'content-type': 'application/json'
})
content = json.loads(content)

POST request

A JSON object containing the parameters is encoded as a string and then passed as the request body.

import json
import oauth2 as oauth

consumer = oauth.Consumer('PROVIDEDKEYHERE', 'PROVIDEDSECRETHERE')
client = oauth.Client(consumer, None)
params = {
    'domain': 'somebusinessname.com',
    ...
}
response, content = client.request('/api/v2/sites/', 'POST', body=json.dumps(params), headers={
    'Content-Type': 'application/json'
})
content = json.loads(content)
PreviousCode examplesNextPHP

Last updated 2 months ago

Was this helpful?