Last active
March 17, 2024 09:30
-
-
Save ValekS/72e7aa9a3b581d9fa16f184e7f2278f1 to your computer and use it in GitHub Desktop.
[Monobank open API for providers] registration / check reg.status / get corp.info EXAMPLE REQUESTS | Original: https://gist.github.com/mydropcrm/0798023a520826260c60c648dbc0dc6a
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import base64 | |
import time | |
import ecdsa | |
import hashlib | |
# Monobank open API for providers - registration | |
# Docs - https://api.monobank.ua/docs/corporate.html#tag/Avtorizaciya-ta-nalashtuvannya-kompaniyi | |
# POST https://api.monobank.ua/personal/auth/registration | |
if __name__ == '__main__': | |
resource = '/personal/auth/registration' | |
url = f'https://api.monobank.ua{resource}' | |
# PRIVATE KEY | |
# openssl ecparam -genkey -name secp256k1 -rand /dev/urandom -out private.key | |
pem_private_key = open('private.key').read() | |
# get epoch timestamp [a floating point number => integer] | |
timestamp = int(time.time()) | |
timestamp = str(timestamp) | |
# Load key | |
signing_key = ecdsa.SigningKey.from_pem(pem_private_key) | |
# Get X-sign for request | |
data = (timestamp + resource).encode('utf-8') | |
sign = signing_key.sign(data, hashfunc=hashlib.sha256) | |
sign_b64 = base64.b64encode(sign) | |
# logo of your company | |
with open('logo.jpg', 'rb') as image_file: | |
logo_encoded = base64.b64encode(image_file.read()) | |
# PUBLIC KEY | |
# openssl ec -in private.key -pubout > public.key | |
with open('public.key', 'rb') as public_key_file: | |
public_key_encoded = base64.b64encode(public_key_file.read()) | |
request_data = { | |
"pubkey": public_key_encoded.decode(), | |
"name": "Назва компанії", | |
"description": "Опис вашої компанії до 100 символів", | |
"contactPerson": "Ім'я Прізвище", | |
"phone": "380960000001", | |
"email": "[email protected]", | |
"logo": logo_encoded.decode() | |
} | |
headers = { | |
"X-Time": timestamp, | |
"X-Sign": sign_b64 | |
} | |
response = requests.post(url, headers=headers, json=request_data) | |
print(f'Response status code: {response.status_code}') | |
print(response.json()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import base64 | |
import time | |
import ecdsa | |
import hashlib | |
# Monobank open API for providers - check reg.status | |
# Docs - https://api.monobank.ua/docs/corporate.html#tag/Avtorizaciya-ta-nalashtuvannya-kompaniyi/paths/~1personal~1auth~1registration~1status/post | |
# POST https://api.monobank.ua/personal/auth/registration/status | |
if __name__ == '__main__': | |
resource = '/personal/auth/registration/status' | |
url = f'https://api.monobank.ua{resource}' | |
# PRIVATE KEY | |
pem_private_key = open('private.key').read() | |
# get epoch timestamp [a floating point number => integer] | |
timestamp = int(time.time()) | |
timestamp = str(timestamp) | |
# Load key | |
signing_key = ecdsa.SigningKey.from_pem(pem_private_key) | |
# Get X-sign for request | |
data = (timestamp + resource).encode('utf-8') | |
sign = signing_key.sign(data, hashfunc=hashlib.sha256) | |
sign_b64 = base64.b64encode(sign) | |
# PUBLIC KEY | |
with open('public.key', 'rb') as public_key_file: | |
public_key_encoded = base64.b64encode(public_key_file.read()) | |
request_data = { | |
"pubkey": public_key_encoded.decode() | |
} | |
headers = { | |
"X-Time": timestamp, | |
"X-Sign": sign_b64 | |
} | |
response = requests.post(url, headers=headers, json=request_data) | |
print(f'Response status code: {response.status_code}') | |
print(response.json()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import base64 | |
import time | |
import ecdsa | |
import hashlib | |
# Monobank open API for providers - get corp.info | |
# Docs - https://api.monobank.ua/docs/corporate.html#tag/Avtorizaciya-ta-nalashtuvannya-kompaniyi/paths/~1personal~1corp~1settings/get | |
# GET https://api.monobank.ua/personal/corp/settings | |
if __name__ == '__main__': | |
resource = '/personal/corp/settings' | |
url = f'https://api.monobank.ua{resource}' | |
# Your service keyId | |
# send a request to /personal/auth/registration/status | |
key_id = '28a75537175a018645e6f8b14be7681791e701e0' | |
# PRIVATE KEY | |
pem_private_key = open('private.key').read() | |
# get epoch timestamp [a floating point number => integer] | |
timestamp = int(time.time()) | |
timestamp = str(timestamp) | |
# Load key | |
signing_key = ecdsa.SigningKey.from_pem(pem_private_key) | |
# Get X-sign for request | |
data = (timestamp + resource).encode('utf-8') | |
sign = signing_key.sign(data, hashfunc=hashlib.sha256) | |
sign_b64 = base64.b64encode(sign) | |
headers = { | |
"X-Key-Id": key_id, | |
"X-Request-Id": "", | |
"X-Time": timestamp, | |
"X-Sign": sign_b64 | |
} | |
response = requests.get(url, headers=headers) | |
print(f"Response status code: {response.status_code}") | |
print(response.json()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run:
python3 1_registration.py