Compose XML for HTTP POST using file in hot folder

teetomterrific
Member
Posts: 25
Joined: Mon Mar 09, 2020 10:22 pm

Compose XML for HTTP POST using file in hot folder

Post by teetomterrific »

I have a task I'm not sure how to tackle so I am seeking advice on how to approach the following:
1. I need to be able to pick up a file from a hot folder and from the file name extract a portion of the name from the file path
2. The Naming convention is 000000-00_000_0-C-Y.pdf. I only need the first section before the "_" which is a job name which is all numeric
3. I need to extract the last digit from the six digits in the Job name that come before the "-" in order to select a server name for the HTTP POST URL
4. I need to compose the XML for the POST body and put it in the parameters
5. Send the POST and if the response is not 200 OK send a failure email.

I'm looking for advice on flow structure and how to utilize regular expressions to extract the file components. I'm very weak with javascript, but have experience with VB.net. I would prefer to utilize Switch Apps rather than scripting, but that may not be possible. Please Advise.
r.zegwaard
Member
Posts: 94
Joined: Fri Jul 08, 2011 10:31 am
Location: The Netherlands

Re: Compose XML for HTTP POST using file in hot folder

Post by r.zegwaard »

Hi teetomterrific,

I think this should work. (Not tested)

1) Very easy with Switch :-)
2) Use this variable [Job.NameProper:Before="_"] and store it in private data
3) Use this variable [Job.NameProper:Search="\d{1}(?=-)"] and store it in private data
4) Compose the XML with the app "Create text file" or "Create file from template". They are in the app-store.
5) Do the post with Data = script.expression

Code: Select all

jobBody = File.read(job.getPath(),"UTF-8");
jobBody;
freddyp
Advanced member
Posts: 1028
Joined: Thu Feb 09, 2012 3:53 pm

Re: Compose XML for HTTP POST using file in hot folder

Post by freddyp »

One improvement to Robert's answer to number 5: you can avoid the use of a script expression by using v20 of HTTP request and choosing "POST a body - Input job".
teetomterrific
Member
Posts: 25
Joined: Mon Mar 09, 2020 10:22 pm

Re: Compose XML for HTTP POST using file in hot folder

Post by teetomterrific »

I ended up doing everything in a script which works great except I need for Switch to not add the prefix to the file name. When I set the Input folder to "leave originals in place" the path served up by Switch preserves the prefix and the prefix remains the same in the path Switch provides to the script, but the name is unchanged in the input folder so processing of the file from the post I send fails because the path is incorrect for the real filename path which was unchanged as requested. Is this a bug? Is there anyway to make Switch provide the correct path without the the unique job prefix and not have to do string manipulation?
freddyp
Advanced member
Posts: 1028
Joined: Thu Feb 09, 2012 3:53 pm

Re: Compose XML for HTTP POST using file in hot folder

Post by freddyp »

Switch always add a unique prefix to a job. If you need the name without the prefix there is job.getName(true/false) where the boolean value is if you want the job name with or without the extension.
teetomterrific
Member
Posts: 25
Joined: Mon Mar 09, 2020 10:22 pm

Re: Compose XML for HTTP POST using file in hot folder

Post by teetomterrific »

@ffeddyp you misunderstand my need. I need the input file that has the prefix added to NOT have the prefix added so that the filename is not modified. The filename begins with our internal job name and that must remain at the beginning of the name and the remainder of the name cannot be modified because it is a specific pattern that our automation needs to interpret correctly. I have tried changing the setting that says not to modify it, but that changes the path to be an internal path and not the file's real hot folder path so the path in the HTTP POST I send is wrong and the destination app cannot find the file. I have no problem getting the true filename using the command job.getNamePropper and getting the path with job.getPath. It is the modification to the true filename I need to not be modified and the path reported correctly when that option is selected OR some method that will remove the prefix before the script is run. This is some maddening BS that there is no obvious workaround like sting the unique ID in Private Data instead of physically renaming a file.
jan_suhr
Advanced member
Posts: 607
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Compose XML for HTTP POST using file in hot folder

Post by jan_suhr »

Can't you send the file to a folder on disc at the end of a connection, then the prefix is gone. Then you will have the correct path.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
teetomterrific
Member
Posts: 25
Joined: Mon Mar 09, 2020 10:22 pm

Re: Compose XML for HTTP POST using file in hot folder

