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)

Last updated

Was this helpful?