Create a new branch via REST API

rest-api

#1

Hi,
I need to create a new branch via REST API and I’m using guzzle to perform the post request to the endpoint.
In my payload I have added:

'form_params' => [
    'name' => 'master,
    'target' => [
        'hash' => 'default'
    ]
]

but each time I try to submit the request the API responds with a 400 status and this message:

{“target”:“required key not provided”}

How can I solve?


#2

Hi,
I’m not a PHP developer and am not familiar with the Guzzle API, but it looks like this request is likely going to try and somehow coax nested data into a form post. With a quick look at the docs, I’d suggest trying something like:

$client->request('PUT', '/2.0/repositories/{username}/{repo_slug}/refs/branches', 
                             ['json' => [
                                  'name' => 'master',
                                  'target' => [
                                      'hash' => 'default'
                                 ]
                            ]);