I'm trying to curl a URL using GET which requires authorisation but no matter how I pass the token, I'm getting this returned:
{
"response": {
"error": "Authentication required",
"error_code": 1
}
}
I've asked the developer of the API I'm using but all I've been told is "The token must be included in the X-Authorization HTTP header" which doesn't tell me what I'm doing wrong.
Here's an example of one of the commands I've tried:
curl -X GET -H 'Content-Type: application/json' -H "Authorization: Bearer MyTokenGoesHere" -k https://example.com/SomeFolder/endofAPIURL?ArgumentOne=foo&ArgumentTwo=bar
I've tried multiple ways to pass the token but I'm clearly doing something wrong because none of them seem to be even passing the token as I'm getting "Authentication required" instead of incorrect/invalid.
Here are all the ways I've tried passing the token:
-H "Authorization: MyTokenGoesHere"
-H "Authorization: Basic MyTokenGoesHere"
-H "Authorization: Bearer MyTokenGoesHere"
-H "Authorization: Oauth MyTokenGoesHere"
-H "X-Auth-Token: MyTokenGoesHere"
-H "X-Auth-Token: Basic MyTokenGoesHere"
-H "X-Auth-Token: Bearer MyTokenGoesHere"
-H "X-Auth-Token: Oauth MyTokenGoesHere"
All of these different ways of passing the token have been taken from various posts on this site.
I feel I'm missing something obvious but I just can't see it.
So it turns out that the API was using a custom header but didn't have it documented anywhere. The documentation provided also used X-Auth-Token (which I believe is custom in itself but could be mistake) which is why I was trying that.
In my particular case, what I needed was -H "AuthTo: MyTokenGoesHere"
Related
I am using Jira cloud and trying to import the Xunit json report (result.json) generated by cucumber to Jira with Xray using Jira rest API, I've tried various ways to import the reports from command line but so far no luck.
Ex:
curl -H "Content-Type: application/json" -X POST -u ID:token -F "file=D:\Report.json" "https://raheel.atlassian.net/api/v2/import/execution"
curl -H "Content-Type: application/json" -X POST -u user:token --data #"D:\Report.json" "https://raheel.atlassian.net/rest/api/3/issue/DEM-9"
curl -H "Content-Type: application/json" -X POST -u user:token --data #"D:\Report.json" "https://raheel.atlassian.net/rest/raven/2.0/api/Test Execution/DEM-12"
**Error:**
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><status><status-code>404</status-code><message>null for uri: https://raheel.atlassian.net/rest/raven/2.0/api/Test%20Execution/DEM-12</message></status>
token=$(curl -H "Content-Type: application/json" -X POST --data #"{ "client_id": "ID","client_secret": "secret" }" https://xray.cloud.xpand-it.com/api/v2/authenticate| tr -d '"') curl -H "Content-Type: application/json" -X POST -H "Authorization: Bearer $token" --data #"D:\Report.json" https://xray.cloud.xpand-it.com/api/v2/import/execution/cucumber
First of all, it seems that you are using Xray Cloud (i.e. Xray for Jira Cloud).
The proper documentation for Xray Cloud's REST API can be found here.
First, you need to create an API key (pair of client id and client secret) on Xray settings.
Then you need to authenticate in order to obtain a token that you'll need to provide in all following requests.
The following example, shows a way of setting a shell variable with the token value, so it can be used in subsequent requests
token=$(curl -H "Content-Type: application/json" -X POST --data #"cloud_auth.json" https://xray.cloud.xpand-it.com/api/v2/authenticate| tr -d '"')
Then you can invoke the REST API endpoint to submit the Cucumber JSON report.
curl -H "Content-Type: application/json" -X POST -H "Authorization: Bearer $token" --data #"Report.json" https://xray.cloud.xpand-it.com/api/v2/import/execution/cucumber
Please note that in order to import Cucumber related results using a cucumber JSON report, your Scenarios need to be properly tagged. You need to follow one of the flows detailed here.
There is POST here which is calling a rest API to fetch the data.
Below is Just the Short code using rest API Call to fetch the data using /rest/resource-alerts, but it only displays max 500 Critical alerts not all. Below is the Code I'm using:
sessionID=$(curl -k -H "accept: application/json" -H "content-type: application/json" -H "x-api-version: 120" -d '{"userName":"administrator","password":"123456"}' -X POST https://synergy.ksg.com/rest/login-sessions | jq -r ".sessionID")
# cUrl command with header and payload information to ftech the Data using API call
CMD=$(curl -k -H 'accept: application/json' \
-H 'content-type: text/csv' \
-H 'x-api-version: 2' \
-H "auth: $sessionID" \
-X
GET https://synergy.ksg.com/rest/resource-alerts)
echo "$CMD"
However, while today going via API DOC I see the Query Parameters , The section says about the count, does anyone know how to get the full list of messages?
Below is the
Trying to add an org team to a repo but am unable to with the following:
curl -H "Authorization: token tokenID" -H "Content-Length: 0" -X put \
> -d "" https://url/api/v3/teams/23/repos/johndoe/repo-name
https://developer.github.com/v3/teams/#add-or-update-team-repository
Fro the documentation and this blog post, you must provide a custom media type in the Accept header:
application/vnd.github.hellcat-preview+json
With curl:
curl -H "Content-Type: application/vnd.github.hellcat-preview+json"...
My Url is Like:
https://<ip:port>/TestRESTServices/objects/test-folder
JSON data that I want to pass is:
{
"name":"test-1",
"parent-uuid":"126"
}
test-1 is the folder name which i want to create.
When i invoke this url with the data in Poster plugin in firefox via POST it works fine and folder test-1 is created.
//using Content Type : "application/json"
How can I invoke/call this REST API using cURL ?
Need Help.
This is what i tried:
curl -i -H "Accept: application/json" -X POST -d '{"name":"test-1","parent-uuid":"126"}' https://<ip:port>/TestRESTServices/objects/test-folder
It throws an error that curl: (52) Empty reply from server
Unfortunately I don't have a REST API online to try it, but resources that I found suggest the following approaches:
curl -v -H "Content-Type: application/json" -X POST --data "#issue.json" -u login:password http://redmine/issues.json
where the issues.json is a file containing the JSON request.
Resources I found useful:
1, 2
Hope it helps!
For Authentication : Give the userid/password as admin:password
TOKEN=$(curl -s -k -X POST --basic -u "admin:password" "{host}/TestAuthServices/auth/tokens" | sed -rn 's/\{"Token":"([^"]+)".+/\1/p')
After getting this token call curl as:
curl -s -k -X POST -H "Content-Type: application/json" -H "Authorization: X-SAML ${TOKEN}" -d '{"name":"test","parent-uuid":"126"}' "{host}/TestRESTServices/objects/test-folder"
After fighting for quite some time for posting a private gist to Github using their API V3 I almost gave up. Almost. May be some one have also faced similar problem or know what might be the reasoning of the following behavior:
Right now the curl command looks like following:
curl -H "Authorization: bearer MY_AUTHORIZATION_TOKE" -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"public":false,"files":{"test.txt":{"content":"String file contents"}}}' https://api.github.com/gists
I also tried
curl -H "Authorization: bearer MY_AUTHORIZATION_TOKE" -X POST -d '{"public":false,"files":{"test.txt":{"content":"String file contents"}}}' https://api.github.com/gists
I am able to create gist without authorization token using exactly same data:
curl -X POST -d '{"public":true,"files":{"test.txt":{"content":"String file contents"}}}' https://api.github.com/gists
But in that case it will be anonymous
Same results if I am truing to post it as public
In any case Github returns me
HTTP/1.1 404 Not Found
{
"message": "Not Found"
}
I am pretty sure I am authorized, as curl -H "Authorization: bearer MY_AUTHORIZATION_TOKE" https://api.github.com/user returns me my user details.
Application scope is as:
https://github.com/login/oauth/authorize?client_id=...&scope=gist
So, it should have both read and write permission.
Your OAuth2 token doesn't appear to have the required gist scope.
If you run the curl commands with the -v argument you can see the scope sent to request (X-OAuth-Scopes header) and the scope required for the request (X-Accepted-OAuth-Scopes header) to successfully be performed using the token sent.
If you don't see gist listed in the X-OAuth-Scopes header value then that is your problem.