Invoking IBM Cloud Functions with curl results in ""The supplied authentication is invalid" - ibm-cloud

I created a hello world action, could invoke it in the browser.
Invoking with curl and using the API key provided resulted in an error:
$ curl -u API-KEY -X POST https://us-south.functions.cloud.ibm.com/api/v1/namespaces/jps_LMI/actions/HelloWorld?blocking=true
{"code":"cd01b7ea690a0454ef05016daa917bd3","error":"The supplied authentication is invalid"}
Calling the unprotected request is working fine:
https://us-south.functions.cloud.ibm.com/api/v1/web/jps_LMI/default/HelloWorld.json

Related

Is it possible to run a curl command with a splunk dbxquery?

I am developing a dashboard that connects to Splunk via REST API and displays data on various charts/graphs etc. In order to get the data I have to make a POST request via curl (node.js). Everything is working great. However when I try to make a Post request with a dbxquery, it fails and returns 'fatal dbxquery unknown command.' I was wondering if anyone had encountered this before.
curl -H 'Authorization: Basic auth token' -k https://devfg.com:8089/services/search/jobs -d search=" | dbxquery query=\"SELECT count(*) FROM db.table\" connection=\"connection\"" -d output_mode=json
Are the permissions for the dbxquery command set to be executable from any app? Check under app permissions to see if the command is globally exported.
Alternatively, you may need to escape the *, so \*.
Otherwise, you should be able to run the dbxquery via a curl command.

Twilio Verify API verification call return curl error

I am now trying out the Twilio Verify API and the guides actually showed there are only two calls to the API to send the OTP to the target phone number and check if the OTP entered by end user is correct or not. I have problem with the verify code part, which return the curl error.
The OTP is successfully sent to the target phone.
This is the curl command i used to check the OTP:
curl -GET 'https://api.authy.com/protected/json/phones/verification/check' -d api_key=xxxx -d verification_code=xxxx-d phone_number=xx-d country_code=xx
This is the error message:
curl: (58) could not load PEM client certificate, OpenSSL error error:02001002:system library:fopen:No such file or directory, (no key found, wrong pass phrase, or wrong file format?)
Sorry for not reading the error message properly, I fixed it already by add the SSL cert path and private key path of the server to the curl command and it works.
curl -GET 'https://api.authy.com/protected/json/phones/verification/check' -d api_key=xxxx -d verification_code=xxxx-d phone_number=xx-d country_code=xx --cert path/to/fullchain.pem --key path/to/privkey.pem

IBM Cloud API Docs Tone Analyzer

I tried to implement :
curl -u "apikey:{apikey}" "{url}/{method}"
resorce:https://console.bluemix.net/apidocs/tone-analyzer
My question what I need to do? I already have the api key, for example 1234,
and my url is https://gateway.watsonplatform.net/tone-analyzer/api
First what is the: {method} in the above cURL request and what do I need to do with that?
Question 2 this is correct?:
curl -u "apikey:1234" "https://gateway.watsonplatform.net/tone-analyzer/api/{method}
In the cURL request below:
curl -X GET -u "apikey:{apikey}" "https://gateway.watsonplatform.net/tone-analyzer/api/v3/tone?version=2017-09-21&text=Team,%20I%20know%20that%20times%20are%20tough!%20Product%20sales%20have%20been%20disappointing%20for%20the%20past%20three%20quarters.%20We%20have%20a%20competitive%20product,%20but%20we%20need%20to%20do%20a%20better%20job%20of%20selling%20it!"
The {URL} is https://gateway.watsonplatform.net/tone-analyzer/api and {method} is /v3/tone. To under the endpoint, check this link
You are making a GET method call and for this, you need to create a service at https://console.bluemix.net/catalog/services/tone-analyzer
For more information on how to get an API key, refer to this link

Upload SSH public key to bitbucket cloud using curl/REST and token

