Gitlab API adding members to a project - gitlab

I'm experiencing errors when trying to add users to a Gitlab project using the Gitlab API. I'm using Gitlab version 8.11.0 on CentOS 6.8 and I'm not sure if it is a bug or something I am doing wrong.
The following works fine and gives me a list of project members:
curl --header "PRIVATE-TOKEN: top_secret" "https://thegitlabserver.com/api/v3/projects/1/members"
but when trying to add a members with the following, I get an error message:
curl --request POST --header "PRIVATE-TOKEN: top_secret" "https://thegitlabserver.com/api/v3/projects/1/members/myusername?access_level=30"
{"error":"405 Not Allowed"}
Using the web interface I am able to add the user to the project.

It looks like the Gitlab API documentation was incorrect.
As it's a create action, you should send both the user ID and access levels as named parameters (like you would for creating any other resource).
So something like: https://thegitlabserver.com/api/v3/projects/1/members/?user_id=299&access_level=40

Related

how to create a webhook programmatically to check ADO repository has code push

I have find out this called servicehooks link
But I want to do this programmatically where I have more number of projects and want to check any of that project repository has code push event happened , if yes need to check which files are pushed as a commit.
and based on that push message into my service bus queue.
any sample code for the same? looking for azure function app for above solution.
You can subscribe to code push events using ADO public API: Subscription create API
You want your request to look like this:
curl -H "Content-Type: application/json;api-version=4.0" \
-H "Authorization: Basic $(B64_TOKEN)"
--request POST \
--data {
"publisherId": "tfs",
"eventType": "git.push",
"resourceVersion": "1.0",
"consumerId": "webHooks",
"consumerActionId": "httpRequest",
"consumerInputs": {"url": $(WEBHOOK_URL)}
}
https://dev.azure.com/$(ORGANIZATION)/_apis/hooks/subscriptions
This will subscribe you to all code push on all your repositories of all your projects of your organization.
When you receive a code push notification (see documentation), you can extract the commit ids from the resource object (you might need to fetch the Push object using the API).
Then you can inspect which file are impacted with the Commit API.
If you want to see the file diff, there is also an undocumented API.

Continuous deployment gitlab

Line of my .gitlab-ci.yml
IID=$(curl --verbose --request GET --header "Content-Type: application/json" --header "PRIVATE-TOKEN: ${CI_PUSH_TOKEN}" ${APP_REPO_URL}/merge_requests?author_id=xxxxxxxx\&search=${CI_COMMIT_SHORT_SHA} | jq '.[0].iid')
output jq: error (at :0): Cannot index object with number
Please refer to the documentation on Merge requests API and How to use the API to construct a properly formed cURL request with GitLab API before piping the result into jq.
There are a few things going on with your query.
First of all, according to the documentation, the /merge_requests endpoint will
Get all merge requests the authenticated user has access to.
This means that APP_REPO_URL needs to be the GitLab instance URL followed by /api/v4 and not the URL of the specific project.
curl "https://gitlab.example.com/api/v4/merge_requests"
If you need all merge requests for a given project, then you can use
curl "https://gitlab.example.com/api/v4/projects/:id/merge_requests"
where :id is the id of your project. See more at List project merge requests
Then, the search attribute is expecting either a title or a description and not a commit SHA:
Search merge requests against their title and description

How can I make this API call from my Nodejs program?

A member of my team developed this API where you send some numeric values and it gives you back a probability. He deployed it in Heroku and sent me the task of connecting it with our backend, you can make the call from cmd like this:
curl -d "{\"Values\":[[value1,value 2,value 3,value 4,value 5]]}" -H "Content-Type: application/json" -X POST https://apibc1.herokuapp.com/predict
And it will work just like intended, but to be honest I don't know how to make this call in my server file, I'm trying to use the request package in Node but I keep getting the invalid URI error on my logs. An example of the API working from cmd:
And this is what happens when I make the same call in my server.js file:
If you have a working curl you can import it into postman and generate a working code sample for a lot of languages.
Import the curl request
Then click the code button on the right
and select a language/framework option from the dropdown

Get programmingLanguage and topic for Github repo via API

How can I get the repo-language and topic for a Github Repo through the REST API. I looked at the documentation under - https://developer.github.com/v3/ , but could not get an answer.
Just found one way to do the search for topics as follows. Of course it needs a custom media type at moment.
From the documentation:
curl -H "Authentication: token TOKEN" \
-H "Accept: application/vnd.github.mercy-preview+json" \
https://api.github.com/search/repositories?q=topic:ruby+topic:rails
For the language, it is simply the URL like :
https://api.github.com/repos/postgres/pgadmin4/languages

How to show if a camera is online with the nest api

I'm working on a website that contains multiple Nest cameras and I wonder if it is possible to display if a camera is online before a user clicks on the link to view this cam.
I would do it with a XMLRequest in javascript but I cant find how to do it.
You would make a REST call for it, HTTP GET specifically. The request url would look like this:
https://developer-api.nest.com/devices/cameras/<device_id>/is_online?auth=<auth_token>
Using cURL it would look like this:
curl -v -L -H
"Authorization: Bearer <auth_token>"
-X GET "https://developer-api.nest.com/devices/cameras/<device_id>/is_online"
Reference: https://developer.nest.com/documentation/api-reference/overview#cameras

Resources