Gitlab API to create a new file in repository not working

API to create a new file in repository not working if file content is multiline

ISSUE:

  • I am trying to create a new file in repository by API, Its working only if content of file is simple string. If I try to have a content like below screenshot (multiline content) , then I get 400 bad request.
    image

  • currently I am using GitLab Community Edition v16.6.2

  • I can read file, I delete the file both successfully by API, but I am not able to create file with multiline content.

  • I tried to use single line simple string like below api -

curl --request POST --header ‘PRIVATE-TOKEN: <your_access_token>’
–header “Content-Type: application/json”
–data ‘{“branch”: “main”, “author_email”: “author@example.com”, “author_name”: “Firstname Lastname”,
content”: “some content”, “commit_message”: “create a new file”}’
https://gitlab.example.com/api/v4/projects/13083/repository/files/app%2Fproject.rb

  • Only if the content is simple string like above its working, but if its like above screenshot multiline with escape characters, its not working.