gruista Posted October 22, 2012 Posted October 22, 2012 Im tryin to post from Filemaker to Ebay my listing products I Read I need a pluging as scriptmaster to post to http, to connect with Ebay file exchange Anyone knows how I must do it? Someone has a idea? Ive fm5.5 but I can get fm7 or 10 thanks
Tim Anderson Posted October 23, 2012 Posted October 23, 2012 I have done this for a client. Quite a complex process and not for a novice, there are many potential areas that could catch you out. How many items are you going to be uploading and how often?
fseipel Posted October 23, 2012 Posted October 23, 2012 This is pretty much trivial, at least using the 360Works ScriptMaster plugin. I implemented this a couple months ago, could definitely use clean-up, it simply follows http://forums.ebay.com/db2/topic/File-Exchange/Can-Someone-Please/2000170031 Input variables/parameters, e.g. filename_to_upload = e.g. C:\Users\Frank\Documents\single_item.csv my_token=your token from eBay -- get it here http://pages.ebay.com/sellerinformation/sellingresources/fileexchange_programmaticupload.html ---------------------------------------------------------- /** * This is a sample *fully functional* commandline test program for uploading files * in Sandbox or Production environments. * * the usage for production: * java FEClient prod c:\path\to\file\test.csv token_string_for_prod * * the usage for sandbox: * java FEClient sbx c:\path\to\file\test.csv token_string_for_sandbox * */ import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import java.security.Security; import javax.net.ssl.HttpsURLConnection; String UPLOAD_URL_SANDBOX = "https://bulksell.sandbox.ebay.com/ws/eBayISAPI.dll?FileExchangeUpload"; String UPLOAD_URL_PRODUCTION = "https://bulksell.ebay.com/ws/eBayISAPI.dll?FileExchangeUpload"; String UPLOAD_URL_QA = "http://bulksell.qa.ebay.com/ws/eBayISAPI.dll?FileExchangeUpload"; String UPLOAD_URL_DEV = "http://localhost:8080/ws/eBayISAPI.dll?FileExchangeUpload"; /** This method reads in a specified file from the system and * returns its contents as a string * @param filename - complete path to file including name * @return String representing file's contents */ protected String readFile(String filename) { StringBuffer data = new StringBuffer(""); try { File file = new File(filename); FileReader fr = new FileReader(file); BufferedReader in2 = new BufferedReader(fr); int c; while ((c = in2.read()) != -1) { data.append((char) c); } } catch (Exception e) { e.printStackTrace(); } return data.toString(); } /** This method uploads the data content passed in to the url passed * and passes the token provided as a form parameter. * @param url - url to post to * @param token - seller's token * @param data - content of file * @return - string status that is parsed from html response */ protected String uploadFile(String url, String token, String data) { /** *String constant for multipart upload form content boundary */ final String CONTENT_BOUNDARY = "-----------------------------BcLtEsToOlBoUnDaRy"; /** *String constant for production environment */ String ENV_PRODUCTION = "prod"; /** *String constant for sandbox environment */ String ENV_SANDBOX = "sbx"; /** *String constant for qa environment */ String ENV_QA = "qa"; /** *String constant for dev environment */ String ENV_DEV = "dev"; // stores response from upload post StringBuffer response = new StringBuffer(""); OutputStream os = null; BufferedReader in2 = null; HttpURLConnection conn = null; try { System.out.println("DEBUG: Connecting to: " + url); URL serverURL = new URL(url); // connect to server URLConnection uc = serverURL.openConnection(); conn = (HttpURLConnection) uc; conn.setAllowUserInteraction(true); //conn.setFollowRedirects(true); conn.setInstanceFollowRedirects(true); // set connection as POST conn.setRequestMethod("POST"); conn.setDoOutput(true); // turns it into a post // setup headers conn.setRequestProperty( "Content-Type", "multipart/form-data; boundary=" + CONTENT_BOUNDARY); conn.setRequestProperty( "User-Agent", "BCLUpload Test Tool/1.0 [en] (Java; U)"); conn.setRequestProperty("Accept-Language", "en-us"); conn.setRequestProperty("Accept-Encoding", "gzip, deflate"); conn.setRequestProperty( "Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, application/pdf, application/x-comet, */*"); conn.setRequestProperty("CACHE-CONTROL", "no-cache"); // get reference to stream to post to os = conn.getOutputStream(); // constructing data //System.out.println("DEBUG: file read in was:" + data.toString()); String request = "--" + CONTENT_BOUNDARY + "\r\n" + "Content-Disposition: form-data; name=\"token\"\r\n\r\n"; request = request + token+ "\r\n"+ "--"+ CONTENT_BOUNDARY+ "\r\n"; request = request + "Content-Disposition: form-data; name=\"file\"; filename=\"data.csv\"" + "\r\nContent-Type: text/plain\r\n\r\n"; request = request + data+ "\r\n"+ "--"+ CONTENT_BOUNDARY+ "\r\n"; os.flush(); // performing post os.write(request.getBytes(), 0, request.getBytes().length); os.flush(); // getting reference to response stream in2 = new BufferedReader(new InputStreamReader(conn.getInputStream())); String inputLine; // reading respone while ((inputLine = in2.readLine()) != null) { response.append(inputLine); } // closing connections in2.close(); in2 = null; os.close(); os = null; conn.disconnect(); conn = null; } catch (Exception e) { e.printStackTrace(); } finally { if (in2 != null) try { in2.close(); } catch (Exception e) { // ok to ignore this } if (os != null) try { os.close(); } catch (Exception e) { // ok to ignore this } if (conn != null) try { conn.disconnect(); } catch (Exception e) { return e; } } // parse and return response return this.getStatusTextFromResponse(response.toString()); } /** This method parses the message text from the HTML response. * @param response - raw html response * @return String representing message text in HTML response */ protected String getStatusTextFromResponse(String response) { /** *String constant that represents the HTML response's message start */ String RESPONSE_STRING_START = ""; /** *String constant represents the end of the HTML response message end */ String RESPONSE_STRING_END = "."; if (response == null || "".equals(response)) { return response; } String status; // get the index of the start of the message int start = response.toString().indexOf(RESPONSE_STRING_START) + RESPONSE_STRING_START.length(); // get the end of the message location int end = response.toString().indexOf(RESPONSE_STRING_END, start); // set status to substring btw start and end status = response; //status = response.substring(start, end); return status; } /** This method sets up the vars needed for uploading * @param args - args passed to the main program * @return status returned from upload */ protected void downloadFile(String urlToRead, String fileToWrite) { OutputStream os = null; BufferedReader in2 = null; HttpsURLConnection conn = null; try { System.out.println("DEBUG: Connecting to:" + urlToRead); URL serverURL = new URL(urlToRead); conn = (HttpsURLConnection) serverURL.openConnection(); BufferedInputStream is = new BufferedInputStream(conn.getInputStream()); in2 = new BufferedReader(new InputStreamReader(conn.getInputStream())); File file = new File(fileToWrite); os = new FileOutputStream(file); String inputLine; while ((inputLine = in2.readLine()) != null) { os.write(inputLine.getBytes()); } System.out.println("file created:" + fileToWrite); in2.close(); in2 = null; os.close(); os = null; conn.disconnect(); conn = null; } catch (Exception e) { e.printStackTrace(); } finally { if (in2 != null) try { in2.close(); } catch (Exception e) { // ok to ignore this } if (os != null) try { os.close(); } catch (Exception e) { // ok to ignore this } if (conn != null) try { conn.disconnect(); } catch (Exception e) { // ok to ignore this } } } try { // check arg length String status; String env = 'prod'; // For Production Environment //String filepath = 'C:/Users/Frank/Documents/empty2.csv'; String filepath = filename_to_upload; String token = my_token; // // if you are copying & pasting the token by using the API's then the token // will NOT be URL encoded. Uncomment this line if the token was obtained through the FE // web page //token = URLEncoder.encode(token); String uploadURL = null; // set production url uploadURL ="https://bulksell.ebay.com/ws/eBayISAPI.dll?FileExchangeUpload"; // get data from file involved String data = readFile(filepath); // upload file status = this.uploadFile(uploadURL, token, data); return status; } catch (Exception e) { return e; }
john renfrew Posted October 23, 2012 Posted October 23, 2012 It could indeed be tidied up considerably, making it more Groovy in the process. Taking out the unused parts will help others understand it too.
Recommended Posts
This topic is 4482 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now