I'm trying to use Angular5 with DocRaptor and ran into some issues. There isn't any documentation on their site regarding how to integrate with Angular, but there is a getting started guide for 'other'. I have also investigated this issue here (/using-docraptor-web-service-with-angularjs) without much luck.
My Module
In my module I have added the following:
import { HttpClientModule } from '@angular/common/http';
My Component
In my component I have imported:
import { HttpClient } from '@angular/common/http';
I have a button that takes a string and generates a PDF. I'm not too knowledgable with post requests. The following is what i've tried:
return this.http.post('https://myAPIKEY@docraptor.com/docs', {
"test": true,
"name": "testDocument.pdf",
"document_content": '<div>PDF generation test</div>',
"type": "pdf",
}).subscribe(
res => {
console.log(res);
},
err => {
console.log("Error occured");
}
);
This causes two errors:
POST https://docraptor.com/docs 401 (Unauthorized)
and
Failed to load https://docraptor.com/docs: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://mydomain' is therefore not allowed access. The response had HTTP status code 401.
Any assistance on how to correctly post the content to DocRaptor and receive the download URL in return without CORS issues would be massively appreciated.
UPDATE
I managed to get the following code to successfully post to DocRaptor. I just need to make a request with the returned status ID:
return this.http.post('https://docraptor.com/docs?user_credentials=mycreds', forDocRaptor).subscribe(res => {
console.log(res);
},
err => {
console.log("Error occured = ", err);
}
)