Good afternoon, maybe someone from you has worked with the service (worksection.com), if not, I still want to ask for help, because I can't understand what I'm doing wrong.

And so, a brief introduction

  1. Access the API via http GET or POST request at http://your-domain.com/api/admin/ , where your-domain.com is the address of your Worksection account.

The request must contain the parameters:

action - operation

page - project url, task or subtask in the system without an account address For example: / project / 12345 /

hash is a verification record, formed as MD5 from the three glued parameters of the page, action, and your apikey key.

Apikey can get an account owner at http://your-domain.com/account/api/

An example of the formation of a test record for the php language: $hash = md5($page.$action.$apikey).

Text data must be encoded in UTF-8

  1. The answer is generated in JSON format, UTF-8 encoding

Next, I try to translate this into code -

 import json import requests import hashlib adr = 'http://milkiweed.worksection.com/api/admin/' action = 'get_priority' page = 'project/205032/6086356/' apikey = 'e6***b080e162****88b5656***6d0' items = page + action + apikey hash = hashlib.md5(items.encode('utf-8')).hexdigest() r = requests.post(adr,json=hash) data = json.loads(r.text) print(data) 

When I start, I get an error - {'status': 'error', 'status_code': 0, 'message': 'Action is required'}

Based on the documentation, this error indicates that the request or verification record is not formed correctly.

Please tell me, most likely I’m not turning in the right way.

  • one
    compare the http requests that php and python generate. json=hash looks suspicious. - jfs
  • @jfs http://your-domain.com/api/admin/?action=get_priority&hash=HASH Here is an example request for php - Milkiweed Gtlt
  • What is the http method GET or POST? What is Content-Type x-www-form-urlencoded? - jfs
  • @jfs get the method, about the second did not really understand) - Milkiweed Gtlt

2 answers 2

To execute an http GET request and get data in json format:

 import hashlib import requests h = hashlib.md5((page + action + apikey).encode()).hexdigest() data = requests.get('http://your-domain.com/api/admin/' + page + '?action=' + action + '&hash=' + h).json() 
  • Unfortunately, that's it. {'status': 'error', 'status_code': 2, 'message': 'Action hash is missed or invalid'} - Milkiweed Gtlt
  • @MilkiweedGtlt: not knowing how a valid query should look like it is difficult to say anything further. The Python code performs exactly what you asked for. Update the question and explicitly state that the php code is sent and compare with the python code (you can start the server locally: nc -l -p 8888 and replace your-domain.com with localhost:8888 to see the query or just run Wireshark) - jfs
 r = requests.post(adr+'?action='+action+'&hash='+hash) 
  • 2
    Welcome to stack overflow in Russian! Please try to leave a little more detailed answers. you can add an answer by clicking edit - aleksandr barakin
  • 2
    Perhaps the answer is correct, only now it is completely incomprehensible in this form - andreymal
  • There is an example request in the documentation: your-domain.com/api/admin/?action=get_projects&hash=HASH . The line r = requests.post (adr, json = hash) should be replaced by r = requests.post (adr + '? Action =' + action + '& hash =' + hash). For different requests, it will look differently - Anton Pisany