0
votes

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.

2
manually open the URL offline.officeapps.live.com/outage.html is also giving service unavailable error. and it is not a word document, just a html? can you show us at which step you repro it and more detailed information? - MSFT-Jipyua
I have clarified the original question and added a further update. - K Rouse
Have you see the "This Add-in is about to display a new window" dialogue when the Open method is run? and after that it will pop up a new widow to open the document, can you copy me the url of that widow? and it would be good if you can give a short video about the repro since I just tried on O365 account and can't repro it. - MSFT-Jipyua
Also for your O365 account, you should have a personal folder to hold your documents(the folder is where the document saved when you new a document from UI). Can you try just call the CreateDocument API and not the open API, then check whether under that folder the file is created? - MSFT-Jipyua
I was incorrect. The error is happening on the intial context.sync(). I found this out after just calling the create document API and then the sync. A dialogue appears "This Add-In is about to create a new document in your default folder on your current cloud repository". When I click ok then the error is returned in the javascript console. A document is not created in my onedrive business account. - K Rouse

2 Answers

1
votes

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();
    });
0
votes

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.