Register a ticket with redmine API using python requests

Overview

Using python's requests module, using redmine's API Register your ticket.

Why did you write this article

An example using python-redmine is easy to find, There aren't many things that use requests, if you do it like you do with curl I stumbled, so I wrote it in the hope that someone else wouldn't stumbled.

Why didn't python-redmine work?

After registering the ticket, use that ticket as the parent ticket and make child tickets one after another I wanted to register, but with the above library, after ticket registration Because the response returns as a Boolean value Because the registered ticket ID could not be obtained. (Please tell me who can do it!)

Premise

--API key is ready Anyway, it is necessary when registering a ticket using the API, so Let's prepare. --requests are already installed You can also see how to import. I know how to use it.

How to register a ticket

Header preparation

The header information is stored in a variable called myheaders as follows.

myheaders = {
    'Content-Type': 'application/json',
    'X-Redmine-API-Key': 'API key'
}

Input example
myheaders = {
    'Content-Type': 'application/json',
    'X-Redmine-API-Key': 'asdfghjklzxcvbnm'
}

Prepare ticket value

payload = {
    "issue": {
        "project_id":Project ID,
        "subject": "Ticket subject",
        "status_id":Status ID,
        "tracker_id":Tracker ID,
        "parent_issue_id": "If there is a ticket you want to use as a parent ticket, its ticket ID",
        "due_date": "Due date (2017-01-01))",
        "description": "#Overview\n You can start a new line with backslash n.",
        "custom_fields": [
            {"id":Custom field ID, "value": "Value you want to register", "name": "Custom field name"},
            {"id":Custom field ID, "value": ["In one field", "When there are multiple values you want to register", "Divide like this"], "name": "Custom field name"}
        ]
    }
}

Input example
payload = {
    "issue": {
        "project_id": 10,
        "subject": "Ticket subject",
        "status_id": 15,
        "tracker_id": 8,
        "parent_issue_id": "10000",
        "due_date": "2017−01−01",
        "description": "#Overview\n You can start a new line with backslash n.",
        "custom_fields": [
            {"id": 1, "value": "pumpkin", "name": "Favorite vegetables"},
            {"id": 2, "value": ["D", "F","G","H"], "name": "Favorite size"}
        ]
    }
}

Register your ticket with requests!

Register your ticket as follows!

redmineurl = 'http://URL of redmine'  
requests.post(redmineurl,headers=myheaders,data=json.dumps(payload))

Recommended Posts

Register a ticket with redmine API using python requests
[python] Read information with Redmine API
Create a record with attachments in KINTONE using the Python requests module
Recent ranking creation using Qiita API with Python
Operate Redmine using Python Redmine
Retry with python requests
Playing with a user-local artificial intelligence API in Python
[Python] Create a ValueObject with a complete constructor using dataclasses
[Blender] Complement Blender's Python API with a text editor
Using a Python program with fluentd's exec_filter Output Plugin
Create a company name extractor with python using JCLdic
[Vagrant] Set up a simple API server with python
A little bit from Python using the Jenkins API
Using a python program with fluentd's exec Output Plugin
Save images using python3 requests
Use Trello API with python
[S3] CRUD with S3 using Python [Python]
Use Twitter API with Python
Using Quaternion with Python ~ numpy-quaternion ~
Web API with Python + Falcon
Using a printer with Debian 10
Make a fortune with Python
Play RocketChat with API / Python
Call the API with python3.
Use subsonic API with python3
Create a directory with python
Using OpenCV with Python @Mac
Register redmine issue from Python
Send using Python with Gmail
A note about hitting the Facebook API with the Python SDK
Quickly take a query string with API Gateway-> Lambda (Python)
Create API with Python, lambda, API Gateway quickly using AWS SAM
I made a Chatbot using LINE Messaging API and Python
Play with YouTube Data API v3 using Google API Python Client
Complement python with emacs using company-jedi
Harmonic mean with Python Harmonic mean (using SciPy)
Solve ABC163 A ~ C with Python
Retry post request using python requests
Control the motor with a motor driver using python on Raspberry Pi 3!
Operate a receipt printer with python
A python graphing manual with Matplotlib.
[Python] Using OpenCV with Python (Image Filtering)
Create Awaitable with Python / C API
I made a Line-bot using Python!
Rubyist tried to make a simple API with Python + bottle + MySQL
Using Rstan from Python with PypeR
Create a python GUI using tkinter
Get reviews with python googlemap api
A story about adding a REST API to a daemon made with Python
[Python] Using OpenCV with Python (Image transformation)
Let's make a GUI with python.
Run Rotrics DexArm with python API
Implementation of CRUD using REST API with Python + Django Rest framework + igGrid
[Python3] Google translate google translate without using api
Solve ABC166 A ~ D with Python
[Python] POST wav files with requests [POST]
Quine Post with Qiita API (Python)
Get the weather with Python requests
Create a virtual environment with Python!
Try using Pleasant's API (python / FastAPI)
I made a fortune with Python.