I have a bitbucket cloud account. Under: https://id.atlassian.com/manage/api-tokens I have generated an API Token which I am trying to use in a REST call to upload
a public SSH key to my account. Based on:
https://docs.atlassian.com/bitbucket-server/rest/5.6.2/bitbucket-ssh-rest.html?utm_source=%2Fstatic%2Frest%2Fbitbucket-server%2F5.6.2%2Fbitbucket-ssh-rest.html&utm_medium=301#idm45427244388592
https://community.atlassian.com/t5/Answers-Developer-Questions/Bitbucket-REST-API-POST-using-token-instead-of-basic-auth/qaq-p/474823
I have tried:
curl -X POST -d '{"text":"ssh-rsa AAAAB3... me#127.0.0.1"}' -H "Authorization: Bearer ADasdaEeasAsd..." https://bitbucket.org/[my-account]]/rest/ssh/latest/keys
But when I run that I get:
{"type": "error", "error": {"message": "Access token expired. Use your refresh token to obtain a new access token."}}
I have tried to re-create the token and re-run the above command again - with the new token - but I get the same error.
Any suggestions?
Based on below answer and link I have now tried:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer wxdrtblabla..." \
-d '{"key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKqP3Cr632C2dNhhgKVcon4ldUSAeKiku2yP9O9/bDtY myuser#bitbucket.org/myuser"}' \
https://api.bitbucket.org/2.0/users/myuser/ssh-keys
But I get the exact same error:
{"type": "error", "error": {"message": "Access token expired. Use your refresh token to obtain a new access token."}}
So still no luck. Also if I access:
https://api.bitbucket.org/2.0/users/[myuser]/ssh-keys
directly in a browser I get:
type "error"
error
message "This API is only accessible with the following authentication types: session, password, apppassword"
EDIT/ANSWERED: Based on the updated answer below I have no tried to create an app password and grant it account: read/write in bitbucket and it works. I run it with:
curl -v -u myuser:my-generated-app-password -X POST \
-H "Content-Type: application/json" \
-d '{"key": "ssh-rsa AAA....ro"}' \
https://api.bitbucket.org/2.0/users/myuser/ssh-keys
You're looking at Bitbucket Server documentation but using Bitbucket Cloud. (The giveaways: the "bitbucket-server" part of the doc path, and the "bitbucket.org" in the path where you're pushing your key.)
Check out https://developer.atlassian.com/bitbucket/api/2/reference/resource/users/%7Busername%7D/ssh-keys#post instead - that's the Bitbucket Cloud documentation to do what you're trying to do. Your URL will be more like https://api.bitbucket.org/2.0/users/[your-account]/ssh-keys.
EDIT: The error you received indicates the problem: you either need to make that call from within an existing session (i.e. from the GUI), use your password, or use an app password. I'd recommend the app password, since it's scoped, meant to be disposable, and won't let you log onto the GUI. Your curl call then becomes something like curl -u myuser:myapppassword -X POST -H "Content-Type: application/json" -d '{"key": "key content goes here"}' https://api.bitbucket.org/2.0/users/myuser/ssh-keys.

How to create a github.com repository over HTTP API?

According to the general instruction to the github.com API and the explanation of the create command
curl -u "krichter722" https://api.github.com # works (returns JSON response)
curl -d '{"name":"test"}' https://api.github.com/user/repos/
should work and create a repository, but the second command fails with
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3"
}
I found Using `curl` to create a repo on GitHub.com with two-factor authentication which resolves an issue caused by missing parts in the request for two-factor authentication.
Other questions, like "Bad Credentials" when attempting to create a GitHub repo through the CLI using curl, indicate that the URL is correct (the creation fails due to bad credentials according to error message in this case).
You can do it as follows:-
curl -u "$username:$token" https://api.github.com/user/repos -d '{"name":"'$repo_name'"}'
You can find personal access token in Github Settings -> Application, replace username with your username and repo_name with repository name.
Note:- You might need to create personal access token if you haven't used it earlier.