{"url":"https://api.github.com/gists/5ef5e8dbf48e63e2172a573f7b32c638","forks_url":"https://api.github.com/gists/5ef5e8dbf48e63e2172a573f7b32c638/forks","commits_url":"https://api.github.com/gists/5ef5e8dbf48e63e2172a573f7b32c638/commits","id":"5ef5e8dbf48e63e2172a573f7b32c638","node_id":"MDQ6R2lzdDVlZjVlOGRiZjQ4ZTYzZTIxNzJhNTczZjdiMzJjNjM4","git_pull_url":"https://gist.github.com/5ef5e8dbf48e63e2172a573f7b32c638.git","git_push_url":"https://gist.github.com/5ef5e8dbf48e63e2172a573f7b32c638.git","html_url":"https://gist.github.com/michaellihs/5ef5e8dbf48e63e2172a573f7b32c638","files":{"gitlab_access_token.md":{"filename":"gitlab_access_token.md","type":"text/markdown","language":"Markdown","raw_url":"https://gist.githubusercontent.com/michaellihs/5ef5e8dbf48e63e2172a573f7b32c638/raw/56c388c52f1f338816a67b2894d7e341956a1df5/gitlab_access_token.md","size":2724,"truncated":false,"content":"Create Gitlab Personal Access Token using curl\n==============================================\n\nPrerequisites\n-------------\n\n* You need a Gitlab server up and running\n* You need user credentials for a (admin) user on the Gitlab server\n* You need curl and Perl on your server\n\nWhat does it do?\n----------------\n\n1. Open the login page of Gitlab to get session cookie\n1. Login to Gitlab using username and password to get authenticated session cookie\n1. Open the *Personal Access Tokens* page\n1. POSTing the Personal Access Token for to generate a personal access token\n1. Scrape the personal access token from the returned HTML page\n\nCode\n----\n\n```` bash\ngitlab_host=\"http://localhost:8080\"\ngitlab_user=\"root\"\ngitlab_password=\"12341234\"\n\n# 1. curl for the login page to get a session cookie and the sources with the auth tokens\nbody_header=$(curl -c cookies.txt -i \"${gitlab_host}/users/sign_in\" -s)\n\n# grep the auth token for the user login for\n#   not sure whether another token on the page will work, too - there are 3 of them\ncsrf_token=$(echo $body_header | perl -ne 'print \"$1\\n\" if /new_user.*?authenticity_token\"[[:blank:]]value=\"(.+?)\"/' | sed -n 1p)\n\n# 2. send login credentials with curl, using cookies and token from previous request\ncurl -b cookies.txt -c cookies.txt -i \"${gitlab_host}/users/sign_in\" \\\n\t--data \"user[login]=${gitlab_user}&user[password]=${gitlab_password}\" \\\n\t--data-urlencode \"authenticity_token=${csrf_token}\"\n\n# 3. send curl GET request to personal access token page to get auth token\nbody_header=$(curl -H 'user-agent: curl' -b cookies.txt -i \"${gitlab_host}/profile/personal_access_tokens\" -s)\ncsrf_token=$(echo $body_header | perl -ne 'print \"$1\\n\" if /authenticity_token\"[[:blank:]]value=\"(.+?)\"/' | sed -n 1p)\n\n# 4. curl POST request to send the \"generate personal access token form\"\n#      the response will be a redirect, so we have to follow using `-L`\nbody_header=$(curl -L -b cookies.txt \"${gitlab_host}/profile/personal_access_tokens\" \\\n\t--data-urlencode \"authenticity_token=${csrf_token}\" \\\n\t--data 'personal_access_token[name]=golab-generated&personal_access_token[expires_at]=&personal_access_token[scopes][]=api')\n\n# 5. Scrape the personal access token from the response HTML\npersonal_access_token=$(echo $body_header | perl -ne 'print \"$1\\n\" if /created-personal-access-token\"[[:blank:]]value=\"(.+?)\"/' | sed -n 1p)\n````\n\nUsage of token in API Requests\n------------------------------\n\nAccording to the [Gitlab API documentation](https://docs.gitlab.com/ce/api/README.html#personal-access-tokens), you can now use the `personal_access_token` to make API requests:\n\n````bash\ncurl --header \"Private-Token: ${personal_access_token}\" https://gitlab.example.com/api/v4/projects\n````","encoding":"utf-8"}},"public":true,"created_at":"2017-12-23T22:31:03Z","updated_at":"2025-06-20T12:40:45Z","description":"Create Gitlab Personal Access Token using curl","comments":16,"user":null,"comments_enabled":true,"comments_url":"https://api.github.com/gists/5ef5e8dbf48e63e2172a573f7b32c638/comments","owner":{"login":"michaellihs","id":575011,"node_id":"MDQ6VXNlcjU3NTAxMQ==","avatar_url":"https://avatars.githubusercontent.com/u/575011?v=4","gravatar_id":"","url":"https://api.github.com/users/michaellihs","html_url":"https://github.com/michaellihs","followers_url":"https://api.github.com/users/michaellihs/followers","following_url":"https://api.github.com/users/michaellihs/following{/other_user}","gists_url":"https://api.github.com/users/michaellihs/gists{/gist_id}","starred_url":"https://api.github.com/users/michaellihs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaellihs/subscriptions","organizations_url":"https://api.github.com/users/michaellihs/orgs","repos_url":"https://api.github.com/users/michaellihs/repos","events_url":"https://api.github.com/users/michaellihs/events{/privacy}","received_events_url":"https://api.github.com/users/michaellihs/received_events","type":"User","user_view_type":"public","site_admin":false},"forks":[{"url":"https://api.github.com/gists/fa49cbc594840737ce69886d858319ec","user":{"login":"afahounko","id":2297648,"node_id":"MDQ6VXNlcjIyOTc2NDg=","avatar_url":"https://avatars.githubusercontent.com/u/2297648?v=4","gravatar_id":"","url":"https://api.github.com/users/afahounko","html_url":"https://github.com/afahounko","followers_url":"https://api.github.com/users/afahounko/followers","following_url":"https://api.github.com/users/afahounko/following{/other_user}","gists_url":"https://api.github.com/users/afahounko/gists{/gist_id}","starred_url":"https://api.github.com/users/afahounko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/afahounko/subscriptions","organizations_url":"https://api.github.com/users/afahounko/orgs","repos_url":"https://api.github.com/users/afahounko/repos","events_url":"https://api.github.com/users/afahounko/events{/privacy}","received_events_url":"https://api.github.com/users/afahounko/received_events","type":"User","user_view_type":"public","site_admin":false,"name":"Danny","company":"Red Hat","blog":"","location":"Paris - France","email":null,"hireable":null,"bio":"Network Engineer with SDN in my DNA.\r\nCloud Infrastructure architect.\r\nOpen-Source and IPv6 evangelist.","twitter_username":null,"public_repos":124,"public_gists":21,"followers":17,"following":9,"created_at":"2012-09-07T08:07:13Z","updated_at":"2026-05-04T07:43:36Z"},"id":"fa49cbc594840737ce69886d858319ec","created_at":"2019-05-28T16:17:35Z","updated_at":"2019-05-28T16:17:35Z"},{"url":"https://api.github.com/gists/cfc3cd9cff00b70e4cdec6b4b8813964","user":{"login":"eldorplus","id":1168143,"node_id":"MDQ6VXNlcjExNjgxNDM=","avatar_url":"https://avatars.githubusercontent.com/u/1168143?v=4","gravatar_id":"","url":"https://api.github.com/users/eldorplus","html_url":"https://github.com/eldorplus","followers_url":"https://api.github.com/users/eldorplus/followers","following_url":"https://api.github.com/users/eldorplus/following{/other_user}","gists_url":"https://api.github.com/users/eldorplus/gists{/gist_id}","starred_url":"https://api.github.com/users/eldorplus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eldorplus/subscriptions","organizations_url":"https://api.github.com/users/eldorplus/orgs","repos_url":"https://api.github.com/users/eldorplus/repos","events_url":"https://api.github.com/users/eldorplus/events{/privacy}","received_events_url":"https://api.github.com/users/eldorplus/received_events","type":"User","user_view_type":"public","site_admin":false,"name":"Patrick Luzolo","company":"Perso","blog":"","location":"France","email":"eldorplus@gmail.com","hireable":null,"bio":null,"twitter_username":null,"public_repos":297,"public_gists":89,"followers":57,"following":112,"created_at":"2011-11-02T18:58:10Z","updated_at":"2026-05-10T17:49:31Z"},"id":"cfc3cd9cff00b70e4cdec6b4b8813964","created_at":"2019-10-22T06:39:06Z","updated_at":"2019-10-22T06:39:06Z"},{"url":"https://api.github.com/gists/3ff8df6740f9c1bf0046b17f66784a89","user":{"login":"liuzongyao","id":19768704,"node_id":"MDQ6VXNlcjE5NzY4NzA0","avatar_url":"https://avatars.githubusercontent.com/u/19768704?v=4","gravatar_id":"","url":"https://api.github.com/users/liuzongyao","html_url":"https://github.com/liuzongyao","followers_url":"https://api.github.com/users/liuzongyao/followers","following_url":"https://api.github.com/users/liuzongyao/following{/other_user}","gists_url":"https://api.github.com/users/liuzongyao/gists{/gist_id}","starred_url":"https://api.github.com/users/liuzongyao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liuzongyao/subscriptions","organizations_url":"https://api.github.com/users/liuzongyao/orgs","repos_url":"https://api.github.com/users/liuzongyao/repos","events_url":"https://api.github.com/users/liuzongyao/events{/privacy}","received_events_url":"https://api.github.com/users/liuzongyao/received_events","type":"User","user_view_type":"public","site_admin":false,"name":null,"company":null,"blog":"","location":null,"email":"highcareer@126.com","hireable":null,"bio":null,"twitter_username":null,"public_repos":25,"public_gists":1,"followers":0,"following":0,"created_at":"2016-06-06T02:55:53Z","updated_at":"2026-04-03T02:27:09Z"},"id":"3ff8df6740f9c1bf0046b17f66784a89","created_at":"2020-05-08T10:18:15Z","updated_at":"2020-05-08T10:18:16Z"},{"url":"https://api.github.com/gists/fc56166f03c7487c84a3de5ce1abfb9d","user":{"login":"feedsbrain","id":1344157,"node_id":"MDQ6VXNlcjEzNDQxNTc=","avatar_url":"https://avatars.githubusercontent.com/u/1344157?v=4","gravatar_id":"","url":"https://api.github.com/users/feedsbrain","html_url":"https://github.com/feedsbrain","followers_url":"https://api.github.com/users/feedsbrain/followers","following_url":"https://api.github.com/users/feedsbrain/following{/other_user}","gists_url":"https://api.github.com/users/feedsbrain/gists{/gist_id}","starred_url":"https://api.github.com/users/feedsbrain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/feedsbrain/subscriptions","organizations_url":"https://api.github.com/users/feedsbrain/orgs","repos_url":"https://api.github.com/users/feedsbrain/repos","events_url":"https://api.github.com/users/feedsbrain/events{/privacy}","received_events_url":"https://api.github.com/users/feedsbrain/received_events","type":"User","user_view_type":"public","site_admin":false,"name":"Indra Gunawan","company":"@setel-engineering","blog":"https://indragunawan.com","location":"Kuala Lumpur, Malaysia","email":"indra.gunawan@setel.com","hireable":null,"bio":"Multipotentialite | Free Spirit","twitter_username":"feedsbrain","public_repos":67,"public_gists":12,"followers":102,"following":57,"created_at":"2012-01-18T10:16:05Z","updated_at":"2026-05-08T02:20:06Z"},"id":"fc56166f03c7487c84a3de5ce1abfb9d","created_at":"2020-11-02T04:21:12Z","updated_at":"2020-11-02T04:21:12Z"},{"url":"https://api.github.com/gists/c51fac36e11336ad64f698c8d72d1bb8","user":{"login":"jdluna","id":4078215,"node_id":"MDQ6VXNlcjQwNzgyMTU=","avatar_url":"https://avatars.githubusercontent.com/u/4078215?v=4","gravatar_id":"","url":"https://api.github.com/users/jdluna","html_url":"https://github.com/jdluna","followers_url":"https://api.github.com/users/jdluna/followers","following_url":"https://api.github.com/users/jdluna/following{/other_user}","gists_url":"https://api.github.com/users/jdluna/gists{/gist_id}","starred_url":"https://api.github.com/users/jdluna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdluna/subscriptions","organizations_url":"https://api.github.com/users/jdluna/orgs","repos_url":"https://api.github.com/users/jdluna/repos","events_url":"https://api.github.com/users/jdluna/events{/privacy}","received_events_url":"https://api.github.com/users/jdluna/received_events","type":"User","user_view_type":"public","site_admin":false,"name":"Dario Luna","company":null,"blog":"","location":"Lima","email":null,"hireable":null,"bio":null,"twitter_username":"jdluna","public_repos":508,"public_gists":20,"followers":3,"following":19,"created_at":"2013-04-06T15:40:09Z","updated_at":"2026-04-09T19:19:21Z"},"id":"c51fac36e11336ad64f698c8d72d1bb8","created_at":"2023-07-20T04:31:38Z","updated_at":"2023-07-20T04:31:38Z"},{"url":"https://api.github.com/gists/b2b34ee9e78e59583c90512a52bdd52f","user":{"login":"anilsingla","id":50365729,"node_id":"MDQ6VXNlcjUwMzY1NzI5","avatar_url":"https://avatars.githubusercontent.com/u/50365729?v=4","gravatar_id":"","url":"https://api.github.com/users/anilsingla","html_url":"https://github.com/anilsingla","followers_url":"https://api.github.com/users/anilsingla/followers","following_url":"https://api.github.com/users/anilsingla/following{/other_user}","gists_url":"https://api.github.com/users/anilsingla/gists{/gist_id}","starred_url":"https://api.github.com/users/anilsingla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anilsingla/subscriptions","organizations_url":"https://api.github.com/users/anilsingla/orgs","repos_url":"https://api.github.com/users/anilsingla/repos","events_url":"https://api.github.com/users/anilsingla/events{/privacy}","received_events_url":"https://api.github.com/users/anilsingla/received_events","type":"User","user_view_type":"public","site_admin":false,"name":"ANIL SINGLA","company":"Wipro Ltd.","blog":"","location":"Gurugram","email":"anilsingla111@gmail.com","hireable":null,"bio":"With a considerable amount of experience in software industry since last 16 years, I am loving to explore and contribute to new technologies and spaces. ","twitter_username":null,"public_repos":166,"public_gists":1,"followers":1,"following":8,"created_at":"2019-05-07T11:50:23Z","updated_at":"2026-05-21T14:36:10Z"},"id":"b2b34ee9e78e59583c90512a52bdd52f","created_at":"2024-03-18T05:09:30Z","updated_at":"2024-03-18T05:09:30Z"}],"history":[{"user":{"login":"michaellihs","id":575011,"node_id":"MDQ6VXNlcjU3NTAxMQ==","avatar_url":"https://avatars.githubusercontent.com/u/575011?v=4","gravatar_id":"","url":"https://api.github.com/users/michaellihs","html_url":"https://github.com/michaellihs","followers_url":"https://api.github.com/users/michaellihs/followers","following_url":"https://api.github.com/users/michaellihs/following{/other_user}","gists_url":"https://api.github.com/users/michaellihs/gists{/gist_id}","starred_url":"https://api.github.com/users/michaellihs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaellihs/subscriptions","organizations_url":"https://api.github.com/users/michaellihs/orgs","repos_url":"https://api.github.com/users/michaellihs/repos","events_url":"https://api.github.com/users/michaellihs/events{/privacy}","received_events_url":"https://api.github.com/users/michaellihs/received_events","type":"User","user_view_type":"public","site_admin":false},"version":"7875ce12d24a129a1c89eb4876362371a005948a","committed_at":"2017-12-23T22:49:44Z","change_status":{"total":2,"additions":1,"deletions":1},"url":"https://api.github.com/gists/5ef5e8dbf48e63e2172a573f7b32c638/7875ce12d24a129a1c89eb4876362371a005948a"},{"user":{"login":"michaellihs","id":575011,"node_id":"MDQ6VXNlcjU3NTAxMQ==","avatar_url":"https://avatars.githubusercontent.com/u/575011?v=4","gravatar_id":"","url":"https://api.github.com/users/michaellihs","html_url":"https://github.com/michaellihs","followers_url":"https://api.github.com/users/michaellihs/followers","following_url":"https://api.github.com/users/michaellihs/following{/other_user}","gists_url":"https://api.github.com/users/michaellihs/gists{/gist_id}","starred_url":"https://api.github.com/users/michaellihs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaellihs/subscriptions","organizations_url":"https://api.github.com/users/michaellihs/orgs","repos_url":"https://api.github.com/users/michaellihs/repos","events_url":"https://api.github.com/users/michaellihs/events{/privacy}","received_events_url":"https://api.github.com/users/michaellihs/received_events","type":"User","user_view_type":"public","site_admin":false},"version":"52d782377a33ba259aa1f4b3ddccaac6554f650c","committed_at":"2017-12-23T22:49:07Z","change_status":{"total":32,"additions":22,"deletions":10},"url":"https://api.github.com/gists/5ef5e8dbf48e63e2172a573f7b32c638/52d782377a33ba259aa1f4b3ddccaac6554f650c"},{"user":{"login":"michaellihs","id":575011,"node_id":"MDQ6VXNlcjU3NTAxMQ==","avatar_url":"https://avatars.githubusercontent.com/u/575011?v=4","gravatar_id":"","url":"https://api.github.com/users/michaellihs","html_url":"https://github.com/michaellihs","followers_url":"https://api.github.com/users/michaellihs/followers","following_url":"https://api.github.com/users/michaellihs/following{/other_user}","gists_url":"https://api.github.com/users/michaellihs/gists{/gist_id}","starred_url":"https://api.github.com/users/michaellihs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaellihs/subscriptions","organizations_url":"https://api.github.com/users/michaellihs/orgs","repos_url":"https://api.github.com/users/michaellihs/repos","events_url":"https://api.github.com/users/michaellihs/events{/privacy}","received_events_url":"https://api.github.com/users/michaellihs/received_events","type":"User","user_view_type":"public","site_admin":false},"version":"a6ed614c0d43f05e98e506674c75aa3c7c81c618","committed_at":"2017-12-23T22:37:41Z","change_status":{"total":9,"additions":6,"deletions":3},"url":"https://api.github.com/gists/5ef5e8dbf48e63e2172a573f7b32c638/a6ed614c0d43f05e98e506674c75aa3c7c81c618"},{"user":{"login":"michaellihs","id":575011,"node_id":"MDQ6VXNlcjU3NTAxMQ==","avatar_url":"https://avatars.githubusercontent.com/u/575011?v=4","gravatar_id":"","url":"https://api.github.com/users/michaellihs","html_url":"https://github.com/michaellihs","followers_url":"https://api.github.com/users/michaellihs/followers","following_url":"https://api.github.com/users/michaellihs/following{/other_user}","gists_url":"https://api.github.com/users/michaellihs/gists{/gist_id}","starred_url":"https://api.github.com/users/michaellihs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaellihs/subscriptions","organizations_url":"https://api.github.com/users/michaellihs/orgs","repos_url":"https://api.github.com/users/michaellihs/repos","events_url":"https://api.github.com/users/michaellihs/events{/privacy}","received_events_url":"https://api.github.com/users/michaellihs/received_events","type":"User","user_view_type":"public","site_admin":false},"version":"f12d115e1c5b17960e84373b661c263e2c7c1c74","committed_at":"2017-12-23T22:37:04Z","change_status":{"total":0,"additions":0,"deletions":0},"url":"https://api.github.com/gists/5ef5e8dbf48e63e2172a573f7b32c638/f12d115e1c5b17960e84373b661c263e2c7c1c74"},{"user":{"login":"michaellihs","id":575011,"node_id":"MDQ6VXNlcjU3NTAxMQ==","avatar_url":"https://avatars.githubusercontent.com/u/575011?v=4","gravatar_id":"","url":"https://api.github.com/users/michaellihs","html_url":"https://github.com/michaellihs","followers_url":"https://api.github.com/users/michaellihs/followers","following_url":"https://api.github.com/users/michaellihs/following{/other_user}","gists_url":"https://api.github.com/users/michaellihs/gists{/gist_id}","starred_url":"https://api.github.com/users/michaellihs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaellihs/subscriptions","organizations_url":"https://api.github.com/users/michaellihs/orgs","repos_url":"https://api.github.com/users/michaellihs/repos","events_url":"https://api.github.com/users/michaellihs/events{/privacy}","received_events_url":"https://api.github.com/users/michaellihs/received_events","type":"User","user_view_type":"public","site_admin":false},"version":"83b3678b0be98bd8cb17d75831feec96500921a4","committed_at":"2017-12-23T22:34:00Z","change_status":{"total":11,"additions":0,"deletions":11},"url":"https://api.github.com/gists/5ef5e8dbf48e63e2172a573f7b32c638/83b3678b0be98bd8cb17d75831feec96500921a4"},{"user":{"login":"michaellihs","id":575011,"node_id":"MDQ6VXNlcjU3NTAxMQ==","avatar_url":"https://avatars.githubusercontent.com/u/575011?v=4","gravatar_id":"","url":"https://api.github.com/users/michaellihs","html_url":"https://github.com/michaellihs","followers_url":"https://api.github.com/users/michaellihs/followers","following_url":"https://api.github.com/users/michaellihs/following{/other_user}","gists_url":"https://api.github.com/users/michaellihs/gists{/gist_id}","starred_url":"https://api.github.com/users/michaellihs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaellihs/subscriptions","organizations_url":"https://api.github.com/users/michaellihs/orgs","repos_url":"https://api.github.com/users/michaellihs/repos","events_url":"https://api.github.com/users/michaellihs/events{/privacy}","received_events_url":"https://api.github.com/users/michaellihs/received_events","type":"User","user_view_type":"public","site_admin":false},"version":"283eb0ddeedc4cbcd89762d46ae2d8c221ada46e","committed_at":"2017-12-23T22:31:28Z","change_status":{"total":2,"additions":0,"deletions":2},"url":"https://api.github.com/gists/5ef5e8dbf48e63e2172a573f7b32c638/283eb0ddeedc4cbcd89762d46ae2d8c221ada46e"},{"user":{"login":"michaellihs","id":575011,"node_id":"MDQ6VXNlcjU3NTAxMQ==","avatar_url":"https://avatars.githubusercontent.com/u/575011?v=4","gravatar_id":"","url":"https://api.github.com/users/michaellihs","html_url":"https://github.com/michaellihs","followers_url":"https://api.github.com/users/michaellihs/followers","following_url":"https://api.github.com/users/michaellihs/following{/other_user}","gists_url":"https://api.github.com/users/michaellihs/gists{/gist_id}","starred_url":"https://api.github.com/users/michaellihs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaellihs/subscriptions","organizations_url":"https://api.github.com/users/michaellihs/orgs","repos_url":"https://api.github.com/users/michaellihs/repos","events_url":"https://api.github.com/users/michaellihs/events{/privacy}","received_events_url":"https://api.github.com/users/michaellihs/received_events","type":"User","user_view_type":"public","site_admin":false},"version":"06d932f4c71e129e9969f182bb80cdb3a3cbe66e","committed_at":"2017-12-23T22:31:02Z","change_status":{"total":59,"additions":59,"deletions":0},"url":"https://api.github.com/gists/5ef5e8dbf48e63e2172a573f7b32c638/06d932f4c71e129e9969f182bb80cdb3a3cbe66e"}],"truncated":false}