1

I am using Python with Requests module to connect to an EasyRedmine API. I'm having trouble creating a project using the post method in order to post a JSON. It returns "[Unprocessable Entity <Response [422]>]". I have tried the same request using Postman and Curl and it works perfectly. Does anyone know what could be causing this problem? The following curl command works fine.

curl -X 'POST'
'https://cafte.easyredmine.com/projects.json?key=0224b4238XXXX'
-H 'accept: application/json'
-H 'X-Redmine-API-Key: 0224b4238XXX'
-H 'Content-Type: application/json'
-d '{ "project": { "easy_external_id": "external-system-1", "name": "Blue 2", "homepage": "blue-7", "description": "I can’t abide these Jawas. Disgusting creatures.", "author_id": 0, "is_planned": true, "easy_is_easy_template": true, "easy_currency_code": "EUR" }

This is the methode code:

def create_project(self, name: str, description="", external_id="", homepage="", parent_id="", author_id="",
                   is_planned= 'false', is_easy_template= "true", start_date="", due_date="", custom_fields=[],
                   tag_list=[], currency='EUR'):
    print(name)

    data = {"project": {
        "easy_external_id": external_id,
        "name":name,
        "homepage": homepage,
        "description": description,
        "parent_id": parent_id,
        "author_id": author_id,
        "is_planned": is_planned,
        "easy_is_easy_template": is_easy_template,
        "easy_start_date": start_date,
        "easy_due_date": due_date,
        "custom_fields": custom_fields,
        "tag_list": tag_list,
        "easy_currency_code": currency
    }
    }


    endpoint_path = "/projects"
    endpoint = f'{self.base_url}{endpoint_path}'
    headers = {'X-Redmine-API-Key': f'{self.api_key}',
               'accept': 'application/json',
               'Content-Type': 'application/json'
               }


    r = requests.post(endpoint, headers=headers, json= data)
Aymanete
  • 11
  • 2
  • When using CURL your URL has `projects.json`, but in python code, you forgot to add `.json` to the URL (it should be `endpoint_path="/projects.json"`) – Aleksandar Varicak Jun 15 '22 at 12:23

0 Answers0