Misconception about /api/upload and use. Requesting input

Hello BigFix Forum. I am hoping for some assistance in understanding and utilizing aspects of the API.

My overall objective is to automate the uploading of a file (jar file in this specific case) to BF’s _Upload directory and create an action to send it out to some targets (that exist in pre-defined groups).

I had thought to make use of /api/upload and /api/action to get the job however, I may have misunderstood /api/upload.

$FilePath = "TEST_FILE.txt" $body = "" $global:uploadResult = Invoke-RestMethod -Credential $Credential -Uri https://b1p1-wbfxap01:52311/api/upload -Headers $headers -Method POST -InFile $FilePath -ContentType 'multipart/form-data' -ErrorAction SilentlyContinue -ErrorVariable uploadError -OutVariable uploadResult

My attempts at using /api/upload have managed to put my test file into the Master Action Site’s “Files” container. I was using the MO account in an attempt to work around some current access issues but going forward this would NOT be the case. It was the location of the file that surprised me. I was "ass"uming it would end up under \BES Server\wwwrootbes\Uploads.

Using get /api/uploads I get a return of all of my files under \BES Server\wwwrootbes\Uploads so it seemed that if I used it to POST that is where it would go.

Should I even be using /api/upload to put a file into \BES Server\wwwrootbes\Uploads or should I use a script to copy my file from source to the Uploads directory using it’s SHA1 as the directory?

Am I even on the correct path for getting where I want to be?

1 Like

@MrTonyBarnes, the /api/upload is analogous to file upload feature within the BES console.

image

I believe I understand where you’re going with this, but please DM me here so that we can discuss further and potentially develop a solution to share with the greater community.

1 Like

I think you are indeed on the correct path. Due to US weather my power is out and I can’t post my examples, but the “site file” result you are observing should result from POST to /api/site/{site}/file . Have you tried multiple iterations and maybe posted to the site in a different call?

A POST to /api/uploads should upload the file or files to the wwwrootbes/Uploads folder. A new subdirectory is created, named for the file’s sha1 for a single file; I’m actually not sure what the folder name is based on when uploading multiple files in one call, but that’s valid too.

The HTTP response should be an XML document containing the name, url, sha1, and size of the uploaded file.

I think you’re on the right track, I just suspect you may have duplicate copies of your file in a couple of different places.

https://developer.bigfix.com/rest-api/api/upload.html

1 Like

As Jason mentioned, I also believe you are on the right path.

The POST request to the /api/upload method will put the files under the Uploads folder.
I think you don’t even need to deal with the exact folder location of your new file. If you make the appropriate call to the POST request, you will be getting the following as response:

Response: BESAPI showing the name, url, sha1, and size of file.

You can parse that response to build your new action based on that without the need to check on the server locally.

I have written a couple of scripts that do exactly what you are trying to achieve I can provide more guidance if needed.

1 Like

Thank you @cmcannady. I appreciate the input and the offer. I will follow up with directly.

Sorry to hear about your power @JasonWalker. I hope that it was restored in short order. This weather (I’m outside Chicago) is dangerous for people and homes to be without power. Wishing you the best… and kudos for checking the forums under such conditions!

I will re-try my /api/upload call from using different credentials and see if being a non-MO user will put it under wwwrootbes/Uploads.

That may be possible. I did a check of wwwrootbes/Uploads and initially didn’t find my uploaded test file there but it’s possible that I missed it. I will re-verify during my testing.

Thanks @fermt, If both you and @JasonWalker are saying that the call to /api/uploads will put files into the Uploads folder… I will accept that as truth and figure out how I screwed it up :wink:

I appreciate the offer and I may take you up on that. But first I need to do my due-diligence. You know how that is.

Thank you all! Greatly appreciate this community and it’s giving nature.

1 Like