Postman works, but the "Code snippet" generated no. cURL - rest

From my computer the query via postman to my endpoint works, it returns the expected result.
but the code generated by "code snippet" does not work, what could be the cause ?
--That code doesnt work. But in postman yes (same laptop)
curl --location --request POST 'https://service' \
--header 'Ocp-Apim-Subscription-Key: myKey' \
--header 'Content-Type: audio/mpeg' \
--data-binary '#/path/audio_test.mp3'
Error: curl: (28) Failed to connect to <service> port 443: Timed out
To check that it is not a problem with my end, I tried another service that works in postman and the code generated by postman through "code snippet" works as well.
-- That works in postman and in my consol --
curl --location --request POST 'https://´service' \
--header 'Key: myKey' \
--header 'Content-Type: application/json' \
--data-raw '{"text":"myText",
"language": "en"
}
'
its return the expected result
Does anyone have any idea where I could look? Thanks

curl: (28) Failed to connect to port 443: Timed out
This will likely be a connection error either due to the client context (application/terminal) or the client host (the device itself). I assume the second request doesn't try to hit the same location or it was ran from another context.
Check your connection first and then troubleshoot from your way up. To do so, in the same exact place you're running your curl run the following:
telnet service 443
Where service is the endpoint you are using in the request. If that still gives the same error then the issue is down to a networking problem. Check from other clients, check VPNs or other applications that could be causing the blockage.

Related

WSO2-AM 3.2.0 - Make sure your API invocation call has a header: testkey is missing

I've published an API in WSO2 AM and now, when I try to test the API by curl, passing the token, it shows an error:
curl request:
curl -X GET "https://192.168.21.120:8243/ms-authorization/1.0.0/authorization/access-type/access-type"
-H "accept: application/json" -H "Authorization: Bearer eyJ4NXQiOiJNell4TW1Ga09HWXdNV0kwWldObU5Er0m9eU..
-iNxXl0D9to5ptemrd42itirPDJiYJJ_FkSMKSfQ6m78X2fr-Tag" -k
response:
{"fault":{"code":900902,"message":"Missing Credentials","description":"Authentication Error. Make sure your API invocation call has a header: testkey is missing"}}
Why is expecting a "testkey" in header?
If you are trying to test the API using the Publisher Test Console, you need to include the generated access token/test key in your curl with the header testkey.
eg:
curl -X GET "https://localhost:8243/napi/1.0/*" -H "accept: */*" -H "testkey: 032456ff-4764-4321-2348-e7ad1ac5t6g0" -k
I just enabled CORS configuration, redeployed the API and everything worked:

How can I connect to MSTR library via CURL to get the session state?

I am trying to connect to MicroStrategy REST API via curl in order to obtain the session state.
I have tried a PHP code using this example https://community.microstrategy.com/s/article/Library-REST-API-Login-PHP?language=en_US.
I get the following error:
{"code":"ERR009","message":"The user's session has expired, please reauthenticate","ticketId":"d2a5595614634adba2bb07e5b15bedc9"}
I've also tried to call the API directly from curl on Windows command line.
curl -X POST "http://localhost:8080/MicroStrategyLibrary/api/auth/login"
-H "accept: application/json" -H "Content-Type: application/json"
-d "{\"username\":\"Administrator\",\"password\":\"myPassword\",
\"loginMode\":1,\"maxSearch\":3,\"workingSet\":10,\"changePassword\":false,
\"newPassword\":\"string\",\"metadataLocale\":\"en_us\",
\"warehouseDataLocale\":\"en_us\",\"displayLocale\":\"en_us\",
\"messagesLocale\":\"en_us\",\"numberLocale\":\"en_us\",\"timeZone\":\"UTC\",
\"applicationType\":35}"
I do not get any response for this call.
What is the reason for this error?

PCF p-config-server /decrypt api returning 403 forbidden error

