Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a MR using GitLab API?

I am trying to create a merge request using the GitLab Merge Request API with python and the python requests package. This is a snippet of my code

import requests, json

MR = 'http://www.gitlab.com/api/v4/projects/317/merge_requests'

id = '317'
gitlabAccessToken = 'MySecretAccessToken'
sourceBranch = 'issue110'
targetBranch = 'master'
title = 'title'
description = 'description'

header = { 'PRIVATE-TOKEN' : gitlabAccessToken,
           'id'            : id,    
           'title'         : title, 
           'source_branch' : sourceBranch, 
           'target_branch' : targetBranch
         }

reply = requests.post(MR, headers = header)
status = json.loads(reply.text)

but I keep getting the following message in the reply

{'error': 'title is missing, source_branch is missing, target_branch is missing'}

What should I change in my request to make it work?

like image 938
Ali Avatar asked Jul 31 '17 01:07

Ali


1 Answers

Apart from PRIVATE-TOKEN, all the parameters should be passed as form-encoded parameters, meaning:

header = {'PRIVATE-TOKEN' : gitlabAccessToken}
params = {
           'id'            : id,    
           'title'         : title, 
           'source_branch' : sourceBranch, 
           'target_branch' : targetBranch
         }

reply = requests.post(MR, data=params, headers=header)
like image 165
Yigal Avatar answered Sep 22 '22 12:09

Yigal