Document creation via the API

lock
push_pin
done
Answered
10

 

The following documentation is followed: 

https://docs.superoffice.com/en/api/netserver/web-services/howto/document/rest-generate-document.html?tabs=generate-document-rest

The first step, creating the document data set via the API, is successfully completed. However, when generating the content - both via a document template and when uploading the content directly - the following error message always appears:

„Cannot create directory \\**\con\2025.1 because a file already exists with that name.“

This error message also occurs if a new, non-existent file name is specified when the document data record is created.

If a document is created directly in SuperOffice and the content is then overwritten/updated via the API, this works without any problems - in this case a new, unique file name is automatically generated.

The document is available in SuperOffice as a template and contains contact and company variables that should also be filled in via the API

Does anyone have more detailed information or suggestions for solutions?

 

 

12 Feb 2025 | 09:04 AM

All Replies (10)

Hi Ralf,

I am unable to reproduce your error. 

Using the REST API, I can create a document based on a template and a stream without issue. 

// Get a document entity

GET https://{{env}}.superoffice.com/{{tenant}}/api/v1/Document/default
Authorization: Bearer {{token}}
Accept: application/json

Then persist the document entity:

POST https://{{env}}.superoffice.com/{{tenant}}/api/v1/Document
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "DocumentId": 0,
  "UpdatedBy": null,
  "CreatedBy": null,
  "Attention": "",
  "Header": "My document header test",
  "Name": "MyDocumentTest.docx",
  "OurRef": "",
  "YourRef": "",
  "CreatedDate": "0001-01-01T00:00:00Z",
  "UpdatedDate": "0001-01-01T00:00:00Z",
  "Description": "",
  "DocumentTemplate": { DocumentTemplateId: 2 },
  "Person": { PersonId: 8 },
  "Associate": null,
  "Contact": { ContactId: 5 },
  "Project": null,
  "Date": "0001-01-01T00:00:00Z",
  "ExternalRef": "",
  "Completed": "NotStarted",
  "ActiveLinks": 0,
  "Type": "Document",
  "Links": [],
  "LockSemantics": "None",
  "Sale": null,
  "SuggestedDocumentId": 0,
  "Snum": 0,
  "UserDefinedFields": {
    "SuperOffice:3": "False",
    "SuperOffice:3:DisplayText": "[SR_NO]",
    "SuperOffice:4": ""
  },
  "ExtraFields": {},
  "CustomFields": {
    "SuperOffice:3": "[I:0]",
    "SuperOffice:3:org": "[I:0]",
    "SuperOffice:3:DisplayText": "[SR_NO]",
    "SuperOffice:4": "",
    "SuperOffice:4:org": ""
  },
  "PublishEventDate": "0001-01-01T00:00:00Z",
  "PublishTo": "9999-12-31T23:59:59Z",
  "PublishFrom": "0001-01-01T00:00:00Z",
  "IsPublished": false,
  "VisibleFor": [
    {
      "VisibleId": 0,
      "Visibility": "All",
      "DisplayValue": "[SR_VFC_ALL]",
      "TableRight": null,
      "FieldProperties": {}
    }
  ]
}

 

Then generate the physical document based on the template:

// Assuming returned document ID from above was 166
// Create the physical document from template

POST https://{{env}}.superoffice.com/{{tenant}}/api/v1/Document/166/Content
Authorization: Bearer {{token}}
Accept: application/json

Otherwise, get a document stream, set the hearders based on what you are sending...see the DOCS

PUT https://{{env}}.superoffice.com/{{tenant}}/api/v1/Document/166/Content
Authorization: Bearer {{token}}
Content-Type: application/octet-stream
Accept: application/json

"VEVTVCBET0NVTUVOVA==",

 

So, please provide instructions how to reproduce your error. Use whatever language or code you are using in development. 

 

 

 

12 Feb 2025 | 01:59 PM
Hello Tony
thank you offering further support. See further down the code. Please be aware that we are using SO OnSite

I am using Postman for testing, and here are the detailed steps:

### Request 1 ###
### Set default values into a new DocumentEntity. ###

GET /SuperOffice/api/v1/Document/default HTTP/1.1
Accept: application/json
Authorization: Basic

### Response 1 ###

