Job Submission via API - help please!!

Post Reply
dgordeyev
Newbie
Posts: 2
Joined: Tue Nov 21, 2023 11:30 pm

Job Submission via API - help please!!

Post by dgordeyev »

Hello all! I am developing a custom front-end job submission UI for our project managers to use. I have a simple file upload page which sends a user-selected file to Switch for processing.

For the time being, all my parameters and variables (username, password, content size, etc.) are being defined within my code, as I'm just trying to at least set up a working link between my localhost and the Switch app.

I am using vanilla JavaScript, with VSCode as my IDE, and for my own reference, I am following the Switch Web Services REST API Documentation written by Enfocus: https://www.enfocus.com/manuals/Develop ... index.html

I have no trouble logging in and authenticating to the Switch server, whether I'm using the Documentation sample Login points, or my own JS code:
Login_Success.PNG
Login_Success.PNG (84.64 KiB) Viewed 23345 times


Next, I need to select a file to submit for a job. This has absolutely no issues if using the API Documentation. I'm even getting a job ID response from the server. However, when submitting the same file using my UI, the server returns a status 500 - Internal Server Error:
Submission_Success.PNG
Submission_Success.PNG (72.18 KiB) Viewed 23345 times

How is this possible? If submission via the Documentation is successful, that means all my server settings and ports are correct, and open. I am making sure to include all the necessary data that is also included when submitting via the Documentation page. This can be seen in my code, as well. I have tried troubleshooting for weeks with no success. Maybe someone can help understand where to look next?

I'm attaching a zip of my code, in case its helpful.
SwitchPortal_Front_End.zip
(4.93 KiB) Downloaded 680 times

Thank you so much!
Dima
Padawan
Advanced member
Posts: 358
Joined: Mon Jun 12, 2017 8:48 pm
Location: Belgium
Contact:

Re: Job Submission via API - help please!!

Post by Padawan »

I haven't done job submission to Switch myself, but looking at your code I see that you set the Content-Type and Content-Length headers. When working in nodejs I personally use a library to calculate these when I work in nodejs.
From what I can find online you don't have to specify them when you work in the browser, the browser will add them for you:
https://stackoverflow.com/questions/435 ... sing-fetch

If that doesn't help, I suggest you test both your site and the documentation using the network tab of the browser developer tools open. Then you can compare the requests being sent by the documentation and the request sent by your website and search for the differences.
freddyp
Advanced member
Posts: 1023
Joined: Thu Feb 09, 2012 3:53 pm

Re: Job Submission via API - help please!!

Post by freddyp »

Moreover, the code that sets Content-Length is not correct. Just opening the code in VSC showed an error on line 170.
Post Reply