Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This article shows an example of an API connection in Python.

Code

In the below code replace the following with your own credentials.

...

Code Block
breakoutModewide
languagepy
import requests
import base64
import hmac, hashlib
import simplejson as json
import pprint

pp = pprint.PrettyPrinter(indent=1)

def callAPI(base_url, public_key, token, endpoint='/account', method='GET', body='', query=''):
    
    
    
    signature_token = bytes(token.encode('utf-8'))
    uri_and_body = '{}|{}'.format(endpoint,body).encode('utf-8')
    uri_and_body_hmac_sha256 = hmac.new(signature_token, msg=uri_and_body, digestmod = hashlib.sha256).hexdigest()
    
    xtoken = base64.b64encode(bytes('{}:{}'.format(public_key, uri_and_body_hmac_sha256), 'utf-8'))
    url = '{}{}{}'.format(base_url, endpoint, query)
    headers = {
        'X-Auth-Token': xtoken,
        'version':'1.18.14',
        'verbosity':'full'
    }
    
    response = requests.request(method, url, data=body, headers=headers, params=query)
    return response, xtoken


baseurl = 'https://api.mopinion.com'
endpoint = '/account'

#public key and signature token
public_key = '8e8e8e8e8e88e'
token = '9d9galnojvavlkre455%lreagfglkfgslkng'
query = ''
call = callAPI(baseurl,public_key,token,endpoint,query=query)
pp.pprint(call[0].json())
print(call[1])

 

Filter by label (Content by label)
showLabelsfalse
max5
spacescom.atlassian.confluence.content.render.xhtml.model.resource.identifiers.SpaceResourceIdentifier@957
showSpacefalse
sortmodified
typepage
reversetrue
labelsAPI
cqllabel = "api" and type = "page" and space = "KB"

...