I am trying to upload .apk / .ipa file to browserstack cloud programmatically (instead of running the curl command)
Option 1: Node-fetch api
const myfetch = require('node-fetch');
const buildToPost = {
file: '</my path>'
};
const options = {
method: 'POST',
body: JSON.stringify(buildToPost)
};
myfetch('https://</myusername>:</mykey>@api.browserstack.com/app-automate/upload', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(error => console.error('Error:', error));
But its giving following error:
{ error: 'Invalid format. Refer to REST API document for valid API format - https://www.browserstack.com/app-automate/rest-api' }
Option 2: Axios API
const axios = require('axios');
axios.post('https://</myusername>:</mykey>@api-cloud.browserstack.com/app-automate/upload', {
File: '</my path>'
})
.then
((response) => {
console.log(response);
}).catch((error) => {
console.log((error));
})
Error: data:
{ error: 'Invalid format. Refer to REST API document for valid API format - https://www.browserstack.com/app-automate/rest-api' } } }
Curl command reference:
curl -u "</myusername>:</mykey>" -X POST https://api-cloud.browserstack.com/app-automate/upload -F "file=@/path/to/app/file/Application-debug.apk" -F 'data={"custom_id": "MyApp"}'