0
submitted 2 weeks ago* (last edited 2 weeks ago) by twissell@community.nodebb.org to c/general-discussion@community.nodebb.org

Hello everyone!

I want to create some user programmatically using simple Python script and Master API token I've written this test script

#!/usr/bin/python3

import sys
import requests

auth_url =  'https://forum.example.com/api/v3/utilities/login'
#config_url = 'https://forum.example.com/api/config'
main_url =   'https://forum.example.com/api/v3/users/'

headers = {'Authorization':'Bearer Token-is-here'}
auth_data = {'username':'John','password':'JohnPassword','email':'john@example.com'}


#Authenticate before using API
r = requests.post(auth_url,headers=headers,data=auth_data)

#Get config with user data
#r = requests.get(config_url)
#res_json = r.json();
#csrf_key = res.json['csrf_token']
main_data = {'username':'Robin93', 'password':'MyPassword', 'email':'robin@example.com'}
r = requests.post(main_url, data=main_data)

But I get r.text '{"status":{"code":"forbidden","message":"You are not authorised to make this call"},"response":{}}' in response :-( What am I doing the wrong way?

Thank you all !

P.S. My token is Master Token, so I updated the original code snippet.

top 1 comments
sorted by: hot top controversial new old
[-] twissell@community.nodebb.org 1 points 2 weeks ago

@razibal Yep, it really works! :-)

this post was submitted on 11 Feb 2025
0 points (NaN% liked)

General Discussion

0 readers
4 users here now

A place to talk about whatever you want

founded 1 month ago