Gitlab Post / Put in Node with an Axios or Curl request - cannot write resource - error 400

When using the Gitlab api, I cannot get anything to publish it if its value "Content-Type": "text/plain". I also tried a curl request, I can use GET, but also no luck with POST / PUT.

I went through and made sure that I opened the access as public as possible, checked the availability of the public key, etc. still out of luck.

Work

let url = window.djConfig.DJ_URL + "api/v1/git" + "/project/directory";
 axios.put(url, 'stuff',{
  headers: {
    "Content-Type": "text/plain"
   }
  })
  .then(function (res) {
    //do success stuff
  })
  .catch(function (err) {
    //do error stuff
 })

curl --request GET --header 'PRIVATE-TOKEN: ycEKE_uSQiRXzMtrZuZU' 'https://gitlab.example.com/api/v4/git/journey-content/bower%2Ejson?ref=master'

But if I try to do something more stable, like adding a commit message, I get an error message:

{"message":"Unable to write resource.","status":400}

I have more reliable Axios created as such

Does not work

let url = window.djConfig.DJ_URL + "api/v1/git" + "/project/directory";
let commit = {
  file_path: 'project/directory',
  branch: 'master',
  content: '{key: "value"}',
  commit_message: 'test commit'
}

axios.put(url, commit,{
   headers: {
    "Content-Type": "application/json"
   }
})
.then(function (res) {
   // do success stuff
})
.catch(function (err) {
  // do error stuff
})


curl --request POST --header 'PRIVATE-TOKEN: ycEKE_uSQiRXzMtrZuZU' 'http://localhost:8911/developerjourney/api/v1/git/journey-content/projectrb%2E?branch=master&author_email=author%40example.com&author_name=Firstname%20Lastname&content=some%20content&commit_message=create%20a%20new%20file'

I love how Gitlab provides this useless information ...

- , 400 . :

file_path /../( ); , ; Git, . gitlab-shell boolean return code, GitLab .

, , , , , /.

, --verbose

*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8911 (#0)
> POST /developerjourney/api/v1/git/journey-content/projectrb%2E?branch=master&author_email=author%40example.com&author_name=Firstname%20Lastname&content=some%20content&commit_message=create%20a%20new%20file HTTP/1.1
> Host: localhost:8911
> User-Agent: curl/7.54.0
> Accept: */*
> PRIVATE-TOKEN: ycEKE_uSQiRXzMtrZuZU
> 
< HTTP/1.1 400 Bad Request
< X-Powered-By: Express
< X-DJ-Redirect-URL: http://localhost:8911/developerjourney/authenticate
< X-DJ-GitLab-Host: https://localhost:30443
< X-DJ-GitLab-Path: 
< X-DJ-GitLab-Application-Id: 513ce27b4c730d461fa68ceae3eab23f726dc975c3d250de79af8d301f74f4f7
< X-DJ-JourneyGroup: journeys
< X-DJ-URL: http://localhost:8911/developerjourney/
< Set-Cookie: dj-session=18245958cb989b009e7417d76b62331a; Max-Age=1209600; Path=/; Expires=Fri, 05 Jan 2018 19:46:56 GMT; HttpOnly
< Content-Type: application/json; charset=utf-8
< Content-Length: 52
< ETag: W/"34-mpqGlVzme26p5gWU36ILGyMDScQ"
< Date: Fri, 22 Dec 2017 19:46:56 GMT
< Connection: keep-alive
< 
* Connection #0 to host localhost left intact
{"message":"Unable to write resource.","status":400}

, v4 api

curl --request POST --header 'PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK' 'http://localhost:8911/developerjourney/api/v4/projects/2/journey-content/app%2Fprojectrb%2E?branch=master&content=some%20content&commit_message=create%20a%20new%20file'

, HTML. "travel-content" - , ""

+4
1

API. /projects api,

let url = window.djConfig.DJ_URL + "api/v4/" + "projects?owned=true";

-

[
    {
        "id": XXXXX,
        "description": "",
        "name": "testapi",
        "name_with_namespace": "XXXX / testapi",
        "path": "testapi",
        "path_with_namespace": "XXX/testapi",
        "created_at": "2017-12-24T19:09:11.192Z",
        "default_branch": null,
        "tag_list": [],
        "ssh_url_to_repo": "git@gitlab.com:xxx/testapi.git",
        "http_url_to_repo": "https://gitlab.com/xxx/testapi.git",

let url = window.djConfig.DJ_URL + "api/v4" + "/projects/<id>/repository/commits";

{
  "branch": "master",
  "commit_message": "some commit message",
  "actions": [
    {
      "action": "create",
      "file_path": "foo/bar",
      "content": "some content"
    }
  ]
}

JSON

[
    {
        "id": "cbf63f8050ed033565e28f8d62288d9f6a8be1a7",
        "short_id": "cbf63f80",
        "title": "Add new file",
        "created_at": "2017-12-24T19:23:34.000+00:00",
        "parent_ids": [],
        "message": "Add new file",
        "author_name": "xxx xxx",
        "author_email": "xxx@xxx.com",
        "authored_date": "2017-12-24T19:23:34.000+00:00",
        "committer_name": "xxx xxx",
        "committer_email": "xxx@xxxx.com",
        "committed_date": "2017-12-24T19:23:34.000+00:00"
    }
]

curl --request POST --header 'PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK' 'https://gitlab.example.com/api/v4/projects/13083/repository/files/app%2Fprojectrb%2E?branch=master&author_email=author%40example.com&author_name=Firstname%20Lastname&content=some%20content&commit_message=create%20a%20new%20file'

, URL-

+3

Source: https://habr.com/ru/post/1691057/


All Articles