PeterK
PeterK

Reputation: 4301

Always Free Oracle Autonomous Database Soda not find database

I am testing the Oracle Autonomous Database json soda using this tutorial:

Use SODA for REST with Autonomous Database

All works well until I test the OAuth @ "Use SODA for REST with OAuth Client Credentials" chapter. Then I get the following result:

curl -i -H "Authorization: Bearer zSK2VYerEjIB4TmX7SVrGg" -X GET https://gxxxxxxxxxxxxxx-yyyyyy.adb.eu-stockholm-1.oraclecloudapps.com/ords/my_client/soda/latest
HTTP/1.1 404 Not Found
Date: Sat, 12 Oct 2024 09:43:55 GMT
Content-Type: application/problem+json
Content-Length: 181
Connection: keep-alive

{
"code": "NotFound",
"message": "Not Found",
"type": "tag:oracle.com,2020:error/NotFound",
"instance": "tag:oracle.com,2020:ecid/2f98809191ff9c3094347f5c031a0cdb"

Also see my previous post about the same problem: My previous question about the same problem

I would appreciate any help on this problem.

Current status after Jeffs answer below

curl \
--user aaaaaaaaaa..:bbbbbbbbbb.. \
--data 'grant_type=client_credentials' \
https://gyyyyyyyyyy-zzzzzz.adb.eu-stockholm-1.oraclecloudapps.com/ords/peka/oauth/token
{"access_token":"Bp9iAzk-ICda0q0bPYxJvQ","token_type":"bearer","expires_in":3600}peter_xxxx@cloudshell:~ (eu-stockholm-1)$ 


curl -i -X POST \
-H "Authorization: Bearer Bp9iAzk-ICda0q0bPYxJvQ" \
-H "Content-Type: application/json" \
--data '{}' \
https://gyyyyyyyyyy-zzzzzz.adb.eu-stockholm-1.oraclecloudapps.com/ords/peka/soda/latest/MyTest?action=query
HTTP/1.1 401 Unauthorized
Date: Sat, 12 Oct 2024 17:23:11 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Strict-Transport-Security: max-age=31536000;includeSubDomains
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN

{"type":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.2","status":401,"title":"unauthorized","detail":"Not authorized."}

SOLUTION

I was finally able to solve this:

curl -i -k --user "xxxxxxxxx..:yyyyyyyyyyy.." \
--data "grant_type=client_credentials" \
"https://zzzzzzzz-99999999.adb.eu-stockholm-1.oraclecloudapps.com/ords/peka/oauth/token"

Result: XdXMYiAMfhACM1QtT6qAxg

curl -s -H "Authorization: Bearer XdXMYiAMfhACM1QtT6qAxg" -X GET https://zzzzzzzz-99999999.adb.eu-stockholm-1.oraclecloudapps.com/ords/peka/soda/latest/MyJson | jq -r '.items[0].value.name'

Result: Frank Zappa

This is correct. Thank you for help.

Upvotes: 2

Views: 56

Answers (2)

p3consulting
p3consulting

Reputation: 4640

Now you get a 401 "Not authorized." error, which just means you have to renew the token. See other answers here to use cURL with OAuth2, like How to perform OAuth 2.0 using the Curl CLI?

Upvotes: 0

thatjeffsmith
thatjeffsmith

Reputation: 22457

There's nothing mapped to ords/my_client/soda/latest, so your GET receives a 404.

If you want to access one of your collections, you have to follow soda/latest (which is the api/version - you're saying let's use the latest version of SODA) with the collection name

so ords/my_client/soda/latest/stuff

But that's not it, you don't use GETs, you're going to do a POST

POST ords/my_client/soda/latest/stuff?action=query

Then set a header for your request

-H "Content-Type: application/json"

And on the request body, send your query string --data '{}'

That'll match everything in your stuff collection.

Upvotes: 2

Related Questions