# Upload Application API Endpoints and Route Errors

#### Application Upload Functionality

Adding a new app. If the Application GUID is provided, then add the build ID to that particular app.

#### Application Upload Route

```rust
curl --location 'https://base-url/parser-microservice/build-upload?userFriendlyBuildName=Oct-release' \
--header 'x-sofy-auth-key: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX' \
--form 'applicationFile=@"/C:/Users/User/Downloads/my-app-362-0-0-3-67.apk"' \
--form 'ApplicationGUID=""' \
--form 'CertificateName=""'
```

##### Helpful tips

- Replace the provided authentication key, app file, application GUID, and certificate name values with the actual values.
- Replace the "base-url" with "public.sofy.ai"
- You can also provide an optional query param “`userFriendlyBuildName`“ to specify specify the branch or build friendly name.
- The parameter "CertificateName="CERTIFICATE\_NAME"" is an optional field that can be included if you are uploading an enterprise build.
- If you want to upload a file and link it to an existing app in Sofy, you can find and copy the existing app’s GUID by following the steps under [Finding and Copying an App’s GUID](https://docs.sofy.ai/using-ap-is-for-testing/upload-apk-ipa-using-apis#finding_and_copying_an_app_s_guid).

##### Response:

Once the build is uploaded, the API response will include the hash code of the build number as shown below:

```json
{
    "data": {
        "appHash": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    },
    "message": "Application Upload Successful."
}
```

The above App Hash can be used to trigger a scheduled execution of your test in Sofy for the uploaded build. Visit [Scheduled Run Status API Endpoints](https://docs.sofy.ai/schedule-runs/scheduled-run-status-endpoints-migration) to learn more about how to trigger schedule execution through APIs.

##### Error Response:

```json
{
    "error": {
        "message": "Error message.",
        "details": "Error details.",
        "timestamp": "2023-10-23T09:23:51.845Z"
    }
}
```

##### Finding and Copying an App’s GUID

1. Log in to your Sofy account.
2. Select **App Manager** from the left navigation bar.
3. Choose an app from the left panel.
4. Under the **General** tab, click **Copy GUID** at far right of the **Application GUID** field.
5. Insert the copied app GUID in the “ApplicationGUID” parameter of your API.

#### Application Upload Route Errors

##### **Subscription Errors**

1. **Error Message**: Your subscription plan has expired and requires renewal.
   - **Status Code**: 400
   - **Reason**: The user's subscription is expired.
   - **Resolution**: To renew the subscription, [submit a ticket to Sofy support](https://support.sofy.ai/support/tickets/new.).
2. **Error Message**: Your subscription plan does not support the uploaded application build type.
   - **Status Code**: 400
   - **Reason**: The user's subscription plan does not allow the uploaded build type.
   - **Resolution**: You can either upload the file type specified in your subscription or modify your subscription by [submitting a ticket to Sofy support](https://support.sofy.ai/support/tickets/new.).
3. **Error Message**: You have reached the maximum number of allowed applications for this subscription.
   - **Status Code**: 400
   - **Reason**: The user has exceeded the application upload limit.
   - **Resolution**: To extend the app upload limit, [submit a ticket to Sofy support](https://support.sofy.ai/support/tickets/new.).

##### **Application or Build Errors**

1. **Error Message**: Build already exists.
   - **Status Code**: 400
   - **Reason**: Attempting to upload a build that already exists.
   - **Resolution**: Check and ensure that the build is not duplicated.
2. **Error Message**: **\*** Cannot insert a new application.
   - **Status Code**: 500
   - **Reason**: Error while adding data to the application table.
   - **Resolution**: Investigate and fix the issue with adding application data.
3. **Error Message**: No active release found for this application. Please create a release to upload a build.
   - **Status Code**: 400/500
   - **Reason**: There is no active release for the application.
   - **Resolution**: Create a release from the portal to upload a build.
4. **Error Message**: **\*** Invalid platform type.
   - **Status Code**: 500
   - **Reason**: The platform extracted by the parser service from the app does not match iOS or Android.
   - **Resolution**: Ensure that the correct platform type is used.
5. **Error Message**: No application exists against this applicationGUID.
   - **Status Code**: 400
   - **Reason**: Either the application GUID provided to link the build is wrong or the application is deleted.
   - **Resolution**: Verify the application GUID and its status.
6. **Error Message**: Build upload failed. Please ensure you are uploading the correct build for your app platform (iOS or Android).
   - **Status Code**: 400
   - **Reason**: User is trying to upload an iOS build on an Android application or vice versa.
   - **Resolution**: Upload the build that matches your app platform.
7. **Error Message**: **\*** Unable to insert a new application package.
   - **Status Code**: 500
   - **Reason**: Error while adding data to the applicationPackage table.
   - **Resolution**: Investigate and resolve the issue with adding application package data.

##### **Parser Errors**

1. **Error Message**: The uploaded application build contains corrupt or incomplete data. Please make sure you have a valid application file and upload again.
   - **Status Code**: 500
   - **Reason**: The uploaded build is corrupt.
   - **Resolution**: Ensure you have a valid and complete application file and upload again.
2. **Error Message**: The application’s manifest file could not be found. Please make sure you have a valid application file and upload again.
   - **Status Code**: 500
   - **Reason**: The manifest file is missing in the uploaded build.
   - **Resolution**: Ensure the manifest file is included in the build.
3. **Error Message**: The uploaded application build is missing version information. Please use a valid IPA file and try again.
   - **Status Code**: 500
   - **Reason**: The uploaded IPA build is missing important version information.
   - **Resolution**: Provide a valid IPA build with version information.
4. **Error Message**: Files with extensions other than APK or IPA are not supported. Reupload the file with either an "apk" or an "ipa" extension.
   - **Status Code**: 500
   - **Reason**: The file uploaded is neither an APK nor an IPA.
   - **Resolution**: Reupload the file with either an "apk" or an "ipa" extension.
5. **Error Message**: The uploaded application build does not contain the required info.plist file. Make sure it is a valid application file.
   - **Status Code**: 500
   - **Reason**: The build is missing the "info.plist" file.
   - **Resolution**: Include the required "info.plist" file in the build.
6. **Error Message**: Please select an APK or an IPA file first.
   - **Status Code**: 500
   - **Reason**: No file is uploaded.
   - **Resolution**: Upload either an APK or an IPA file.

##### **Gateway Errors**

1. **Error Message**: Missing required headers.
   - **Status Code**: 400
   - **Reason**: The "x-sofy-auth-key" header is missing from the request.
   - **Resolution**: Ensure the required headers are included.
2. **Error Message**: No user found.
   - **Status Code**: 401
   - **Reason**: Subscription is expired or the provided auth key is not valid.
   - **Resolution**: Renew the subscription or verify the auth key.
3. **Error Message**: Internal Server Error.
   - **Status Code**: 500
   - **Reason**: Multiple reasons can cause this, including invalid auth key format or other unexpected failures.
   - **Resolution**: Investigate the specific issue leading to the internal server error.
