gitlab API unathorized - api

I tried to create a project by importing manually my git repo. I followed that tutorial :
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/raketasks/import.md
At the end I got that error :
* Failed trying to create xxx (xxx/xxx.git)
Errors: {:base=>["Failed to create repository via gitlab-shell"]}
By reading gitlab-shell.log file I discover that access to the API is forbidden I got the following error :
{"message":"401 Unauthorized"}
With that URL :
https://xxx/api/v4/internal/check
Do you know how can I fix this ?

You have to make a HTTP Post request in order to achieve this.
Clearly, according to https://docs.gitlab.com/ee/api/README.html you do not have the authorization. This is because you are not using the Gitlab Private token.
You can go to Profile -> settings -> generate a Private token. Once generated, copy it to your clipboard and use it in your post request.
Best way to use it is by Curl:
Ex:
curl --request POST --header "PRIVATE-TOKEN: XXXX -k "https://example.com//api/v4/projects/11/jobs/16863/retry"

u need to genrate private Token :
open your account gitlab -> settings->genrate private Token

Related

problem with my API in Jenkins: Invalid password/token for user:

When i try to connect to my Api with basic authentification on my Jenkinsfile after successfully running my container: (toto is the username/python is the password)
curl -u toto:python -X GET http://0.0.0.0:8080/pozos/api/v1.0/get_student_ages
i received this error in my console Output on my Jenkins server:
Error 401 Invalid password/token for user: toto
HTTP ERROR 401
Problem accessing /pozos/api/v1.0/get_student_ages. Reason:
Invalid password/token for user: toto
Jenkins successfully builds my dockerfile and runs my container on the port 8080,i don't understand why it doesn't work...everything works normally when i don't use Jenkins,
Thanks so much for your help
I think the password will not work. You will need to create an API Token for the user. And then use that token as the password in the call.
So your call will be changed to
curl -u toto:<token> -X GET http://0.0.0.0:8080/pozos/api/v1.0/get_student_ages
Here is the link on how to generate and use the token
https://wiki.jenkins.io/display/JENKINS/Authenticating+scripted+clients
The API token is available in your personal configuration page. Click your name on the top right corner on every page, then click
"Configure" to see your API token. (The URL $root/me/configure is a
good shortcut.) You can also change your API token from here.

Autodesk Forge Authentication - "The client_id specified does not have access to the api product"

Trying to follow tutorials but cannot get past authentication. From OSX shell:
curl -v 'https://developer.api.autodesk.com/authentication/v1/authenticate' -X 'POST' -H 'Content-Type: application/x-www-form-urlencoded' -d 'client_id=MY_CLIENT_ID&client_secret=MY_SECRET&grant_type=client_credentials&scope=data:read'
I get back:
...
* Connection #0 to host developer.api.autodesk.com left intact
{ "developerMessage":"The client_id specified does not have access to the api product","userMessage":"","errorCode":"AUTH-001","more info":"http://developer.api.autodesk.com/documentation/v1/errors/AUTH-001"}
I have enabled all of the APIs in the app's configuration page.
I regenerated the secret key twice - same result.
If I had screwed up the client_id/secret key somehow, it looks like I would get an AUTH-003 error so I don't think that is the problem.
Documentation lists several possible errors but not AUTH-001.
Any ideas on how to debug this?
TIA
Only way to get past that was to delete that app and create a whole new one from scratch. The new ID/Secret works.

Bitbucket API 2.0 - list of private repositories

It is possible to get all user repositories using Bitbucket API 2.0 including private repositories? When I use https://api.bitbucket.org/2.0/repositories/{username} i got only public.
Resolved, just have to get access token from bitbucket and send GET to https://api.bitbucket.org/2.0/repositories with Authorization: Bearer {YOUR ACCESS TOKEN}.
Because I got stuck, here a little complement #Łukasz Strzałka post.
To get an access token you have to create a consumer. It's described here https://confluence.atlassian.com/bitbucket/oauth-on-bitbucket-cloud-238027431.html (Thanks #Łukasz Strzałka)
You have to go to your Team Account: Click on your user icon -> choose your Team -> Settings -> OAuth
Add a consumer. The minimum is to set a title and a callback URL. Then you will get a key and a secret.
curl in terminal
curl -X POST -u "your_key:your_secret" \
https://bitbucket.org/site/oauth2/access_token -d grant_type=password \
-d username={username} -d password={password}
The response should be a token.

Not able to download log files using following API

We are not able to download log files. Once run below command, it is getting unable to parse object filter.
curl -X GET -u : -g https://api.service.softlayer.com/rest/v3/SoftLayer_Event_Log/getAllObjects.json
I'm able to retrieve the Event Logs through SoftLayer's private network, I used the same request:
curl -X GET -u $user:$apiKey -g https://api.service.softlayer.com/rest/v3/SoftLayer_Event_Log/getAllObjects.json
According to the exception, it seems that you are sending something else in the request.
Are you able to make others api calls? can you try again please? Did you have success before with this request?
Also, can you try with the public endpoint: https://api.softlayer.com instead of https://api.service.softlayer.com

github api - create repo

I'm trying to create a repo using Github API, but it always return this JSON:
{"message":"Not Found"}
But this error appears only when I try to create using OAuth access token in request header, if I use username and password, API create the repo and return a successful message.
Anyone had problems with this API endpoint?
You can create a new repository using the Python library, PyGithub.
from github import Github
g = Github("your username", "your password")
g = Github("your token") # safer alternative, if you have an access token
u = g.get_user()
repo = u.create_repo("name-of-your-repo")
This should solve your problem.
I had a different message come up with this
curl -i -d '{"name":"NAME"}' https://api.github.com/orgs/:ORG/repos?access_token=XXX
{
"message": "Must be an owner or admin of Organization."
}
But still not sure why I cannot create either
Ok
This worked for me
Create Auth Token
curl -u 'iwarner' -d '{"scopes":["repo"],"note":":NAME"}' https://api.github.com/authorizations
Create Repo - Need to contain "Authorization: token"
curl -i -H 'Authorization: token TOKENHERE' -d '{"name":":NAME"}' https://api.github.com/user/repos
This works, just tried it.
curl -F 'login=c00kiemon5ter' -F 'token=s3cr3t' https://github.com/api/v2/json/repos/create -F 'name=testapi' -F 'public=0'
Are we talking about API v2 or v3 ?
I do not know what technology you are using. But just in case of iOS, you can use this demo app which describes 3 simple ways to interact with the GitHub API.
Note: This demo app provide only few selected functionality.
GitHub-Interaction
Hope this helps!!
As of today, the GitHub v3 API documentation explicitly states:
Create
Create a new repository for the authenticated user. (Currently not enabled for Integrations)
EDIT:
The "not enabled for Integrations" means, if you get your OAuth token via one of your OAuth apps (which is an "integration") the GitHub API will refuse to create a repository with that function.
However, if you use some other access token (e.g. a personal access token you add yourself, see below) then the GitHub API will happily create a repository for you with the very same API call.
curl -u your_username -d '{"scopes":["repo"], "note":"Description of personal token"}' https://api.github.com/authorizations
That's the reason why the solution presented by Ian Warner works. The solution with PyGithub will suffer the same limitation. Only the token makes the difference!
EDIT: Not entirely true: With OAuth you can specify the scope to attach specific permissions to your OAuth token when authenticating (OAuth app flow). For creating repositories you need to have the 'repo' scope. (See also: Github v3 API - create a REPO)