{
"DocumentId": 0,
"UpdatedBy": null,
"CreatedBy": null,
"Attention": "",
"Header": "",
"Name": "",
"OurRef": "",
"YourRef": "",
"CreatedDate": "0001-01-01T00:00:00",
"UpdatedDate": "0001-01-01T00:00:00",
"Description": "",
"DocumentTemplate": null,
"Person": null,
"Associate": null,
"Contact": null,
"Project": null,
"Date": "0001-01-01T00:00:00",
"ExternalRef": "",
"Completed": "NotStarted",
"ActiveLinks": 0,
"Type": "Document",
"Links": [],
"LockSemantics": "None",
"Sale": null,
"SuggestedDocumentId": 0,
"Snum": 0,
"UserDefinedFields": {
"SuperOffice:1": "",
"SuperOffice:3": "",
"SuperOffice:2": ""
},
"ExtraFields": {},
"CustomFields": {
"SuperOffice:1": "",
"SuperOffice:1:org": "",
"SuperOffice:3": "",
"SuperOffice:3:org": "",
"SuperOffice:2": "",
"SuperOffice:2:org": ""
},
"PublishEventDate": "0001-01-01T00:00:00",
"PublishTo": "9999-12-31T23:59:59",
"PublishFrom": "0001-01-01T00:00:00",
"IsPublished": false,
"VisibleFor": [
{
"VisibleId": 0,
"Visibility": "All",
"DisplayValue": "[SR_VFC_ALL]",
"TableRight": null,
"FieldProperties": {}
}
],
}

### Request 2 ###
### Creates a new DocumentEntity Save the document entity. ###

POST /SuperOffice/api/v1/Document HTTP/1.1
Content-Type: application/json
Authorization: Basic

{
"DocumentId": 0,
"UpdatedBy": null,
"CreatedBy": null,
"Attention": "",
"Header": "My document header test",
"Name": "MyDocumentTest.docx",
"OurRef": "",
"YourRef": "",
"CreatedDate": "0001-01-01T00:00:00",
"UpdatedDate": "0001-01-01T00:00:00",
"Description": "",
"DocumentTemplate": { "DocumentTemplateId": 543 },
"Person": { "PersonId": 30176 },
"Associate": null,
"Contact": { "ContactId": 23697 },
"Project": null,
"Date": "0001-01-01T00:00:00",
"ExternalRef": "",
"Completed": "NotStarted",
"ActiveLinks": 0,
"Type": "Document",
"Links": [],
"LockSemantics": "None",
"Sale": null,
"SuggestedDocumentId": 0,
"Snum": 0,
"UserDefinedFields": {
"SuperOffice:1": "",
"SuperOffice:3": "",
"SuperOffice:2": ""
},
"ExtraFields": {},
"CustomFields": {
"SuperOffice:1": "",
"SuperOffice:1:org": "",
"SuperOffice:3": "",
"SuperOffice:3:org": "",
"SuperOffice:2": "",
"SuperOffice:2:org": ""
},
"PublishEventDate": "0001-01-01T00:00:00",
"PublishTo": "9999-12-31T23:59:59",
"PublishFrom": "0001-01-01T00:00:00",
"IsPublished": false,
"VisibleFor": [
{
"VisibleId": 0,
"Visibility": "All",
"DisplayValue": "[SR_VFC_ALL]",
"TableRight": null,
"FieldProperties": {}
}
]
}

### Response 2 ###

{
"DocumentId": 441106,
"UpdatedBy": null,
"CreatedBy": {
"AssociateId": 567,
xxx
},
"Attention": "",
"Header": "My document header test",
"Name": "MyDocumentTest.docx",
"OurRef": "",
"YourRef": "",
"CreatedDate": "2025-02-13T07:58:24",
"UpdatedDate": "0001-01-01T00:00:00",
"Description": "",
"DocumentTemplate": {
"DocumentTemplateId": 543,
xxx
},
"Person": {
"Position": "",
"PersonId": 30176,
xxx
},
"Associate": {
"AssociateId": 567,
xxx
},
"Contact": {
"ContactId": 23697,
xxx
},
"Project": null,
"Date": "2025-02-13T00:00:00",
"ExternalRef": "",
"Completed": "NotStarted",
"ActiveLinks": 0,
"Type": "Document",
"Links": [],
"LockSemantics": "None",
"Sale": null,
"SuggestedDocumentId": 0,
"Snum": 27,
"UserDefinedFields": {
"SuperOffice:1": "",
"SuperOffice:3": "",
"SuperOffice:2": ""
},
"ExtraFields": {},
"CustomFields": {
"SuperOffice:1": "",
"SuperOffice:1:org": "",
"SuperOffice:3": "",
"SuperOffice:3:org": "",
"SuperOffice:2": "",
"SuperOffice:2:org": ""
},
"PublishEventDate": "0001-01-01T00:00:00",
"PublishTo": "9999-12-31T23:59:59",
"PublishFrom": "0001-01-01T00:00:00",
"IsPublished": false,
"VisibleFor": [
{
"VisibleId": 0,
"Visibility": "All",
"DisplayValue": "[SR_VFC_ALL]",
"TableRight": null,
"FieldProperties": {}
}
]
}

