Page 1 of 2

Header in request some REST

Posted: Mon Mar 16, 2020 2:15 pm
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?

Re: Header in request some REST

Posted: Mon Mar 16, 2020 2:20 pm
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]

Re: Header in request some REST

Posted: Mon Mar 16, 2020 10:57 pm
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.

Re: Header in request some REST

Posted: Tue Mar 17, 2020 2:27 pm
by Mateus Garrido Kern
Hello, HighAley.

This works great, thank you.

Re: Header in request some REST

Posted: Wed Mar 18, 2020 10:17 am
by Andrew
Great! You are welcome!

Re: Header in request some REST

Posted: Wed May 13, 2020 3:52 pm
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);
},

Re: Header in request some REST

Posted: Thu May 14, 2020 12:41 pm
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.

Re: Header in request some REST

Posted: Sat May 16, 2020 1:28 pm
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.

Re: Header in request some REST

Posted: Tue May 19, 2020 2:12 pm
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.

Re: Header in request some REST

Posted: Tue May 19, 2020 4:06 pm
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