DocStarDownloadFile via REST SSO

And inside Epicor in this instance you can access this same file?

Yes.
I should also mention that when I test the

/DocStarTestConnection

and fill out all the required feilds, I connect successfully.
Which makes me wonder if I need to be passing DocStar credentials.
Have you worked with DocStar attachments via REST before?

Yes I have and you normally don’t need any credentials
As long as your rest api is authenticated that should be all you need

I’m going to put in a support request.
Thanks for your help.
Cheers.

What file transfer setting you have in attachment maintenance UI for Docstar, client side or using service?

1 Like

Was using Client Side, switched it to Using Service and it’s working.
Very Much Appreciated @Olga!

1 Like

@brandtley - could you provide more details on how to call the Ice.BO.AttachmentSvc/DocStartDownloadFile REST API, and how to extract the returned file - preferably using C# code?

Thanks

What is your use case?

We are using DocStar with Epicor for storing attachments related to sales orders. I’d like to be able to copy those files to another platform - Salesforce.com. I know how to upload files to Salesforce - just can’t figure out how to get the file from DocStar. We’re using Epicor REST API’s for a lot of other integration stuff between Salesforce and Epicor.

THanks

Interesting. Have you done a cost study for that? I’ve heard of more people moving documents out of SF than to SF. Document storage on SF wasn’t cheap the last time I checked.

Jose showed it in WCF. REST should be similar

2 Likes

@Olga - you don’t have a REST example, do you?

@Mark_Wonsil - we’re not moving document storage to Salesforce - we’re wanting to create an integration between Epicor and Salesforce and copying the Epicor files to Salesforce (we’re already doing it the other way and that works good). And, we have plenty of available storage in Salesforce.

@daveleland, this is in Javascript, but it’s still an example.

function uploadImage() {
    let epicorUrl = '';

This would be your Epicor API URL.

   let authentication = '';

This would be your Authentication. (e.g. Username + Password)

    let url = '/api/v1/Ice.BO.AttachmentSvc/DocStarUploadFile';

    var fileName = "TestImage" + $('#fileNumber').val();
    var fileExt = ".jpg";
    var file = fileName + fileExt;
    var fileData = $('#base64').val();
    return (async () => {
        const rawResponse = await fetch(epicorUrl + url, {
          method: 'POST',
          headers: {
            "accept": "application/json",
            "Content-Type": "application/json",
            "Authorization": authuentication
          },
          body: JSON.stringify({
            fileName: file,
            data: fileData,
            docTypeID: "Image",
            parentTable: "ShipHead",
            metadata: {
              _Author: "API User",
              _TableName: "Erp.ShipHead"
            }
          })
        });
        const content = await rawResponse.json();
      
        console.log(content);
        contentObject = content;
    })();
};

Don’t know if this is helpful at all.
Is there a specific method you are trying to use?

@daveleland, do you have postman?
https://www.postman.com/

1 Like

@brandtley - do you have an example for DocStarDownloadFile?

@daveleland, sorry had to dig around, but I found it.
Take my notes from the snippet before about ‘epicorUrl’ and ‘authentication’.

function downloadAttachment() {
    console.log("contentObject2: ", contentObject2);
    let epicorUrl = '';
    let authentication = '';
    let url = '/v1/Ice.BO.AttachmentSvc/DocStarDownloadFile';

    var val = contentObject2.value[0];
    var refNum = val.XFileRefNum;
    var xRefNum = parseInt(refNum);
    //const response2 = JSON.parse(contentObject2);
    return (async () => {
        const rawResponse3 = await fetch(epicorUrl + url, {
          method: 'POST',
          headers: {
            "accept": "application/json",
            "Content-Type": "application/json",
            "Authorization": authuentication
          },
          body: JSON.stringify({
            xFileRefNum: xRefNum,
            metadata: {
            }
          })
        });
        const content3 = await rawResponse3.json();

        //console.log(content3);
        contentObject3 = content3;
    })();
};

I think it gives you a base64 string, and you’ll have to convert it to whatever file format it should be.

@daveleland, sorry it isn’t in C#. I’m not really good at anything, but I am much more familiar with JavaScript than C#. Maybe @josecgomez would bless us with his wisdom.

Update: check this out, Epicor Rest Helper (Nuget) Updated V2, there may be some helpful information in here.

1 Like

Here’s the REST Call to do that

//Setup the Epicor REST API as outlined in the Epicor Rest Helper Nuget Documentation
var addedDocStarFile = EpicorRest.DynamicPost("Ice.BO.AttachmentSvc", "DocStarDownloadFile", new { xFileRefNum = 2222 });
//Where 2222 is the XFileRef number of the attachment 

The response looks like this

{
  "returnObj": "string",
  "parameters": {
    "metadata": {
      "additionalProp1": "string",
      "additionalProp2": "string",
      "additionalProp3": "string"
    },
    "additionalProp1": {},
    "additionalProp2": {},
    "additionalProp3": {}
  },
  "additionalProp1": "string",
  "additionalProp2": "string",
  "additionalProp3": "string"
}

Where returnObj is a Base64 encoded file.

3 Likes

Thanks much @brandtley and @josecgomez . With your help, I have it working now.

1 Like