Post by teetomterrific »

jan_suhr wrote: Mon May 06, 2024 9:09 pm Can't you send the file to a folder on disc at the end of a connection, then the prefix is gone. Then you will have the correct path.
The file comes in to a hot folder on a NAS, The script is the next action. The file never leaves the hot folder. It will be picked up by the POST destination server. It will never get to another folder. The script has to read where the file is and that must be on a network path, not an internal Switch folder. Moving to a different folder changes the path that the POST has already provided to the destination so that server will fail to pickup the file since it has moved.
jan_suhr
Advanced member
Posts: 607
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Compose XML for HTTP POST using file in hot folder

Post by jan_suhr »

But you can send a copy of the file to one folder at the end of the connection and another copy to do the rest the flow.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
teetomterrific
Member
Posts: 25
Joined: Mon Mar 09, 2020 10:22 pm

Re: Compose XML for HTTP POST using file in hot folder

Post by teetomterrific »

jan_suhr wrote: Mon May 06, 2024 11:12 pm But you can send a copy of the file to one folder at the end of the connection and another copy to do the rest the flow.
I fail to understand how that would work. Switch physically modifies the filename on the storage device adding the unique prefix. That alters the file path. How would making copies of the file change that when switch serves up that modified path when the script calls job.getPath(). This flow has just one action attached to the input hot folder which is the script. Adding copies means I have to mange/delete copies, which is stupid. I just need to disable the prefix and have Switch serve up the correct path and not some internal path location that happens when I disable the prefix and doesn't really exist. The Flow never does anything but run the script and the prefix is completely unnecessary as well as never used. I do not need to add unnecessary steps to a badly designed unique ID process that when disabled should actually be disabled instead of changing the path behavior to a bogus path when the file is still sitting in the freaking hot folder with the correct name.
jan_suhr
Advanced member
Posts: 607
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Compose XML for HTTP POST using file in hot folder

Post by jan_suhr »

The copy is sent to a folder that ends there on the disc. No connections out of the folder. Then Switch think it is done with that job and leave it with its original filename, no prefix.

Now you can use it with your script. The resto of the flow continue with its tasks.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
teetomterrific
Member
Posts: 25
Joined: Mon Mar 09, 2020 10:22 pm

Re: Compose XML for HTTP POST using file in hot folder

Post by teetomterrific »

jan_suhr wrote: Tue May 07, 2024 8:05 am The copy is sent to a folder that ends there on the disc. No connections out of the folder. Then Switch think it is done with that job and leave it with its original filename, no prefix.

Now you can use it with your script. The resto of the flow continue with its tasks.
This makes no sense to me. I would have to see an example that makes the ID go away because everything I try the path still has the stupid unique ID as part of the file name.
User avatar
magnussandstrom
Advanced member
Posts: 376
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Re: Compose XML for HTTP POST using file in hot folder

Post by magnussandstrom »

On the output folder there is a property called 'Strip unique name' set that to 'Yes'.
User avatar
magnussandstrom
Advanced member
Posts: 376
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Re: Compose XML for HTTP POST using file in hot folder

Post by magnussandstrom »

Why bother with a script when there is an out of the box solution?
freddyp wrote: Thu May 02, 2024 11:36 am 5: you can avoid the use of a script expression by using v20 of HTTP request and choosing "POST a body - Input job".
teetomterrific
Member
Posts: 25
Joined: Mon Mar 09, 2020 10:22 pm

Re: Compose XML for HTTP POST using file in hot folder

Post by teetomterrific »

magnussandstrom wrote: Tue May 07, 2024 2:53 pm Why bother with a script when there is an out of the box solution?
freddyp wrote: Thu May 02, 2024 11:36 am 5: you can avoid the use of a script expression by using v20 of HTTP request and choosing "POST a body - Input job".
The script does more than send the Post. It also determines which Server out of 5 the POST needs to be sent to and formats the server URL by using Regular Expressions to pull the last digit of the Job name to a select case for the server. It's not the actual POST I have issues with. It is not being able to disable the silly unique ID.

I have tried your suggestion to connect the input folder to an output folder and set the 'Strip unique name' to yes. However as soon as I connect that output folder to the script all the folder properties change and the Strip unique name' is no longer available as a property of the folder and it keeps the prefix. That inconsistency is maddening.
Post Reply