curl -h or curl --header not working - api

i'm trying to connect ti a web api service, box-api, and following the tutorial i have to type this command to fetch a folder in the user content:
curl https://api.box.com/2.0/folders/FOLDER_ID/items?limit=2&offset=0 -H "Authorization: Bearer ACCESS_TOKEN"
I tryied to connect from the command line to test the command but it keep complaining about the -H or the --header command saying that it doesn exist:
-bash: -H: command not found
-bash: --header: command not found
but when i type curl --help the command is in the manual:
-H, --header LINE Custom header to pass to server (H)
I'm confused, what should i do to connect to this site and get the JSON content? Thanks

Your url has & sign. and this is making end of command on there(and running at background). You can remove this error by using quotes around. Like this
curl "https://api.box.com/2.0/folders/FOLDER_ID/items?limit=2&offset=0" -H "Authorization: Bearer ACCESS_TOKEN"
Hope this helps.

There seem to be two problems:
The '&' in the middle of the URL passed to curl,
The order of the statements. The curl manual reports a different order for the statements. Example:
curl -H "Authorization: Bearer AUTH_KEY" "https://api.box.com/2.0/folders/0/items?limit=2&offset=0"
This should be the complete solution.

Related

Can I get a working curl command to remove a system from RHEL subscription?

I want to automate the addition and removal of VMs from the RHEL Subscription. I want to use a curl command if possible and keep it simple.
I tried executing curl commands on the api.access.redhat.com/management/v1/subscriptions endpoints but it is giving errors like "Authentication parameters missing".
Below is an example command I am using:
curl -X GET -s -k -u username:Password "https://api.access.redhat.com/management/v1/subscriptions" -H "accept: application/json"
Expected to see the list of Subscribed systems but getting the "Authentication parameters missing" message.
In order to get all the subscriptions you have, run the following command:
curl -H "Authorization: Bearer $access_token" "https://api.access.redhat.com/management/v1/subscriptions"
You can retrieve the access_token variable by running the following command:
curl https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token -d grant_type=refresh_token -d client_id=rhsm-api -d refresh_token=$offline_token
The offline_token, instead, has to be generated from the API Tokens Page.
Check this article for further details.

Curl command no return

Im working with an api, in the documentaion found here:
http://api.simplicate.nl/
There is an example curl:
`curl -H “Authentication-Key: {API Key}” -H “Authentication-Secret:{API secret}” https://{subdomain}.simplicate.nl/api/v2/crm/organization.json`
I ran that code like this in terminal:
curl -H “Authentication-Key:XX” -H “Authentication-Secret:XX” https://mydomain.simplicate.nl/api/v2/crm/organization.json
It runs but returns nothing.
You are using Header inside “...” that is wrong. You have to use double quote "..." (not sure what it is called, standard double quote?).
So it should be:
curl -H "Authentication-Key:XX" -H "Authentication-Secret:XX" https://mydomain.simplicate.nl/api/v2/crm/organization.json
As a note, currently your curl is sending the headers as following with extra characters.
“Authentication-Key:XX”
“Authentication-Secret:XX”
But it should be:
Authentication-Key:XX
Authentication-Secret:XX

Unable to call Azure Management Events REST API

I am trying to use the rest api found here: https://msdn.microsoft.com/en-us/library/azure/dn931934.aspx to get the azure events from my subscription. I have followed the instructions very carefully, but my GET requests return a 400 error:
{"Code":"BadRequest","Message":"The $filter query parameter value is invalid."}
My cURL request can be seen below. I've redacted any private info
curl -X GET -H "Authorization: bearer XXX" -H "content-type: application/json" "https://management.azure.com/subscriptions/YYY/providers/microsoft.insights/eventtypes/management/values?api-version=2014-04-01&$filter=eventTimestamp%20ge%20%272016-07-25T22:00:37Z%27%20and%20eventTimestamp%20le%20%272016-07-25T23:36:37Z%27%20and%20eventChannels%20eq%20%27Admin,%20Operation%27"
I have tried many variations of the filter param, but I think this should be correct. Each space was replaced with a %20, and each ' was replaced with a %27.
If anyone can please inform me as to what the correct query should look like i'd really appreciate it!
Thanks!
Please try to change the double quotes over the url to the single quotes. And it works fine on my side after modification.
E.G.,
curl -X GET -H 'Authorization: bearer <token>' -H 'content-type: application/json' 'https://management.azure.com/subscriptions/XXX/providers/microsoft.insights/eventtypes/management/values?api-version=2014-04-01&$filter=eventTimestamp%20ge%20%272016-07-25T22:00:37Z%27%20and%20eventTimestamp%20le%20%272016-07-25T23:36:37Z%27%20and%20eventChannels%20eq%20%27Admin,%20Operation%27'

How to perform Basic Authorization using CURL and get a json/string response in terminal?

curl -X POST -u myusername:mypassword \
-H "Authorization: Basic YXBpdXNlcjphcGlwd2Q=" \
http://someapi.com/v1/auth/login
//Ignore slashes.
I'm using this command in terminal but not getting the desired result.
Desired result should be a json, I think something is wrong with my paramenters.

Box.com update/delete folder using curl

I am trying to update the folder name in box.com using curl tool in windows command prompt. However, I am not able to do that and getting the "insufficient permissions" error. Following is the exact curl command I am using with the request parameters for updating the folder:
curl -i https://api.box.com/2.0/folders/0 -H "Authorization: Bearer rn4lh6kST6bhmaLEuZdjMtxXpTfORg1B" -d "{\"name\":\"New Folder Name!\"}'-X PUT
And I am getting the following error:
{"type":"error","status":403,"code":"access_denied_insufficient_permissions","help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Access denied - insufficient permission","request_id":"11155318795551a7373138a"}
I get the same error for "DELETE" the folder command in curl.
Can anyone please help me with this?
I believe your issue is with the quote escaping. Also, you have -d "....' (note the mismatched " and '
Try the following commands that are from Box API: (Don't forget to add your folder ID & Access Token)
Update Folders
curl https://api.box.com/2.0/folders/FOLDER_ID
-H "Authorization: Bearer ACCESS_TOKEN" -d '{"name":"New Folder Name!"}' -X PUT
Delete Folders
curl https://api.box.com/2.0/folders/FOLDER_ID?recursive=true
-H "Authorization: Bearer ACCESS_TOKEN" -X DELETE