Streaming live at 10am (PST)

Python 3.7.1 - Webflow class - Error 404

Hi,

I am trying to build a Webflow class in Python 3.7.1 to use Webflow API fast and easily in the future but I get an error 404. As it’s my first time using an API, I’ve tried to adapt the Webflow official Javascript client (https://github.com/webflow/js-webflow-api) to Python.
Can you help please ?


INPUT:

class Webflow:
    def __init__(self,token):
        self.end_point='https://api.webflow.com'
        self.token=token
        self.version=str('1.0.0')
        Bearer='Bearer '+token
        self.headers={'Accept':'application/json',
                      'Authorization':Bearer,
                      'accept-version':self.version,
                      'Content-type':'application/json'}
    def authenticatedFetch(self,method,path,data,query):
        queryString='?'+str(query)
        uri=self.end_point+path+queryString
        opts={'method':method,
             'headers':self.headers,
             'mode':'cors'}
        if type(data)=='dict':
            opts['body']=str(data)
        response=requests.patch(uri,opts)
        return json.loads(response.content.decode('utf-8'))
    def GET(self,path,query={}):
        return self.authenticatedFetch('GET',path, False, query)
wf=Webflow('my_token')
resultat=wf.GET('/info','')
for i in resultat:
    print(i,resultat[i])

OUTPUT:

https://api.webflow.com/info?

msg Route not found: /info 
code 404 
name RouteNotFoundError 
path /info 
err RouteNotFoundError: Route not found: /info 
meta {'code': 'RouteNotFound'} 
errorEnum RouteNotFound

I am not use to post in forums, I hope I’ve been as clear as possible !
Thank you very much!

I changed the code and now I’ve got an Error 400. I think I am getting closer but still doesn’t work :confused:


When I call Webflow('my_token').info() I get this :

msg No API version specified on request
code 400
name InvalidAPIVersion
path /info
err InvalidAPIVersion: No API version specified on request

Here is the new Webflow class :

class Webflow:
    def __init__(self,token):
        self.end_point='https://api.webflow.com'
        self.token=token
        self.headers={'Accept':'application/json',
                      'Authorization':'Bearer '+token,
                      'accept-version':str('1.0.0'),
                      'Content-type':'application/json'}
    def authenticatedFetch(self,method,path,data,query):
        if query:
            url=self.end_point+path+str('?'+str(query))
        else:
            url=self.end_point+path
        if   method == 'GET'    : response = requests.get(   url,        self.headers)
        elif method == 'POST'   : response = requests.post(  url,  data, self.headers)
        elif method == 'PUT'    : response = requests.put(   url,  data, headers=self.headers)
        elif method == 'PATCH'  : response = requests.patch( url,  data, headers=self.headers)
        elif method == 'DELETE' : response = requests.delete(url,        headers=self.headers)

        # json format
        response = json.loads(response.content.decode('utf-8'))

        # Errors
        if response['code'] != 200:
            for i in response:
                print(i, response[i])

        return response

    def info(self,query={}):
        return self.get('/info',query=query)
    def get(self,path,query={}):
        return self.authenticatedFetch('GET',    path, False, query)