Create
Tags: #canny #product
Author: Martin Donadieu

Input

Import librairies

1
import requests
2
import json
3
import pandas as pd
Copied!

Enter credentials

1
canny_api = "CANNY_API_KEY" # api key of canny
2
post_title = "Post title" # Enter post title
3
post_body = "Post body using canny api" # Enter post body
Copied!

Model

Board dataframe using api-key

1
api_key = {
2
"apiKey":canny_api
3
}
4
limit = {
5
"limit":"100"
6
}
7
response = requests.get("https://canny.io/api/v1/boards/list")
8
response = requests.post("https://canny.io/api/v1/boards/list", api_key)
9
post_details = response.json()
10
db = post_details['boards']
11
df = pd.DataFrame(columns = db[0].keys())
12
for i in range(len(db)):
13
df = df.append(db[i], ignore_index=True)
14
df = df[['name','id']]
15
board_list = df.rename(columns={'name': 'BOARD_NAME', 'id': 'BOARD_ID'})
16
board_list
Copied!

Enter board name

1
board_name = "Requests" #Enter board name
2
for i in range(len(board_list)):
3
if board_list['BOARD_NAME'][i] == board_name:
4
board_id = board_list['BOARD_ID'][i]
5
board_id
6
board_id = {
7
"boardID":board_id
8
}
Copied!

Using api and board name to get author list

1
response = requests.get("https://canny.io/api/v1/posts/list")
2
data = {**api_key, **board_id, **limit}
3
response = requests.post("https://canny.io/api/v1/posts/list", data)
4
post_details = response.json()
5
# post_details['posts']
6
author_list = pd.DataFrame()
7
for i in range(len(post_details['posts'])):
8
author_list = author_list.append(post_details['posts'][i]['author'], ignore_index=True)
9
author_list.drop_duplicates(subset ="email", keep = False, inplace = True)
10
author_list = author_list[['name','id']]
11
author_list = author_list.rename(columns={'name': 'AUTHOR_NAME', 'id': 'AUTHOR_ID'})
12
author_list
Copied!

Enter author name

1
author_name = "Sanjay Sabu" #Enter author name
2
for i in author_list['AUTHOR_NAME'].index:
3
if author_list['AUTHOR_NAME'][i] == author_name:
4
author_id = author_list['AUTHOR_ID'][i]
5
author_id = {
6
"authorID":author_id
7
}
Copied!

Creating post

1
post_title = {
2
"title":post_title
3
}
4
post_body = {
5
"details":post_body
6
}
7
data = {**api_key, **author_id, **board_id, **post_body, **post_title}
Copied!

Output

Send the post

1
response = requests.post("https://canny.io/api/v1/posts/create", data)
Copied!
Copy link
Edit on GitHub