hi all
i am trying to poll an api on a multi-threaded timer, looking at the documentation here i see how to authenticate using a username/password. for my use case i must authenticate using a bearer token, please see the below image for my QActionBefore code in which i construct the request
i'm expecting to receive a response with a json body, instead i receive html for a login page - it seems authentication has failed. i tried adding the access token in the request headers but no luck
how can i authenticate properly using a bearer token rather than username/password while using a multi-threaded timer ?
many thanks all
Hi Stephen,
I tried to locally reproduce your issue and DataMiner seems to send the header as expected, so it should not be an issue for DataMiner to authenticate with the bearer token header.
I suggest you log the contents of the `requestSettings` object, to see what the actual contents of the bearer token are.
You could do this in the following way:
```
protocol.Log(protocol, \"QActionBefore Request data: new object[3] { \\\"http\\\" , new string[6] { \" + String.Join(\",\", requestSettings) + \" } };\");
```
The output of this should be visible in the element logging file.
This file can be found in `C:\\Skyline DataMiner\\Logging` and has the following name: <YourElementName>.txt.
You can then verify if the bearer token works as expected by using it in curl, Postman,...
Alternatively, you could take a completely different approach by not using a multithreaded timer, but by spinning up multiple threads in the QAction itself.
Instead of using the DataMiner `requestSettings` object, you would then be able to use a .NET Framework HTTP library, such as .NET HTTPClient to perform the HTTP calls.
This way, all the HTTP logic is handled by that library, and not by DataMiner itself.
Hope this helps.
Kind regards,