Project

General

Profile

Script to import issues via REST API in private project

Added by Victor Sergienko over 5 years ago

I'm trying to create an issue via POST request to hostedredmine.com API in Python 3 like:

url = "https://www.hostedredmine.com/issues.json" 
key = "***" 

def createIssue(body):
    body = {'issue': body}
    data = urllib.parse.urlencode({'issue': body})
    data = data.encode('utf-8')
    request = urllib.request.Request(url)

    # adding charset parameter to the Content-Type header.
    request.add_header("Content-Type", "application/json")
    request.add_header("X-Redmine-API-Key", key)
    #request.add_header("Content-Length", len(data))

    f = urllib.request.urlopen(request, data)
    print(f.read().decode('utf-8'))

createIssue({
    'project_id': 'plando',
    'subject': 'test1',
    'notes': 'tetest',
     #'parent_issue_id': '215453',
    }
)

and getting a HTTP Error 500: Internal Server Error.

I've tried various URLs, with and without .json suffix or my project path.

Does anybody have any idea, what could it be?


Replies (16)

RE: Problem creating an issue via REST API in private project - Added by Victor Sergienko over 5 years ago

The double {'issue':body} thing is a latest addition and I get the same after fixing it ;)

RE: Problem creating an issue via REST API in private project - Added by Victor Sergienko over 5 years ago

...got it. It was a single quote instead of double quotes.

RE: Problem creating an issue via REST API in private project - Added by Victor Sergienko over 5 years ago

For those who are interested, here's a ready import script.

import urllib.parse
import urllib.request
import json

url = "https://www.hostedredmine.com/issues.json" 
key = "***" 

# http://www.redmine.org/projects/redmine/wiki/Rest_api_with_curl
# curl -v -H "Content-Type: application/json" -X PUT --data "@388.json" -H "X-Redmine-API-Key: xxxx" http://redmine/issues/388.json

def createIssue(body):
    body = {'issue': body}

    data = json.dumps(body).encode('utf-8')
    #print(data)

    request = urllib.request.Request(url, data)

    request.add_header("Content-Type", "application/json")
    request.add_header("X-Redmine-API-Key", key)
    request.add_header("Content-Length", len(data))

    f = urllib.request.urlopen(request, data)
    response = json.loads(f.read().decode('utf-8'))
    print(response)
    return response

#createIssue({
#    'project_id': 'plando',
#    'subject': 'test1',
#    'notes': 'tetest',
#     #'parent_issue_id': '215453',
#     #'tracker_id': 2,
#    })
#
#exit(0)

with open('/home/me/tasks.csv') as f:
    story_id = "" 
    for line in f.readlines():

        splat = list(s.strip() for s in line.split('|'))
        if len(splat) < 3 or not splat[0]:
            story_id = "" 
            continue
        (title, hrs, desc) = splat[0:3]

        issue = {
            'project_id': 'myproject',
            'subject': title,
            'notes': desc,
            'parent_issue_id': story_id,
            'tracker_id': 6, # User Story
            'estimated_hours': hrs,
            }
        if story_id:
            print("Task: '{}' for {} hrs".format(title, hrs))
            issue['parent_issue_id'] = story_id
            issue['tracker_id'] = 4 # Task
            if hrs.isdigit():
                issue['estimated_hours'] = hrs
            createIssue(issue)
        else:
            print("Story: '{}'".format(title))
            response = createIssue(issue)
            story_id = response['issue']['id']
            print(" = ", story_id)

RE: Script to import issues via REST API in private project - Added by Victor Sergienko over 5 years ago

Please don't worry. There's no rest. It's that short.

RE: Script to import issues via REST API in private project - Added by Brad Rushworth over 5 years ago

Mukesh Ghatiya wrote:

Where is the rest of the code ?? !!

If it isn't obvious, you need to install Python 3 on your computer before being able to run this. Most Linux computers will already have this installed, but on Windows you will need to download it and install before running the script above.

RE: Script to import issues via REST API in private project - Added by Aleksey Oriekhov over 5 years ago

Thank you for the script!
Just a couple notes:
1. Seems like instead of 'notes' field 'description' should be used. I have no luck, when used 'notes'
2. Does anybody know, how I can export/import not only issues name & desc, but also journal notes? I have a lot of cases where important information is placed in notes during discussion, not in the description of the issue. I've tried to find the way how to export the list of issues with journal, but haven't found any script..

RE: Script to import issues via REST API in private project - Added by Aleksey Oriekhov over 5 years ago

Sorry guys, my question is not actual anymore.
I've created small .NET app with journal notes copying support. Details here: http://www.hostedredmine.com/boards/1/topics/8844

