Adding comment to the pull request throws "Message: Not Found" error - github-api-v3

I am trying to add commit to the pull request using GitHub API for issues. But seeing error
curl -H "Authorization: token "Key"" -X POST -d '{"body": "Failed"}' "https://github-site/repos/:repository/issues/PR_NUMBER/comments"
Response for the curl command.
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/enterprise/2.15/v3/issues/comments/#create-a-comment"
}

Ah I found my mistake. I was passing basic authorizing keys. To Post the comment or to create a Label we need OAUTH token generated on github.
https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/

Related

Get an access token

I tried to get an access token with the google documentation.
curl -L -X POST 'https://www.googleapis.com/oauth2/v4/token?
client_id=oauth2-client-id& client_secret=oauth2-client-secret&
code=authorization-code& grant_type=authorization_code&
redirect_uri=https://www.google.com'
With this request it didn't worked.
I added -H 'Content-Length: 0' and now I'm ending up with
{
"error": "invalid_grant",
"error_description": "Bad Request"
}
Anybody have an idea?
If fixing the space didn't work, re-do you linking here from the Google guide, steps 1-6. Then get a new authorization code. I had the same issue and re-linking worked for me (with the -H flag).
it seems you have a space in the request:
/v4/token? client_id=oauth2-client-id
when i tried to copy past the commands from the documentation it didn't work.
i had to re-edit the request before i could use it and it worked.
I've got the same issue.
curl -L -X POST "https://www.googleapis.com/oauth2/v4/token?client_id=<client_id>.apps.googleusercontent.com&client_secret=<secret>&code=4/4wGANiKF5......N0Jg&grant_type=authorization_code&redirect_uri=https://www.google.com"
Stumped
Don't you have to use a different redirect_uri? Your own configured redirect uri?

Error 500 when retrieving Clockify workspaces

When retrieving workspaces using the GET /workspaces/ API endpoint, I’m getting the following error 500:
{
"timestamp": "2018-10-18T05:48:29.740+0000",
"status": 500,
"error": "Internal Server Error",
"exception": "java.lang.RuntimeException",
"message": "java.lang.NullPointerException",
"path": "/workspaces/"
}
This is the request I'm sending:
curl -XGET -H 'X-Api-Key: <snip>' https://api.clockify.me/api/workspaces/
I hope this is trivial to resolve.
Your example works when using the API key generated on the settings page, i.e.:
curl -XGET -H 'X-Api-Key: WchCprB5h15WpmvB' https://api.clockify.me/api/workspaces/
(of course that is not a valid key, but I've posted it so you see the format).
Make sure you're not adding any additional formatting or using the wrong key. If you're using a JWT token you need 'X-Auth-Token' header instead.

Artifactory access token works via Bearer, not user

Artifactory OSS
5.4.6 rev 50406900
Trying to get access token to work.
I created token...
e.g. curl -uadmin:adminpw -X POST "myserver:8081/artifactory/api/security/token" -d "username=moehoward"
Returned msg looks like success...
{
"scope" : "member-of-groups:readers api:*",
"access_token" : <very-long-string>
"expires_in" : 3600,
"token_type" : "Bearer"
}
I can see it in the gui (admin -> Security -> Access Tokens) with "Subject" = to the user ("moehoward" in the example above) and with a "Token ID" that's a lot shorter, something like...
f2eb693a-d4ff-4618-ba52-764dc975c497
To test, I tried to ping using example in the docs...
curl -umoehoward:<very-long-string> myserver:8081/artifactory/api/system/ping
Fails with a 401 (bad credentials).
I replace the token with the "token id" I see in the gui, same result.
I replace again with the hardcoded pw of the "moehoward" user and that works (responds with "OK").
I tried the "-H"Authentication: Bearer " approach using the long string and that worked. So I guess the very long string is the token and not the "Token ID" in the gui.
Q: Any idea why this works for Bearer" and not the user by name ?
So you are right that this is supposed to work for both standard authentication and the Authentication HTTP header.
I did the test on a server with the same version Artifactory OSS 5.4.6 and the following works fine here
Inject the proper variables
export SERVER=server-artifactory
export APIKEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Create and use an access token for user moehoward
curl -u "admin:$APIKEY" -X POST "http://$SERVER/artifactory/api/security/token" -d "username=moehoward" -d "scope=member-of-groups:readers" > token.log
export TOKEN=`cat token.log | jq -r '.access_token'`
curl -u "moehoward:$TOKEN" "http://$SERVER/artifactory/api/system/ping"
curl -H "Authorization: Bearer $TOKEN" "http://$SERVER/artifactory/api/system/ping"
I get "OK" from the last two commands. Can you run exactly these commands and report back?
I have personally experienced the same problem (Bearer header working, standard user credentials not working) with an old version of curl. The obvious workaround is to use Bearer, the more complex workaround is to upgrade curl (or use another tool).
What is the version of curl you use? Any curl from 2015 or more recent should work fine.

httr POST authentication error

I am trying to structure a POST json request using httr. The API documentation proposes the following the CURL request:
curl -X POST -H "Authorization:Token XXXXXXXXX" -H "Content-Type: application/json" --data "{\"texts\":[\"A simple string\"]}" https://api.uclassify.com/v1/uclassify/topics/classify
My R httr implementation is the following:
POST("https://api.uclassify.com/v1/uClassify/Topics/classify",
encode="json",
add_headers('Authorization:Token'="XXXXXXXXX"),
body=("A simple string"))
But I received a 401 error message which indicates that my authentication failed. Any suggestion on how I can implement the CURL request on httr?
Just in case it can help somebody else, the below code works for me:
POST("https://api.uclassify.com/v1/uClassify/Topics/classify",
encode="json",
add_headers(Authorization = "Token XXXXXXXXX"),
body = "{\"texts\":[\"A simple string\"]}")

Microsoft cognitive API token doesn't work

I'm trying to use the Microsoft cognitive API for text analysis using the recommended curl method from their documentation:
curl -v -X POST "https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment" -H "Content-Type: application/jscp-Apim-Subscription-Key: {bc94cba9b84748ebb2f2b79a28ee3450}" --data-ascii "{I had a wonderful experience! The rooms were wonderful and the staff were helpful.}"
But I get back:
{ "statusCode": 401, "message": "Access denied due to invalid subscription key. Make sure to provide a valid key for an active subscription." }
I also tried removing the {} surrounding token and text to be analyzed. What am I doing wrong here?
Note: yes I realize the security issue with showing key but I have re-generated thanks.
There are three issues with your request:
Content-Type header should be application/json. This is likely a copy-paste error.
Ocp-Apim-Subscription-Key header value must be the API without the curly braces. This is the cause for your 401 error.
The body must be JSON of a particular format. You can find the schema here.
Here's the rewritten request:
curl -v "https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: $OXFORD_TEXT_KEY" --data-ascii '{"documents":[{"language":"en","id":"1234","text":"I had a wonderful experience! The rooms were wonderful and the staff were helpful."}]}'
Which should result in:
{"documents":[{"score":0.9750894,"id":"1234"}],"errors":[]}

Resources