gitlab ci REST base URL - rest

I tried to update a variable for gitlab ci with
curl --request PUT --header "PRIVATE-TOKEN: $CI_TOKEN" "https://gitlab.com/mathmeier/landesrunde-nrw/api/v4/projects/1/variables/DATABASE_LIST" --form "value=$NEW_DB_LIST"
but my URL is obviously broken. From the description on the gitlab REST api pages, I do not understand how I construct the URL. Furthermore, I do not know what this project number or id should be.
Can anybody enlighten me?

You can get the project id from the main page of the project. Then the call would look something like this:
curl --request PUT --header "PRIVATE-TOKEN: $CI_TOKEN" "https://gitlab.com/api/v4/projects/37804337/variables/DATABASES_LIST" --form-string value=$NEW_DB_LIST

Related

$select parameter not working on Microsoft Graph API share calendar (cURL)

When using the following URL in Microsoft Graph Explorer, I can see a list of my Calendar Event's with only the subject field returned as JSON.
https://graph.microsoft.com/v1.0/me/calendarview?startdatetime=2022-06-17T16:37:48.171Z&enddatetime=2022-06-24T16:37:48.171Z&$select=subject
When doing the same for a resource's Calendar, all the information is returned instead of just the subject field.
curl -H "Authorization: Bearer <BEARER_TOKEN>" "https://graph.microsoft.com/v1.0/users/<CALENDAR_SMTP>/calendarView?startdatetime=2022-06-17T16:37:48.171Z&enddatetime=2022-06-24T16:37:48.171Z&$select=subject"
Am I doing something wrong in cURL or doesn't $select work on other users' calendars?
Any help would be appreciated.
Solved - Skipped the $ in cURL and it worked.
curl -H "Authorization: Bearer <BEARER_TOKEN>" "https://graph.microsoft.com/v1.0/users/<CALENDAR_SMTP>/calendarView?startdatetime=2022-06-17T16:37:48.171Z&enddatetime=2022-06-24T16:37:48.171Z&select=subject"

Jenkins REST API: Create new Job View

I am using the Jenkins REST API to automate our CI process.
The last thing that is missing in the automatization pipeline is the creation of a view if theuser-defined view does not exist.
So far I used:
jenkins_alias/createView?name=My-Test-View
but it is somehow incomplete and returns the error that:
the viewtype should be defined
how can I define this viewtype from the RESTAPI? Should I send it in the Url or in the request body?
thanks
Per this post, this is apparently (a) possible with the REST API and (b) without referencing any weird Hudson stuff.
# create the view
curl -vvv -X POST -d #view.xml -H "Content-Type: text/xml" http://localhost:8080/createView?name=MyView
# get the configuration
curl http://localhost:8080/view/MyView/config.xml
# update the view
curl -X POST -d #view.xml -H "Content-Type: text/xml" http://localhost:8080/view/MyView/config.xml
Caveat emptor - I believe this is undocumented. According to the Jenkins REST API documentation, all the REST API can do is:
retrieve information from Jenkins for programmatic consumption
trigger a new build
create/copy jobs
Please try this request as an example:
curl -X POST -H 'Jenkins-Crumb:<JENKINS-CRUMB>' --form name=test --form mode=hudson.model.ListView --form json='{"name": "test", "mode": "hudson.model.ListView"}' https://<Jenkins-URL>/createView
View types:
ListView: hudson.model.ListView
Dashboard (if plugin Dashboard View is installed): hudson.plugins.view.dashboard.Dashboard
MyView: hudson.model.MyView

How to POST an updated config.xml using Jenkins REST API?

