Header in request some REST

Stimulsoft Reports.JS discussion
Mateus Garrido Kern
Posts: 45
Joined: Wed Sep 04, 2019 5:19 pm
Location: Curitiba/PR (Brazil)

Header in request some REST

Post by Mateus Garrido Kern »

Hi, I intend to make a call to a GET method of my API, but I need to send the Token in the header.

I manage my request changing the "pathData" of my report.

The follow code was get by the publish page of stimulsoft site (https://publish.stimulsoft.com), and modified the pathData:

Code: Select all

import { Component } from '@angular/core';
import { ViewEncapsulation } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';

declare var Stimulsoft: any;

@Component({
	selector: 'app-root',
	template: `<div>
					<h2>Stimulsoft Reports.JS - MockTest_ReportLivroDiario.mrt - Viewer</h2>
					<div id="viewerContent"></div>
				</div>`,
	encapsulation: ViewEncapsulation.None
})

export class AppComponent {
	options: any = new Stimulsoft.Viewer.StiViewerOptions();
	viewer: any = new Stimulsoft.Viewer.StiViewer(this.options, 'StiViewer', false);

	ngOnInit() {
		var report = Stimulsoft.Report.StiReport.createNewReport();
		report.loadFile("reports/MockTest_ReportLivroDiario.mrt");

		var dbMockTest = report.dictionary.databases.getByName("MockTest");
		dbMockTest.pathData = "https://api.test.com//mock-test";

		this.viewer.report = report;
		this.viewer.renderHtml("viewerContent");
	}

	constructor(private http: HttpClientModule) {

	}
}
How am I manage the header of my request?
Mateus Garrido Kern
Email: mateus.kern@digibyte.com.br
Mateus Garrido Kern
Posts: 45
Joined: Wed Sep 04, 2019 5:19 pm
Location: Curitiba/PR (Brazil)

Re: Header in request some REST

Post by Mateus Garrido Kern »

Or to read some JSON Object, but I was not successful to use the "loadFromJsonObject", I got this error:

Code: Select all

[color=#FF0000]
ERROR TypeError: t.properties is not a function
    at a.u.loadFromJsonObject (stimulsoft.reports.js:58)
    at a.s.loadFromJsonObject (stimulsoft.reports.js:58)
    at AppComponent.push../src/app/app.component.ts.AppComponent.ngOnInit (app.component.ts:26)
    at checkAndUpdateDirectiveInline (core.js:20665)
    at checkAndUpdateNodeInline (core.js:21929)
    at checkAndUpdateNode (core.js:21891)
    at debugCheckAndUpdateNode (core.js:22525)
    at debugCheckDirectivesFn (core.js:22485)
    at Object.eval [as updateDirectives] (AppComponent_Host.ngfactory.js? [sm]:1)
    at Object.debugUpdateDirectives [as updateDirectives] (core.js:22477)
[/color]
Mateus Garrido Kern
Email: mateus.kern@digibyte.com.br
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Header in request some REST

Post by HighAley »

Hello, Ram.

You could handle the BeginProcessData event.
You could modify headers there with code like this:

Code: Select all

viewer.onBeginProcessData = function (event) {
	event.headers.push({key: "headerName", value: "headerValue"});
}
Thank you.
Mateus Garrido Kern
Posts: 45
Joined: Wed Sep 04, 2019 5:19 pm
Location: Curitiba/PR (Brazil)

Re: Header in request some REST

Post by Mateus Garrido Kern »

Hello, HighAley.

This works great, thank you.
Mateus Garrido Kern
Email: mateus.kern@digibyte.com.br
Andrew
Posts: 4104
Joined: Fri Jun 09, 2006 3:58 am

Re: Header in request some REST

Post by Andrew »

Great! You are welcome!
d.pujdak
Posts: 12
Joined: Wed May 13, 2020 3:44 pm

Re: Header in request some REST

Post by d.pujdak »

I am trying to do the same but it is not working.
Do you know if there is anything I am missing?
I am using OData conection.

Code: Select all

stiViewer.onBeginProcessData = this.onBeginProcessData;
onBeginProcessData(e) {
    e.headers.push({ key: "Authorization", value: `Bearer ${this.me.access_token}` });
    console.log(e);
},
Last edited by d.pujdak on Sat May 16, 2020 1:26 pm, edited 1 time in total.
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Header in request some REST

Post by HighAley »

Hello,

Sorry, we don't know how the authorization should work.
We were asked for a way to add the header, and we have added it.

Thank you.
d.pujdak
Posts: 12
Joined: Wed May 13, 2020 3:44 pm

Re: Header in request some REST

Post by d.pujdak »

Ok. Looks like it is a bug. I reproduced it here: https://github.com/fairking/Samples-JS/ ... rc/App.vue
Headers are not applied to the odata request.
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Header in request some REST

Post by HighAley »

Hello.

You could add authentication information when you create the OData connection in the Designer.
We need to check if it's possible to push the token there.
We will answer you by email.

Thank you.
d.pujdak
Posts: 12
Joined: Wed May 13, 2020 3:44 pm

Re: Header in request some REST

Post by d.pujdak »

You could add authentication information when you create the OData connection in the Designer.
It is not possible. It asks for user's password which I don't have. I only have OAuth 2.0 Token:

Code: Select all

Authorization: Bearer <user_token>
https://developer.mozilla.org/en-US/doc ... on_schemes
Post Reply