Community
Showing results for 
Search instead for 
Do you mean 
Reply

Adding an Attachment using the Web API

Highlighted
Silver Super Contributor
Posts: 2,340
Country: USA

Adding an Attachment using the Web API

I have been attempting to add an attachment to Act! using the Web API and while I have managed to create a history it isn't attaching the document.  I've also tried creating an attachment link and that doesn't appear to be working either.  Has anyone been able to get it to work?  I saw a post from a year ago with the same issue and there was no resolution.

 

This is the body of the post that I am using.  I've basically copied the output and just left out a couple of the parameters.

 

{

"isPrivate": false,
"details": "",
"regarding": "Doc2.docx",
"duration": "0 minutes",
"startTime": "2019-12-11T14:38:00",
"endTime": "2019-12-11T14:38:00",
"outlookID": null,
"historyTypeID": -1,
"historyType": {
"id": -1,
"name": "Library Document",
"description": ""
},
"created": "2019-12-11T14:38:01.247",
"edited": "2019-12-11T14:38:01.247",
"companies": null,
"contacts": [
{
"id": "8e3b215d-1673-441a-98b1-8c5dd55fdfec",
"displayName": "Chris Huffman"
}
],
"groups": null,
"opportunities": null,
"attachment": {
"displayName": "Doc2.docx",
"fileExtension": ".lnk",
"fileName": "C:\\ACTSHARE\\Databases\\BM_Empty-database files\\Attachments\\Doc2.lnk",
"fileSize": 1,
"fileSizeDisplay": "1 KB",
"fileType": "Microsoft Word Document",
"lastModified": "2019-12-11T14:38:01.2413212-06:00",
"personal": false
}
}

 

Thanks!

 

Stan


If you would like to get more out of ACT! you can find an ACT! Certified Consultant near you by going to:www.act.com/acc.
-------------------------------------------------------------------------------------
Stan Smith
ACT! Certified Consultant
ADS Programming Services, Inc.
(205) 222-1661
www.adsprogramming.com
www.actwebhosting.com
Click Here to Purchase Act!
Highlighted
Employee
Posts: 123
Country: USA

Re: Adding an Attachment using the Web API

In the swagger docs, look under SupplementalFiles.  This is a list of endpoints that are used for attachments.  After you created the history record you can upload the attachment with this endpoint.

 

FormData post to:

 

POST: /api/attachments/history/{history id}

Content-Type: application/x-www-form-urlencoded

 

 

Highlighted
Silver Super Contributor
Posts: 2,340
Country: USA

Re: Adding an Attachment using the Web API

Is there a way to add a link to a document using the API?


If you would like to get more out of ACT! you can find an ACT! Certified Consultant near you by going to:www.act.com/acc.
-------------------------------------------------------------------------------------
Stan Smith
ACT! Certified Consultant
ADS Programming Services, Inc.
(205) 222-1661
www.adsprogramming.com
www.actwebhosting.com
Click Here to Purchase Act!
Highlighted
Employee
Posts: 123
Country: USA

Re: Adding an Attachment using the Web API

Not sure I understand what you're asking.  Once you create and upload a document it should already be linked.  First, post the document (1st post below).  This will create a document and response with a document id.  Use that document id to post the attachment document (2nd post below - SupplementalFiles)  The attachment document will be linked to the document.

 

 

POST: api/documents
{
    "regarding":"PostMan Backup",
    "startTime":"2019-10-22T15:00:00-07:00",
    "endTime":"2019-10-22T15:30:00-07:00",
    "contacts": [
        {
            "id": "e778ea09-5477-48d6-9c58-bb899c5c453c"
        }
    ],
    "historyTypeID": -1
}

POST: api/attachments/documents/eeda9be2-2bf4-45a6-8116-cc2e4b7bd213       -- GUID is the document id from the first post.

 

 

Highlighted
Silver Super Contributor
Posts: 2,340
Country: USA

Re: Adding an Attachment using the Web API

There are currently two ways to attach a document in Act!.  The first way is to attach the document by making a copy of the document and putting it in the attachments folder.  The second way is to simply create a link to the document in it's current location.  That is what my client wants to do.  They have the documents somewhere on the local network and they simply want to point to the current location of the document.  There is no need to "upload" the document using the api but the api would need to support the creation of a linked document entry.  Make sense?

 

Stan


