Reputation: 11
We are attempting to create a new document in word online using the office javascript library. The script is contained in a word add in. The documentation for the create method is at https://dev.office.com/reference/add-ins/word/application. Calling the createdocument followed by the open method always results in a 403 forbidden error.
HTTP403: FORBIDDEN - The server understood the request, but is refusing to fulfill it.
(XHR)OPTIONS - https://offline.officeapps.live.com/outage.html
Failed to load https://offline.officeapps.live.com/outage.html: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://auc-word-edit.officeapps.live.com' is therefore not allowed access. The response had HTTP status code 403.
The code to open the document is as follows.
Word.run(function (context) {
var myNewDoc = context.application.createDocument();
context.load(myNewDoc);
return context.sync()
.then(function () {
myNewDoc.open();
context.sync();
}).catch(function (myError) {
console.log(e);
})
}).catch( errorHandler });
The error is occurring on the initial context.sync() call.
Word Online is saving to a Office 365 business account. Creating documents from the interface works.
Why is this error being returned?
Update
The error occurs only when the add in is used in the context of a Office 365 Business account backed by an online sharepoint server.
When I try using a personal OneDrive account the create document and open are successful.
Upvotes: 1
Views: 1622
Reputation: 11
This issue seems to have resolved itself. I can now create and open a document. I can only assume that it was a temporary problem with sharepoint or an issue in the javascript library.
thanks to those who tried to provide assisitance.
Upvotes: 0
Reputation: 5036
I think what you are trying to do its achievable with a single line of code, and it works in online. please try
Word.run(async (context) => {
context.application.createDocument().open();
context.sync();
});
Upvotes: 1