### Request 3 ###
### Create a new physical document based on a document template and store it in the document archive. ###

POST /SuperOffice/api/v1/Document/441106/Content HTTP/1.1
Accept: application/json
Authorization: Basic

### Response 3 ###

{
"Error": true,
"ErrorType": "InvalidOperationException",
"Message": "Cannot create directory \\\\***\\con\\2025.1 because a file already exists with that name.",
"FriendlyMessage": "",
"ErrorSource": "SoDataBase",
"InnerError": {
"ErrorType": "SoException",
"Message": "Service call Document.CreateNewPhysicalDocumentFromTemplateWithCustomTags2 failed",
"ErrorSource": "SuperOffice.Services.Implementation",
"InnerError": {
"ErrorType": "Exception",
"Message": "Error occurred at creating the physical document MyDocumentTest.docx",
"ErrorSource": "SoDataBase",
"InnerError": {
"ErrorType": "InvalidOperationException",
"Message": "Cannot create directory \\\\***\\con\\2025.1 because a file already exists with that name.",
"ErrorSource": "SoDataBase",
"InnerError": null
}
}
}
}

15 Feb 2025 | 09:33 AM

Are you using an Online or OnSite environment?

 

In case of OnSite, This bug might be related: https://community.superoffice.com/en/product-releases/bugs-wishes/product-issue/?bid=71284&azure=1

12 Feb 2025 | 06:04 PM
Looks the same. I would still be interesting in seeing code to reproduce it because the snippet on the page linked to doesn't match the results.
13 Feb 2025 | 08:27 AM
Hello David
I uploaded the detailed steps of the code.
Please be aware that we are using SO OnSite.
Postman has been used from our Supplier in charge of the API and our Website.
Best regards
Ralf
15 Feb 2025 | 10:03 AM

Hi Ralf! Thanks for the reproducable code snippet. We are sorry for the inconvenience, and have flagged this bug and it is slated to be fixed/released in the next onsite release.

Best regards.

16 Feb 2025 | 06:00 AM
Hi Tony,
thank you very much. Any idea when the new onsite release is scheduled?
Best regards
16 Feb 2025 | 06:56 AM
It's only a rough estimate at this time, but I think we're aiming to publish v10.5.4 for onsite in April.
18 Feb 2025 | 02:19 PM

Hello Tony

good news, we wait for v10.5.4 for onsite in April.

 

May I ask you to have a quick look on the following request

https://community.superoffice.com/en/technical/forums/api-forums/online-web-services/trigger-double-opt-in-for-newsletter-subscriptions-via-api/

We embedded a webinar registration on our website with REST API link to SuperOffice. We face a final problem not knowing how the execute the double-opt in. 

( a ) Is it possible to trigger a form submit with via REST API to initiate the normal double opt-in which we would like to use for e-mails which are not yet stored in SuperOffice

For repeat registration we would like to not only add the contacts to the webinar project but also document it in SuperOffice as it is normally done by form submission protocolled as activity. 

( b ) can we set form submission entities via REST API or any other idea?

 

Best regards

Ralf

19 Feb 2025 | 11:24 AM

Hi Ralf,

Unfortunately there is no API to send a form submittion via the API. There was a wish for it, but that was not prioritized and closed.

You can use the PersonAgent.SendConsentConfirmationEmail to method. The person must already exists, and the person must already have the Consent Info already set. If not, you can use the PersonAgent.CreateDefaultConsentPerson API to create one, and then save it using the PersonAgent.SaveConsentPerson API.

Hope this helps!

3 h, 57 m ago | 03:34 PM

Add reply