I am using powershell to automate the upload and submission of my app.
i can upload the file and I get a file key in response but when I go to update and add the binary to my app I get the following error:
Invoke-RestMethod : {“from”:“seller”,“body”:{“ctntId”:null,“contentStatus”:null,“httpStatus”:“BAD_REQUEST”,“errorCode”:“4128”,“errorMsg”:“You must have an app in service that is already registered on the Seller Portal. The Developer API does not support
new app registration.”},“message”:“Request failed with status code 400”}
I already have an app that is registered and is for sale on the store.
This is my powershell script, can you please advise how I can resolve this?
Import function
Import-Module ./Generate-JWT.psm1
if (-not (Test-Path function:\Generate-JWT)) {
throw "Failed to import function."
}
Write-Host “Function imported successfully, Obtaining access token…”
Use function to generate JSON Web Token
$jwt = Generate-JWT -Algorithm “RS256” -Issuer $ServiceID -ValidforSeconds 1199 -privateKeyXml $privateKeyXml
$authHeader = @{
“Content-Type” = “application/json”
“Authorization” = “Bearer $jwt”
}
$accessTokenResponse = Invoke-RestMethod -Uri $AuthUrl -Method Post -Headers $authHeader
$accessToken = $accessTokenResponse.createdItem.AccessToken
if ($accessTokenResponse.ok -ne “True”) {
throw “Failed to retrieve access token”
}
Write-Host “Access Token Obtained, Retrieving session ID…”
$sessionHeader = @{
“Content-Type” = “Application/json”
“service-account-id” = $ServiceID
“Authorization” = “Bearer $accessToken”
}
$sessionIDResponse = Invoke-RestMethod -Uri $SessionIdUrl -Method Post -Headers $sessionHeader
$sessionID = $sessionIDResponse.sessionID
if ($sessionID -eq $null) {
throw “Failed to obtain session ID”
}
Write-Host “Session ID has been obtained, Uploading File…”
Read file content
$fileContent = [System.IO.File]::ReadAllBytes($ApkPath)
$boundary = [System.Guid]::NewGuid().ToString()
$LF = “r
n”
Construct body lines
$uploadBody = @()
$uploadBody += “–$boundary”
$uploadBody += “Content-Disposition: form-data; name="sessionId
”"
$uploadBody += “”
$uploadBody += $SessionID
$uploadBody += “–$boundary”
$uploadBody += “Content-Disposition: form-data; name="file
”; filename="$(Split-Path -Leaf $ApkPath)
“”
$uploadBody += “Content-Type: multipart/form-data”
$uploadBody += “”
$uploadBody += [System.IO.File]::ReadAllText($ApkPath)
$uploadBody += “–$boundary–”
Join body lines
$body = $uploadBody -join $LF
Convert body to bytes
$uploadBodyBytes = [System.Text.Encoding]::UTF8.GetBytes($body)
Set headers
$uploadHeaders = @{
“Content-Type” = “multipart/form-data; boundary=$boundary”
“service-account-id” = $ServiceID
“Authorization” = “Bearer $accessToken”
}
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }
Send the POST request
$uploadResponse = Invoke-RestMethod -Uri $UploadUrl -Method Post -Headers $uploadHeaders -Body $uploadBodyBytes
if ($uploadResponse.filekey -eq $null) {
throw “Failed to obtain file key”
}
Write-Host “File has successfully uploaded, Attempting to register the app”
$binaryList = @(
@{
fileName = “app-prod-release.apk”
binarySeq = “1”
versionCode = $null
versionName = $null
packageName = “com.entersekt.authapp.parmenion”
nativePlatforms = $null
apiminSdkVersion = “1”
apimaxSdkVersion = $null
iapSdk = “N”
gms = “Y”
filekey = $null
},
@{
gms = “Y”
filekey = $uploadResponse.filekey
}
)
$updateBody = @{
ContentId = $ContentId
AppTitle = $AppTitle
DefaultLanguageCode = $DefaultLanguageCode
paid = “N”
binaryList = $binaryList
} | ConvertTo-Json
$updateHeaders = @{
“Authorization” = “Bearer $accessToken”
“service-account-id” = $ServiceID
“Content-Type” = “application/json”
}
$UpdateResponse = Invoke-RestMethod -Uri $UpdateUrl -Method Post -Headers $updateHeaders -Body $updateBody