How to upload App on LambdaTest through Code?

How to upload App on LambdaTest through Code?

Hi Darran,

You can use the following code snippet to upload App on LambdaTest:

public static void upload() throws IOException {

        String credential = Credentials.basic(userName, accessKey);

        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        MediaType mediaType = MediaType.parse("text/plain");
        RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
                .addFormDataPart("appFile","Location_of_APK_OR_IPA_file",
                        RequestBody.create(MediaType.parse("application/octet-stream"),
                                new File("apps/sample.apk")))
                .build();
        Request request = new Request.Builder()
                .url("https://manual-api.lambdatest.com/app/upload/realDevice")
                .method("POST", body)
                .addHeader("Authorization", credential)
                .build();
        Response response = client.newCall(request).execute();
        System.out.println(response.body().string());
    }