Gitlab Commit API returns Bad Request Error

I am trying to push some file as an update to gitlab using Gitlab v4 REST API but seeing issues.

Request Body:

const reqBody = {
            uri: `${GITLAB_URL}/projects/123/repository/commits`,
            headers: {
                'PRIVATE-TOKEN': GITLAB_TOKEN,
                'Content-Type': 'application/json'
            },
            data: {
                'branch': 'testBranch',
                'commit_message': 'testing MR commit',
                'actions': [
                    {
                        'action': 'update',
                        'file_path': 'dir/file_abc.eyaml',
                        'content': 'updatedFileContent'
                    }
                ]
            }
        }
const resp = await request.post(reqBody);

While running this, I see the response as:

"400 - "{\"error\":\"branch is missing, branch is empty, commit_message is missing, actions is missing\"}""

Am I missing something in the request body? I have been following this Gitlab API reference: https://docs.gitlab.com/ee/api/commits.html#create-a-commit-with-multiple-files-and-actions .

Thanks!

1 Like