Hi! Im using GoodData Cloud with @gooddata/sdk-bac...
# gd-beginners
r
Hi! Im using GoodData Cloud with @gooddata/sdk-backend-tiger and im trying to use axios from the tiger backend and im getting this error. I dont see anything wrong in my code please give me an correct example of how to do it. Thank you
r
Hi, you're sending API request with incorrect Content-type (
application/json
) instead of
application/vnd.gooddata.api+json
. Update your api client to send a proper content-type
🙌 1
i
Hi @Robin Karlsson, as stated by my colleague above, the issue is really caused by incorrect Content-type, as indicated in the error details itself.
r
Hi! I also tried to add it to headers but still same error. Im trying to make this post from React application built with GoodData´s toolkit. Cant you please show me where i need to change this ? or give me link to correct documentation. Thank you!
i
Sorry to hear so. May I know what exact steps or article did you follow, please?
r
No article or steps, im just exploring GoodData Cloud and want to make child workspace and i need to do it with the API call. So im just trying to figure out how to make a correct API call from GoodData Cloud. Can you share the documentation for it, I just cant find it. Thank you
i
Sure thing, thank you for the clarification. Please check the articles below: Workspace Objects Life Cycle Workspace Declarative API Interface
j
Hello @Robin Karlsson! How did you come up with
backend.backend.decorated.client.axios
? May I suggest you look for something like
backend.sdk.xhr
(or
backend.backend.sdk.xhr
)? This is what I use to fire my custom API requests towards the API endpoints and it works for me.
For example, I use the following to update CORS allowedOrigins:
Copy code
import { useAuth } from "../contexts/Auth";

const backend = useAuth();

backend.backend.sdk
    .xhr
    .put('/gdc/domains/jirizajic-internal/securitySettings/allowedOrigins', {
    body: {
        "allowedOrigins": {
        "items": [
            "<https://deployed-analytics-app.com>",
            "<https://localhost.dev>"
        ]
        }
    }
    })
    .then(response => console.log(response))
r
When i logged backend on @gooddata/sdk-backend-tiger i found it, When im using backend.backend.sdk.xhr with @gooddata/sdk-backend-bear it works but with my other project on GoodData Cloud with @gooddata/sdk-backend-tiger i get undefined
So my question is, is there a simple way to use the API when using @gooddata/sdk-backend-tiger ? Like backend.backend.sdk.xhr on @gooddata/sdk-backend-bear ? Thank you
j
That's weird 🤔 Both sdk-backend-bear and sdk-backend-tiger should implement sdk-backend-spi so it should work in both. Let me check and I'll get back to you!
I see what's going on. The
xhr
is actually not part of the interface. It is only implemented in sdk-backend-bear. I understand it works for you, but now you're looking for a similar thing in sdk-backend-tiger, correct?
Actually, sdk-backend-tiger contains directly all the methods you should need. For example, to list all the dashboards you can simply call:
Copy code
backend
    .backend
    .workspace('ecommerce-parent')
    .dashboards()
    .getDashboards()
    .then(response => console.log(response));
You can find the API reference at https://sdk.gooddata.com/gooddata-ui-apidocs/v8.11.0/docs/sdk-backend-spi.ianalyticalworkspace.html.
If you want to use axios to work with the tiger backend, you can do that too. Unlike bear, the tiger backend supports token authentication, so setting up the right headers for axios is really simple:
Copy code
axios.get('/api/v1/entities/workspaces/ecommerce-parent/analyticalDashboards', {
    headers: {
        'Authorization': 'Bearer amlyaS56yoursecrettokn',
    }
}).then(response => console.log(response.data));
Let me know if it works for you @Robin Karlsson!
r
Getting dashboard data works for me.
But when im trying to create childworkspace with axios i still get this error and im using token.
j
Hello @Robin Karlsson! I see your POST request going against https://localhost:3000 — is there a proxy in your environment? Is it the environment created using @gooddata/create-gooddata-react-app?
I just tested this in a different browser that I don't normally use in a plain HTML setup — no proxy, no webpack, no SDK… and it still works 👇
r
Im using @gooddata/create-gooddata-react-app with tiger backend, and the token im using is personal access token and is created here:
and yes i think Im using proxy that comes with @gooddata/create-gooddata-react-app
j
At this point I would encourage you to start with the plain index.html I shared — just to double-check your token and everything else is working. Then I would continue debugging by comparing the requests in the Network tab until I find a diff — if it works in plain HTML environment then it must work in create-gooddata-react-app as well.