I wanna write a groovy script to bulk update my job configuration using Jenkins REST API. But I am quite confused by its API doc (http://localhost:8080/jenkins/job/my_job_name/api/).
Fetch/Update config.xml
To programmatically obtain config.xml, hit this URL. You can also POST an updated config.xml to the same URL[http://localhost:8080/jenkins/job/my_job_name/config.xml] to programmatically update the configuration of a job.
How am I gonna POST an xml file to an url mentioned above?
The below curl command works for me.
curl --user $USER:$API_TOKEN -X POST http://localhost:8080/job/test/config.xml -H 'Content-Type: application/xml' --data-binary "#mymodifiedlocalconfig.xml"
curl -X POST -H 'Content-Type: application/octet-stream' http://<ip>/job/<job name>/config.xml --user uname:upass --data-binary #./test.xml
Many answers set Content-Type: application/xml, and it didn't work in my Jenkins. I try to set Content-Type: application/octet-stream and it work successfully.
I tried cURL and it worked.
curl -F "file=#updated_config.xml" "http://localhost:8080/jenkins/job/my_job_name/config.xml"
Note: U will need to toggle off "Prevent Cross Site Request Forgery exploits" in Jenkins config.

Uber Rush API Sandbox

Trying to test Uber Rush API (from localhost and from linux server).
Calling Token works - I get the token
trying to implement sanbox example:
curl -X "PUT /v1/sandbox/deliveries/{delivery_id}" \
-H "Authorization: Bearer <OAUTH TOKEN>" \
-d "{\"status\":\"en_route_to_pickup\"}"
with url https://sandbox-api.uber.com/
and I tried the same request with file_get_contents (in PHP)
So, I always get error "405 Method Not Allowed"
{"message":"Method not supported for this endpoint.","code":"method_not_allowed"}
What I need to do to get access to method from this sandbox example https://developer.uber.com/docs/rush/sandbox?
Corrent syntax
curl -X "PUT" -H "Authorization: Bearer <TOKEN>" -H "Content-Type: application/json" -d "{\"status\":\"en_route_to_pickup\"}" https://sandbox-api.uber.com/v1/sandbox/deliveries/DELIVERY_ID
EDIT: Updated to reflect both issues in your question...
You have a mismatch in your requests and an incorrect syntax for curl.
First off your CURL request is incorrectly specified. It should be:
curl -X "PUT" -H "Authorization: Bearer <OAUTH TOKEN>" -d "{\"status\":\"en_route_to_pickup\"}" https://sandbox-api.uber.com/v1/sandbox/deliveries/{delivery_id}
In addition, your curl command is trying to issue a PUT request to the uber sandbox PUT API. However, your PHP code is not setting the context correctly and so is probably issuing a GET request. I suspect that the server is therefore rejecting the request as a GET as not allowed to do this sort of operation.
To fix it, see Bad request using file_get_contents for PUT request in PHP. This should give you an example of how to pass in the necessary context to issue a PUT request using file_get_contents().

Github v3 API - create a REPO

I’m trying to use the Github v3 API - I already implemented the required OAuth flow and it works well.
Now I’m trying some of the Repos API endpoints (http://developer.github.com/v3/repos/).
So far, I’m able to get a List of my repos using: GET /user/repos
However, when I try to create a repo using POST /user/repos, I get a 404.
Any thoughts what I might be doing wrong?
Joubert
Can you please tell us how exactly you did the HTTP request? The 404 sounds like you were using a wrong path, probably. But to give a reliable answer instead a wild guess, we need to see your request, including how you are sending your token, just mask it with 'xxx' or something.
I'll show you in the meantime an example request, that is working:
curl -XPOST -H 'Authorization: token S3CR3T' https://api.github.com/user/repos -d '{"name":"my-new-repo","description":"my new repo description"}'
You would need to replace the OAuth token of course: S3CR3T
I had the same issue. The reason why you are getting a 404 with your oauth access token is that when you authorize to github you need to also additionally pass the scopes you want. For example, in the header you should see "X-OAuth-Scopes: repo, user", which means this user has read/write access to his profile and repositories. Once you have set the correct scopes you should be able to do POST/PUT requests just fine.
To see whether or not you have the correct permissions. You can do something like the following. Substitute the XXXXXXX with your access token.
curl -I https://api.github.com/user?access_token=XXXXXXXX
For creating repositories as a user you can use an personal access token and basic auth, which can be much simpler when you are fluffing around on the command line and have 2FA enabled.
curl -d '{"name":"test"}' -u githubuser:personaccesstoken https://api.github.com/user/repos
Create a personal access token here https://github.com/settings/tokens and make sure it has the 'repo' scope.
This script lets you read in in the token and project name as variables so you can use it in a script
#!/usr/bin/env bash -u
#
TOKEN=`cat token_file`
PROJECT=myproject
curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -d '{"name": "'"$PROJECT"'"}' https://api.github.com/user/repos?access_token=$TOKEN