Search code examples
apicurlgitlabgitlab-api

Gitlab API: How to generate the private token


This is what I tried:

curl http://git.ep.petrobras.com.br/api/v3/session --data-urlencode 'login=myUser&password=myPass'

Answer:

{"message":"401 Unauthorized"}


Solution

  • The problem is the data-urlencode CURL option. Since it's an HTTP POST you don't need to URL encode the data, and is actually encoding the & into & and causing your issue. Instead use the --data option.

    curl http://git.ep.petrobras.com.br/api/v3/session --data 'login=myUser&password=myPass'
    

    Also, be careful sending credentials over plain HTTP. It could be easily sniffed.