I am running into another issue. I have
# package-development
p
I am running into another issue. I have an API controller that I am trying to reach, but it returns an Unauthorized. However, the code is almost exactly the same as another piece of code that doesn't have that issue. Do I need to do anything else than this? https://cdn.discordapp.com/attachments/882984798719729704/1291477827396309138/image.png?ex=67003df4&is=66feec74&hm=54c56bb0cb7491992b52c4ff322e99c6c00578ee32fbe90d98f873d41b7acc84&
a
Does the request to the API include the
Authorization
header with a bearer token?
p
Nope, it doesn't 🤔 While the other one does
Only difference I see is that one gets its host from the HTML element and the other gets it from the constructor of a context
a
Can you share more of your code? Mostly related to calling the API. There must be somewhere the header/token isn't properly being set
p
Yes, everything is in here: https://github.com/patrickdemooij9/SeoToolkit.Umbraco/tree/dev/main/src/SeoToolkit.Umbraco.RobotsTxt/assets/src Basically context creates the repository, which creates the source and then immediately does the API call
Which maybe is too quickly? I am not sure if I should do API calls in the constructor of the context
w
Have you generated API from OpenAPI spec with HEYApi or similar. Then in the entrypoint you need to do the Auth stuff
Ignore me 🙈 as I didn't see that you have that code already in your screenshot
p
Omg, finally figured it out! Need to import
import { OpenAPI } from './api';
instead of
import { OpenAPI } from '@umbraco-cms/backoffice/external/backend-api';
w
AH yeh your locally generated one rather than trying to reuse the backoffice CMS MGMT API