Skip to content

Python Example

Basic python functions:

If you dont want to write your own there is a python library for webhookbin.net:

https://pypi.org/project/webhookbin/

Below are examples of just using requests.


Example:

This will make a bin, post test data and header, and read it back.

import requests

def makebin(url,private:str=False):
    return requests.get(url+'makebin',headers={'private':private})

def postbin(url,binid,data=None,header=None,token=None):
    if token:
        if header:
            header['Binauth'] = token
        else:
            header = {'Binauth': token}
    return requests.post(url+'bin/'+binid,json=data,headers=header)

def getbin(url,binid,token=None,header=None):
    if token:
        header = {'Binauth': token}
    return requests.get(url+'bin/'+binid,headers=header)

testdata = {'Text':"the quick brown fox jumps over the lazy dog",
            'Numbers': 987654310,
            'Authorization':"Bearer Moooo",
            'bool':True,
            'list':[1,2,3,4,5],
            'dict':{'a':1,'b':2,'c':3},
            'none':None,
            'Json':{'Nested':True}}
testheader = {"Test-Header":"The five boxing wizards jump quickly"}
url = 'https://webhookbin.net/v1/'

madebin = makebin(url=url,private='both')
print(madebin.text)

binid = madebin.json().get('binid')
token = madebin.json().get('token')

posted = postbin(url=url,binid=binid,data=testdata,header=testheader,token=token)
print(posted.text)

gotbin = getbin(url=url,binid=binid,token=token)
print(gotbin.text)

Makebin

def makebin(url,private:str=False):
    return requests.get(url+'makebin',headers={"private":private})

Postbin

def postbin(url,binid,data=None,header=None,token=None):
    if token:
        if header:
            header['Binauth'] = token
        else:
            header = {'Binauth': token}
    return requests.post(url+'bin/'+binid,json=data,headers=header)

Getbin

def getbin(url,binid,token=None,header=None):
    if token:
        header = {'Binauth': token}
    return requests.get(url+'bin/'+binid,headers=header)