fashionable jacket - Added by Bairan swift about 1 year ago

I love how your collection is so versatile of leather jackets are the perfect item to wear for this time period but let me tell you a little secret.They are perfect year round.don't be afraid to invest in the
because i promise you'll get your money's worth visit website: https://ippofashion.eu ! They’re are pieces that you can rock at a music festival,
styled like you have done so perfectly, that you can change up to wear

RE: printing services canada - Added by spade james 8 months ago

I love your collection but brentwood printings offers a [https://brentwoodprinting.com/[printing services Canada]], digital and offse printing and much more.

RE: Script to import issues via REST API in private project - Added by maria smith 4 months ago

Cool stuff you have got and you keep update all of us. Thank you for this fascinating post, I am happy I observed this website on Google.https://www.seo-lah.com

RE: Script to import issues via REST API in private project - Added by abbas abbas 4 months ago

"Kenapa dia hidup?" Dasha bertanya padaku, dan aku tercengang.ini ke 20
http://www.gudangbesibaja.com/harga-supplier-plat-besi-baja-jual-pabrik-besi-agen-distributor Supplier plat besi hitam
http://www.pusatbesibaja.co.id/harga-besi-wf-profil-iwf-baja-pabrik-supplier-distributor-jual-agen-toko-produsen Toko besi wf
http://www.pusatbesibaja.com/harga-besi-wf-profil-iwf-baja-pabrik-distributor-jual-supplier-toko-produsen-agen Toko besi wf
http://ironsteelcenter.com/category/stainless-steel-ss-sus-304-210-316-310-301-stenlis Toko stainless steel
http://www.gudangbesibaja.com/category/besi-baja-cnp-kanal-c/ Agen besi cnp
https://goo.gl/XZ6zpY undangan pernikahan akrilik
http://www.sentrabesibaja.com/besi-wiremesh/ Supplier Wiremesh
http://ironsteelcenter.com/besi-baja-plat-kapal/harga-jual-plat-kapal-bki-ks Jual Plat Kapal Besi baja
http://www.gudangbesibaja.com/harga-supplier-plat-besi-baja-jual-pabrik-besi-agen-distributor Toko plat besi hitam
http://www.jualbesibetonhargapabrikmurah.com/category/besi-beton-sni-ulir-polos/ Pabrik besi beton Sni Ulir Polos polos ulir
http://www.pusatbesibaja.co.id/harga-besi-wf-profil-iwf-baja-pabrik-supplier-distributor-jual-agen-toko-produsen Agen besi wf
http://www.pusatbesibaja.com/harga-besi-wf-profil-iwf-baja-pabrik-distributor-jual-supplier-toko-produsen-agen Agen besi wf
http://ironsteelcenter.com/category/spandek Toko atap spandek
http://www.gudangbesibaja.com www.gudangbesibaja.com
https://goo.gl/XZ6zpY undangan pernikahan bentuk tas
http://www.sentrabesibaja.com/pipa-besi-baja-sch-80-schedule/ Supplier Besi Pipa Baja Schedule 80
http://ironsteelcenter.com/besi-baja-plat-kapal/harga-jual-plat-kapal-bki-ks Harga Plat Kapal Besi baja
http://www.gudangbesibaja.com/harga-supplier-plat-besi-baja-jual-pabrik-besi-agen-distributor Agen plat besi hitam
http://www.jualbesibetonhargapabrikmurah.com/category/besi-beton-sii-ulir-polos/ Pabrik besi beton sii
http://www.pusatbesibaja.co.id/harga-besi-wf-profil-iwf-baja-pabrik-supplier-distributor-jual-agen-toko-produsen Pabrik besi wf
http://www.pusatbesibaja.com/harga-besi-wf-profil-iwf-baja-pabrik-distributor-jual-supplier-toko-produsen-agen Pabrik besi wf
http://ironsteelcenter.com/category/baja-ringan Toko baja ringan
http://www./harga-besi-hollow-hitam-baja-toko-distributor-agen-supplier-pabrik-produsen-jual Pabrik besi hollow
http://pabrikbesiwfjakarta.blogspot.com/ Toko besi Wf Baja
http://www.undangancinta.com undangan pernikahan online
http://www.sentrabesibaja.com/pipa-besi-baja-sch-40-schedule/ Supplier Besi Pipa Baja Schedule 40
http://ironsteelcenter.com/besi-baja-plat-kapal/harga-jual-plat-kapal-bki-ks Pabrik Plat Kapal Besi baja
http://www.gudangbesibaja.com/harga-supplier-plat-besi-baja-jual-pabrik-besi-agen-distributor Pabrik plat besi hitam
http://www.jualbesibetonhargapabrikmurah.com/category/besi-beton-psi-ulir-polos/ Pabrik besi beton psi Ulir Polos
http://www.pusatbesibaja.co.id/harga-besi-hollow-hitam-baja-supplier-pabrik-distributor-agen-jual-toko-produsen Distributor besi hollow
http://www.pusatbesibaja.com/harga-besi-hollow-hitam-baja-agen-supplier-toko-produsen-jual-distributor-pabrik Distributor besi hollow
http://ironsteelcenter.com/category/bondek Toko bondek
http://www.gudangbesibaja.com/tag/bondek/ Toko bondek
http://www.undangancinta.com undangan pernikahan modern
http://www.sentrabesibaja.com/pipa-besi-hitam-medium-galvaniz/ Supplier Pipa Besi Hitam Medium
http://ironsteelcenter.com/besi-wiremesh-wermesh-m4-m5-m6-m7-m8-m9-m10-m11-m12-m13-m14-m15-m16/harga-jual-supplier-wiremesh-dan-agen-distributor-pabrik Distributor Wiremesh Besi baja
http://www.gudangbesibaja.com/harga-supplier-plat-kapal-baja-jual-pabrik-besi-agen-distributor Distributor plat kapal besi baja
http://www.jualbesibetonhargapabrikmurah.com/category/besi-beton-perwira-ulir-polos/ Pabrik besi beton perwira
http://www.pusatbesibaja.co.id/harga-besi-hollow-hitam-baja-supplier-pabrik-distributor-agen-jual-toko-produsen Harga besi hollow
http://www.pusatbesibaja.com/harga-besi-hollow-hitam-baja-agen-supplier-toko-produsen-jual-distributor-pabrik Harga besi hollow
http://ironsteelcenter.com/category/besi-baja-plat-kapal Toko Plat kapal besi baja bki krakatau steel
http://www.gudangbesibaja.com/category/besi-wiremesh/ Toko wiremesh
http://www.undangancinta.com undangan pernikahan unik dan murah
http://www.sentrabesibaja.com/besi-baja-i-wf-profil/ Supplier Besi Wf
http://ironsteelcenter.com/besi-wiremesh-wermesh-m4-m5-m6-m7-m8-m9-m10-m11-m12-m13-m14-m15-m16/harga-jual-supplier-wiremesh-dan-agen-distributor-pabrik Supplier Wiremesh Besi baja
http://www.gudangbesibaja.com/harga-supplier-plat-kapal-baja-jual-pabrik-besi-agen-distributor Harga plat kapal besi baja
http://www.jualbesibetonhargapabrikmurah.com/category/besi-beton-pas-ulir-polos/ Pabrik besi beton PAS
https://goo.gl/ncgJmF Jual Jaket Parka
https://goo.gl/ncgJmF Jaket Parka
http://www.undangancinta.com undangan pernikahan kalender
http://www.undangancinta.com undangan pernikahan bahasa inggris islam
http://www.undangancinta.com undangan pernikahan islami
http://www.undangancinta.com undangan pernikahan unik dan murah
http://www.undangancinta.com undangan pernikahan modern
http://www.undangancinta.com undangan pernikahan online
http://www.undangancinta.com undangan pernikahan
http://www.undangancinta.com undangan pernikahan amplop surat
http://www.undangancinta.com undangan pernikahan simple
http://www.undangancinta.com undangan pernikahan murah
http://www.undangancinta.com undangan pernikahan unik
http://www.undangancinta.com undangan pernikahan artis
http://www.undangancinta.com undangan pernikahan modern
http://www.undangancinta.com undangan pernikahan artis
http://www.undangancinta.com undangan pernikahan arab
http://www.pusatbesibaja.com/harga-welded-beam-toko-produsen-supplier-agen-pabrik-distributor-jual Pabrik Welded Beam
http://ironsteelcenter.com/category/spandek Jual atap spandek

RE: Script to import issues via REST API in private project - Added by WILLIAMS ROSE 3 months ago

Bless you designed for presenting modern up-dates concerning the anxiety, As i watch for browse alot more.
Accountants Crawley

RE: Script to import issues via REST API in private project - Added by Erin Jameson about 2 months ago

Thanks very much for the heads up, it now worked for me too! https://www.medicinehatroofing.com/

Nice Post - Added by iran bell about 1 month ago

Very good, I think I found the knowledge I needed.I will see and refer some information in your post.thank you.
Game Lover - https://games.lol/card/

    (1-16/16)