If you would like to get more out of ACT! you can find an ACT! Certified Consultant near you by going to:www.act.com/acc.
-------------------------------------------------------------------------------------
Stan Smith
ACT! Certified Consultant
ADS Programming Services, Inc.
(205) 222-1661
www.adsprogramming.com
www.actwebhosting.com
Click Here to Purchase Act!
Highlighted
Employee
Posts: 123
Country: USA

Re: Adding an Attachment using the Web API

The way I described is the only supported way you can do this in the API.  The call to the supplementalFiles will already copy the file so you don't need to do that manually.  If the file already exists in the attachment folder, you can just upload that file overtop of it's self.  But either way, the API copy the file.

Highlighted
Silver Super Contributor
Posts: 2,340
Country: USA

Re: Adding an Attachment using the Web API

When I attempt to upload the document I'm getting a 415 Unsupported Media Type.  I'm using the Content Type x-www-form-urlencoded.  Is there another setting I'm missing?


If you would like to get more out of ACT! you can find an ACT! Certified Consultant near you by going to:www.act.com/acc.
-------------------------------------------------------------------------------------
Stan Smith
ACT! Certified Consultant
ADS Programming Services, Inc.
(205) 222-1661
www.adsprogramming.com
www.actwebhosting.com
Click Here to Purchase Act!
Highlighted
Employee
Posts: 123
Country: USA

Re: Adding an Attachment using the Web API

Yes:  Since the payload is binary, you would use a Content-Type of: multipart/form-data

 

POST: api/documents

Content-Type: application/json

{
    "regarding":"PostMan Backup",
    "startTime":"2019-10-22T15:00:00-07:00",
    "endTime":"2019-10-22T15:30:00-07:00",
    "contacts": [
        {
          "id": "7945c328-32a3-42eb-90b8-81c1aff037fa"
        }
    ],
    "historyTypeID": -1
}

Response:

{
  "id": "4cbea1ad-62cb-411b-8316-065393f9a0ef",
  "manageUserID": "7945c328-32a3-42eb-90b8-81c1aff037fa",
  "recordManager": "Stephen Burton",
  "createUserID": "7945c328-32a3-42eb-90b8-81c1aff037fa",
  "isPrivate": false,
  "details": "",
  "regarding": "PostMan Backup",
  "duration": "30 minutes",
  "startTime": "2019-10-22T15:00:00-07:00",
  "endTime": "2019-10-22T15:30:00-07:00",
  "outlookID": null,
  "historyTypeID": -1,
  "historyType": {
    "id": -1,
    "name": "Library Document",
    "description": ""
  },
  "created": "2020-03-10T09:31:45-07:00",
  "edited": "2020-03-10T09:31:45-07:00",
  "companies": null,
  "contacts": [
    {
      "id": "7945c328-32a3-42eb-90b8-81c1aff037fa",
      "displayName": "Stephen Burton"
    }
  ],
  "groups": null,
  "opportunities": null,
  "attachment": null
}

POST: api/attachments/documents/4cbea1ad-62cb-411b-8316-065393f9a0ef

Content-Type: multipart/form-data

 

Response:

{
  "id": "4cbea1ad-62cb-411b-8316-065393f9a0ef",
  "attachment": {
    "displayName": "Postman_Dump.json.pdf",
    "fileExtension": ".pdf",
    "fileName": "C:\\Users\\stephen.burton\\Documents\\ACT\\ACT Data\\Databases\\BurtonBox-database files\\attachments\\Postman_Dump.json_637194295336201296.pdf",
    "fileSize": 40245,
    "fileSizeDisplay": "40245KB",
    "fileType": null,
    "lastModified": "0001-01-01T00:00:00-07:00",
    "personal": false
  }
}
Highlighted
Silver Super Contributor
Posts: 2,340
Country: USA

Re: Adding an Attachment using the Web API

When you post the document where are you putting the path to the existing document?


If you would like to get more out of ACT! you can find an ACT! Certified Consultant near you by going to:www.act.com/acc.
-------------------------------------------------------------------------------------
Stan Smith
ACT! Certified Consultant
ADS Programming Services, Inc.
(205) 222-1661
www.adsprogramming.com
www.actwebhosting.com
Click Here to Purchase Act!
Highlighted
Employee
Posts: 123
Country: USA

Re: Adding an Attachment using the Web API

I'm using Postman, so it is handled in the GUI as a NameValuePair.  If you are looking for a sample, it depends on the language how you would make a multi-part/form-data post.  You should be able to google "POST file to an API with multi-part/form-data" for the language (HTML, JavaScript, C#, etc) you are using.  Should have many samples out there.