Project

General

Profile

Script to import issues via REST API in private project

Added by Victor Sergienko about 6 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 (51)

RE: Problem creating an issue via REST API in private project - Added by Victor Sergienko about 6 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 about 6 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 about 6 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 almost 6 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 almost 6 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 almost 6 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 almost 6 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 over 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 about 1 year 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 8 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 8 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 7 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 6 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 5 months 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/

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

Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article. I will make sure to be reading your blog more. https://www.fiverr.com/websitia/do-1000-plus-contextual-backlinks-and-tier-2-and-3-quality-links

paint by numbers free - Added by digitinc digitinc 3 months ago

Excellent assets from you, man. I’ve known your applications running to and you’re simply especially pleasant. I really like what you have taken here, certainly like what you’re stating and the way in which you say it. I can not wait to read far more from you. This is really a great site. https://www.enjoypaintbynumbers.com/ paint by numbers free

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

I am very appreciated for this blog. It's an informative topic. It accommodates me very much to solve some difficulties. Its opportunity is so fantastic and working style so speedy. https://www.entrustfunding.com FHA mortgage

Mumbai Escorts Service Call Ritu Sharma +91- 9OO4OO9481 - Added by sun light 3 months ago

I Saw Your Website Carefully. Thanks For Create Such Kind Of Informative Website. Your All Content Is Relevant To Your Subject. I Say Keep It Continue, Because Your Website And Subject Is Meaningful For The Users. I Have Recommended Your Website With My Friends Also.
I Am Ritu Sharma. I Am An Independent Mumbai Escort Girl. I Deal In Mumbai Escorts Service. I Am Very Hot And Sexy. Being A Mumbai Escort Girl I Have Five Years’ Experience. That’s Why I Understand The Each Personal Needs Of My Every Client. My Service Charge Is Low And Service Is Super. You Can Avail My VIP Mumbai Escorts Service At Your Home Or In Hotel. I Am Comfortable To Provide Mumbai Escorts Service In Local And Outside Also. Visit http://www.escortservicemumbai.net/ Call +91- 9OO4OO9481
Visit The Links Below And Have A Look At My Various Mumbai Escort Services-
http://www.escortservicemumbai.net/
http://www.escortservicemumbai.net/mumbai-call-girls/
http://www.escortservicemumbai.net/mumbai-escorts-in-vileparle/
http://www.escortservicemumbai.net/bandra-escorts/
http://www.escortservicemumbai.net/juhu-escorts/
http://www.escortservicemumbai.net/andheri-escorts/
http://www.escortservicemumbai.net/mumbai-escorts-in-colaba/

business-stepbystep - Added by business -stepbystep 2 months ago

This is actually the kind of information I have been trying to find. Thank you for writing this information. [[https://www.business-stepbystep.com]]

RE: Script to import issues via REST API in private project - Added by Miss Delhi 2 months ago

Most people who want to achieve pleasure with the sexy model always choose my profile. Come and feel my hot waves and energy. You can also enjoy the sexy night with me on just one click of booking. visit [https://www.missdelhiescort.com [Delhi Escorts]]

iwantitlikethis - Added by iwantitlike this 2 months ago

Not all power meters should be example endorsed. There is a lot of disarray in the commercial center about this, running from totally overlooking the lifting of the exception to utilizing design affirmed power meters for all metering applications. https://www.iwantitlikethis.com

healthy hair treatments - Added by digitinc digitinc 2 months ago

Thank you for the update, a very excellent site. I am very happy to read this article. I really like what you have acquired here, remarkably like what you’re responding and the way in which you say it. Thanks for sharing. http://www.scalp-health.com healthy hair treatments

educationcareeradvisors - Added by educationcareer advisors 2 months ago

Hi, I find reading this article a joy. It is extremely helpful and interesting and very much looking forward to reading more of your work. https://www.educationcareeradvisors.com

(1-25/51)