How to Star a Topic on GitHub with API? - github

Star a topic can be done on the website. But how to do the same operation via GitHub API v3 or v4? I read through the reference but got no clues.

For the v3 REST API it's documented at Star a repository for the authenticated user
The curl example is:
curl \
-X PUT \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/user/starred/octocat/hello-world
But this doesn't show how to insert your token, so you actually need something more like:
curl \
-X PUT \
-H "Authorization: token $GITHUB_API_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/user/starred/octocat/hello-world
Where GITHUB_API_TOKEN has been previously set like:
GITHUB_API_TOKEN="ghp_16C7e42F292c6912E7710c838347Ae178B4a"
Per comments to this earlier question how to star a repo with github api make sure that the token used has the correct permissions to do the starring, which means having the repo scope (or at least repo_public) enabled.
I'd also love to know how to do this with the v4 GraphQl API.

Related

gh cli api returns 404 but auth and token scopes are OK

I have the latest gh CLI app. I set a GH_TOKEN. It seems to be working, because this works:
gh api --method GET -H "Accept: application/vnd.github.v3+json" "orgs/MyOrg/repos"
...it returns a few repos.
But this call returns a 404:
gh api --method GET -H "Accept: application/vnd.github.v3+json" "repos/MyOrg/MyRepo/actions/runners"
even though my (classic) token has full repo scope as well as read:org and manage_runners:org.
What I'm really trying to do is create a self-hosted runner, and this doesn't work either:
gh api --method POST -H "Accept: application/vnd.github.v3+json" "/repos/MyOrg/MyRepo/actions/runners/registration-token"
that also returns a 404. Any hints?

hey i want to get the teams of the particular repo in github so im using the github api's GET

link for the docs is here and the curl command is:
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/teams
I've given personal access token as my Authorization but it throws as not found.
Any suggestions on how to get it? My repo was assigned to 3 teams even tho it throws not found
i'm the owner of the org and trued to hit with my PAC even tho its giving me the same 404 statusCode.
for example :
this is the link for getting the contributors but for teams i've this but it is giving me 404

How to get raw github data using github API

I want to know how to get this data from the GitHub API.
I know I can get this data as raw but is there any way to get this using GitHub API?
Here is the requested file:
https://github.com/graphql-compose/graphql-compose-examples/blob/master/examples/northwind/data/csv/employees.csv
As seen here, try
curl -GLOf -H "Authorization: token ${GITHUB_TOKEN?not set}" \
-H "Accept: application/vnd.github.v4.raw" \
"https://api.github.com/repos/$ORG/$REPO/contents/$FILEPATH" -d ref="$REVISION"
In your case, for a public repository:
curl -GLOf -H "Accept: application/vnd.github.v4.raw" \
"https://api.github.com/repos/graphql-compose/graphql-compose-examples/contents/examples/northwind/data/csv/employees.csv"
I just tested it, and got a file employees.csv with its raw content in it.

How to set user attribute value in Keycloak using API?

How I can set user attribute value using Keycloak Rest API?
Update: The /auth path was removed starting with Keycloak 17 Quarkus distribution. So you might need to remove the /auth from the endpoint calls presented on this answer.
To set a user attribute using the Keycloak Admin REST API; you use the endpoint:
PUT <KEYCLOAK_HOST>/auth/admin/realms/<YOUR_REALM>/users/<USER_ID>
with the payload
{"attributes":{"<ATTRIBUTE_NAME>":["<ATTRIBUTE_VALUE>"]}}
the <USER_ID> you can get it using the endpoint:
GET <YOUR_KEYCLOAK_DOMAIN>/auth/admin/realms/<YOUR_REALM>/users/?username=<THE_USERNAME>
from the JSON response, extract the field id.
Step-by-Step:
You can get that information using the Keycloak Admin REST API; to call that API, you need an access token from a user with the proper permissions. For now, I will be using the admin user from the master realm:
curl https://${KEYCLOAK_HOST}/auth/realms/master/protocol/openid-connect/token \
-d "client_id=admin-cli" \
-d "username=$ADMIN_NAME" \
-d "password=$ADMIN_PASSWORD" \
-d "grant_type=password"
You will get a JSON response with the admin's token. Extract the value of property access_token from that response. Let us save it in the variable $ACCESS_TOKEN for later reference.
To get the user id from your realm $REALM_NAME:
curl -X GET https://${KEYCLOAK_HOST}/auth/admin/realms/${REALM_NAME}/users/?username=${USERNAME}&exact=true \
-H "Content-Type: application/json" \
-H "Authorization: bearer $ACCESS_TOKEN"
From the response extract the user id for example as follows
jq -r .[].id
Or even cleaner is to passed to the
To set the user attribute:
curl -X PUT https://${KEYCLOAK_HOST}/auth/admin/realms/${REALM_NAME}/users/${USER_ID} \
-H "Content-Type: application/json" \
-H "Authorization: bearer $ACCESS_TOKEN" \
-d '{"attributes":{"<ATTRIBUTE_NAME>":["<ATTRIBUTE_VALUE>"]}}'
You can also have a look at setUser script on my GitHub repo.

Undocumented Wunderlist update user endpoint

There appears to be an endpoint on the Wunderlist API for updating the wunderlist user (at https://a.wunderlist.com/api/v1/user) which does not appear in the official docs
User information can be updated by sending a PUT request to it, e.g. :
curl \
-H "X-Access-Token: $WL_ACCESS_TOKEN" \
-H "X-Client-ID: $WL_CLIENT_ID" \
-H "Content-Type: application/json" \
-XPUT -d '{"revision":1234,"name":"some-name"}' \
https://a.wunderlist.com/api/v1/user
Assuming the data is valid, this returns with HTTP 200.
Is this endpoint supported?