While trying to use encryption/decryption feature of spring cloud config server with Pivotal Cloud Foundry's p-config-server service which is configured with a symmetric key for encryption, I am getting a 403 forbidden response which calling /decrypt on config server .
I am able to call the /encrypt endpoint successfully for encrypting values using below sample curl -
curl --location --request POST 'https://config-xxxx.apps.xxx.com/encrypt' \
--header 'Authorization: bearer <cf oauth_token here>' \
--header 'Content-Type: text/plain' \
--data-raw 'sample data'
But when trying to decrypt those values using /decrypt, I am getting 403 Forbidden error -
{
"error": "access_denied",
"error_description": "invalid issuer"
}
Sample curl for decryption -
curl --location --request POST 'https://config-xxxx.apps.xxx.com/decrypt' \
--header 'Authorization: bearer <cf oauth_token here>' \
--header 'Content-Type: text/plain' \
--data-raw '<encrypted value from previous step>'
In pivotal's config server documentation though there are reference to /encrypt but nothing related to /decrypt pivotal config server
Any pointers ?
In the Pivotal/Tanzu Spring Cloud Services (commercial product), the /encrypt API is exposed to anyone with the admin scope or to anyone that is a Space Developer in the space of the service.
The /decrypt endpoint is not exposed specifically, so you're not allowed to access with the same credentials, hence why you're seeing a 403.
My quick read of the code is that you'd need a token with scope config_server_<guide>.read to access that endpoint. Where <guid> is the config server's service guide (run cf service --guid <name> to obtain the guide).
To make that work, you'd need to get a token from the bound service or a service key, the latter is easier:
Run cf create-service-key <service_instance> decrypt-key
Run cf service-key <service_instance> decrypt-key
Run export TOKEN=$(curl -vv <access_token_uri> -d 'grant_type=client_credentials' -d 'client_id=<client_id>' -d 'client_secret=<client_secret>' | jq -r .access_token) where the values in <...> are from the output of #2.
Run curl -vv '<uri>/decrypt' -H "Authorization: bearer $TOKEN" -H 'Content-type: text/plain' -d '<encrypted-value>'
These depend on a Bash shell. You can do them on Windows, but the commands will vary. It also uses jq to make extracting the token easier. You could split the command in step #3 into two steps, fetching with curl and manually exporting TOKEN.

Thinksboard - Authentication in API rest call failing

I have to use thingsboard by rest API as it is showed on the guide https://thingsboard.io/docs/reference/rest-api/
In particular, I have a live-demo server and a custom user with administration permission.
I can authenticate it with the username/password on the thingsboard interface
Unfortunately, when I try the following command
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"username":, "password":}' 'https://THINGSBOARD_URL/api/auth/login'
I receive the following output:
{"status":401,"message":"Authentication failed","errorCode":10,"timestamp":"..."}
Anybody can help me?
I will glad,
Gianluca
Solved
It was certifciate problem,
I bypass it by the following command:
tokenAuthResp = requests.post(url, headers=headers, json=loginJSON, verify=False).json()

ERROR 401 on creation of External (Internal) Master Instance on GCP Cloud SQL

I started the creation of a MySQL 1st Gen read replica with Google Cloud SQL. However after 5 hours of waiting I have given up. Now I can't delete the instance and on trying to delete using the cloud terminal just get
I gave up and deleted the project...
Meanwhile back to the first part of the script -
ACCESS_TOKEN="$(gcloud auth application-default print-access-token)"
curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
--header 'Content-Type: application/json' \
--data '{"name": "food22",
"region": "us-central1",
"databaseVersion": "MYSQL_5_5",
"onPremisesConfiguration": {"hostPort": "xxx.xxx.xxx.xxx:3306"}}' -X POST
\
https://www.googleapis.com/sql/v1beta4/projects/[Project ID]/instances
Orange Warning Symbol
I have a nasty feeling that Google have abandoned this on premise link after I saw this - https://serverfault.com/questions/835108/gcp-configure-an-external-master-issue/835266 and looked at Answer Two.....
Come on Google - get your act together!