Skip to main content

Handling Modular Extend SDK API call responses

Last updated on January 30, 2025

Overview

You can use the AccelByte Gaming Services (AGS) Modular Extend SDK to extend AGS by calling its endpoints. The SDK is available in multiple programming languages.

This guide walks you through how to work with the API response object when you call any AGS endpoints using the Modular Extend SDK.

Go

This section outlines the setup steps for the Modular Extend SDK for Go.

Prerequisite

This SDK requires go 1.18 or a newer version.

Import SDK Project

To use the SDK, update your project's go.mod file. Replace:

require (
github.com/AccelByte/accelbyte-go-sdk {VERSION}
)

With:

require (
github.com/AccelByte/accelbyte-go-modular-sdk/{service}-sdk {VERSION}
)

Only import the services you need. Then, replace {VERSION} with your desired release version. Use the latest release version if you're starting a new project.

info

Environment Variables

Set the following environment variables when using ConfigRepository:

NameRequiredExample
AB_BASE_URLYeshttps://test.accelbyte.io
AB_CLIENT_IDYesabcdef0123456789abcdef0123456789
AB_CLIENT_SECRETYes, if using a confidential AB_CLIENT_IDab#c,d)ef(ab#c,d)ef(ab#c,d)ef(ab

Handling API call responses

Every operation in the Modular Extend SDK will return a response object. You can use this object to verify if the call was successful and to retrieve either the response data or the error object.

  • response.IsSuccess will be true if the call is successful. Otherwise, it will be false..
  • response.Data object is optional depending whether the endpoint has a response or not.
  • response.Error<status-code> contains error object if the call failed. Otherwise, it will be null.
  • response.Unpack will return all the responses given by the endpoint.
  • response.StatusCode will return the int status code responses given by the endpoint.

Known errors are available in errors.go in each module, e.g., <module-name>-sdk/pkg/<module-name>clientmodels/errors.go.

response, err := userProfileService.GetMyProfileInfoShort(input)
if response.Error400 != nil {
// Do something
} else {
ok := response.Data
// Do something
response.Unpack // Do something with the return value
}

Python

This section outlines the setup steps for the Modular Extend SDK for Python.

Prerequisite

This SDK requires Python 3.9 or newer.

Install with Pip

  1. Install the core package:

    pip install accelbyte-py-sdk-core
  2. Install the services you need:

    pip install accelbyte-py-sdk-service-achievement
    pip install accelbyte-py-sdk-service-ams
    pip install accelbyte-py-sdk-service-basic
    pip install accelbyte-py-sdk-service-cloudsave
    pip install accelbyte-py-sdk-service-dslogmanager
    pip install accelbyte-py-sdk-service-dsmc
    pip install accelbyte-py-sdk-service-gametelemetry
    pip install accelbyte-py-sdk-service-gdpr
    pip install accelbyte-py-sdk-service-iam
    pip install accelbyte-py-sdk-service-leaderboard
    pip install accelbyte-py-sdk-service-legal
    pip install accelbyte-py-sdk-service-lobby
    pip install accelbyte-py-sdk-service-match2
    pip install accelbyte-py-sdk-service-matchmaking
    pip install accelbyte-py-sdk-service-platform
    pip install accelbyte-py-sdk-service-qosm
    pip install accelbyte-py-sdk-service-reporting
    pip install accelbyte-py-sdk-service-seasonpass
    pip install accelbyte-py-sdk-service-session
    pip install accelbyte-py-sdk-service-sessionbrowser
    pip install accelbyte-py-sdk-service-social
    pip install accelbyte-py-sdk-service-ugc
  3. If needed, install additional features:

    pip install accelbyte-py-sdk-feat-auth
    pip install accelbyte-py-sdk-feat-token-validation

    Or install all features.

    pip install accelbyte-py-sdk-all

Environment Variables

Set the following environment variables when using EnvironmentConfigRepository (default):

NameRequiredExample
AB_BASE_URLYeshttps://test.accelbyte.io
AB_CLIENT_IDYesabcdef0123456789abcdef0123456789
AB_CLIENT_SECRETYes, if using a private AB_CLIENT_IDab#c,d)ef(ab#c,d)ef(ab#c,d)ef(ab
AB_NAMESPACEYes, the SDK will automatically fill up the {namespace} path parameter (overridable)accelbyte
AB_APP_NAMENo, the SDK will automatically fill up the User-Agent header (overridable)MyApp
AB_APP_VERSIONNo, the SDK will automatically fill up the User-Agent header (overridable)1.0.0

Handling API call responses

All operations and their wrapper functions now return an instance of subclass ApiResponse specific to the operation.

from accelbyte_py_sdk.api.iam import public_create_user_v3


def main():
# The wrapper 'public_create_user_v3' wraps around
# the `PublicCreateUserV3` operation which returns
# an instance of `PublicCreateUserV3.Response` which is a
# subclass of `ApiResponse`.
#
# The class `PublicCreateUserV3.Response` also implements the
# '__iter__' dunder method that allows it to be unpacked into
# `result, error` maintaining the previous syntax.
#
# class PublicCreateUserV3(Operation):
# class Response(ApiResponse):
# def __iter__(self):
# yield data
# yield error
response = public_create_user_v3(...)
result, error = response
if error:
exit(1)


if __name__ == "__main__":
main()

You can also use the ok() method in the ApiResponse object to raise an Exception if the response is not successful.

from accelbyte_py_sdk.api.iam import public_create_user_v3


def main():
response = public_create_user_v3(...).ok()
# or
# result, error = public_create_user_v3(...).ok()

if __name__ == "__main__":
main()

You can also compare the error from the ApiResponse object against known errors in the service.

from accelbyte_py_sdk.api.iam import public_create_user_v3
from accelbyte_py_sdk.api.iam.errors import ERROR_10153, ERROR_10154 # known errors for the IAM service


def main():
response = public_create_user_v3(...)
if response.error:
# Get error code
error_code = response.error.code

# Get error message
error_message = response.error.message

# handle errors depending on the code
# - ERROR_10153 = ApiError(code="10153", message="user exist")
# - ERROR_10154 = ApiError(code="10154", message="country not found")
if response.error.code == ERROR_10153.code:
do_something()
elif response.error.code == ERROR_10154.code:
do_something_else()

# Raise an exception
raise response.error.to_exception()


if __name__ == "__main__":
main()

Java

This section outlines the setup steps for the Modular Extend SDK for Java.

Prerequisite

This SDK is developed using JDK 8 and Gradle 7.5.

Gradle configuration

Add the following to your gradle.build file. Replace {VERSION} with the release version tag from releases without the leading v character.

repositories {
mavenCentral()
}

dependencies {
...
implementation 'net.accelbyte.sdk:module-iam:{VERSION}'
}
note

module-iam is the minimum dependency needed use AGS. It is an SDK that wraps the AGS IAM service. For more information, refer to the Samples folder on GitHub.

Environment variables

Set the following environment variables when using DefaultConfigRepository:

NameRequiredExample
AB_BASE_URLYeshttps://test.accelbyte.io
AB_CLIENT_IDYesabcdef0123456789abcdef0123456789
AB_CLIENT_SECRETYes, if using a confidential AB_CLIENT_ID.ab#c,d)ef(ab#c,d)ef(ab#c,d)ef(ab

Handling API call responses

Every operation in the Modular Extend SDK for Java will return a response object. You can use this object to verify if the call was successful and to retrieve either the response data or the error object.

  • isSuccess() getter method will be true if the call is successful. Otherwise, it will be false.
  • getData() getter method contains response data from service. This property is optional depending whether the endpoint has a response or not.
  • getError() getter method contains error object if the call failed. Otherwise, it will be null.

Known errors are available in <ServiceName>Errors static class, e.g., BasicErrors, IamErrors, and so on.

UserProfile userProfile = new UserProfile(sdk);

GetMyProfileInfoOpResponse response = userProfile.getMyProfileInfo(new GetMyProfileInfo("accelbyte"));

if (response.isSuccess())
{
// Do something with response data
}
else
{
// Do something with response error object

// Get error code
String errorCode = response.getError().getCode();

// Get error message
String errorMessage = response.getError().getMessage();

// Or throw an exception
response.getError().throwException();

// Compare to known error to handle more specific error
if (response.getError().isEqualWith(BasicErrors.error11440))
{
// Do something if user profile is not found
}
}

C#

This section outlines the setup steps for the Modular Extend SDK for C#.

Prerequisite

This SDK requires the .NET 8.0 SDK.

Install required packages

# Always include these package to use AccelByte .NET SDK
$ dotnet add package AccelByte.Sdk.Abstractions
$ dotnet add package AccelByte.Sdk.Core

# Include this package to do authentication to AGS or token validation
$ dotnet add package AccelByte.Sdk.Authentication

# Optional feature packages
$ dotnet add package AccelByte.Sdk.Feature.AutoRefreshToken
$ dotnet add package AccelByte.Sdk.Feature.LocalTokenValidation

# API packages. You can include only one or more packages depending on your need.
$ dotnet add package AccelByte.Sdk.Api.<ApiName>

# Compatibility layer. Use this package to enable compatibility layer with monolithic SDK version.
$ dotnet add package AccelByte.Sdk.Api.Compat

View the full list of API packages on GitHub.

Environment variables

The following environment variables need to be set when using DefaultConfigRepository.

NameRequiredExample
AB_BASE_URLYeshttps://test.accelbyte.io
AB_CLIENT_IDYesabcdef0123456789abcdef0123456789
AB_CLIENT_SECRETYes, if using a private AB_CLIENT_IDab#c,d)ef(ab#c,d)ef(ab#c,d)ef(ab
AB_NAMESPACEYesaccelbyte

Handling API call response

Every operation in the Modular Extend SDK will return a response object. You can use this object to verify if the call was successful and to retrieve either the response data or the error object.

  • IsSuccess property will be true if the call is successful. Otherwise, it will be false..
  • Data property contains response data from service. This property is optional depending whether the endpoint has a response or not.
  • Error property contains error object if the call failed. Otherwise, it will be null.

Known errors are available in <ServiceName>Errors static class, e.g., BasicErrors, IamErrors, and so on.

var response = sdk.GetBasicApi().UserProfile.GetMyProfileInfoOp.Execute(sdk.Namespace);
if (response.IsSuccess)
{
// Do something with response.Data
}
else
{
// Do something with response.Error

// Get error code
string errorCode = response.Error.Code;

// Get error message
string errorMessage = response.Error.Message;

// Or throw an exception
response.Error.ThrowException();

// Compare to known error to handle more specific error
if (response.Error == BasicErrors.Error11440)
{
// Do something if user profile is not found
}
}

Use EnsureSuccess() method as a shorthand to do default error and null checking in the response object. This method will return response data directly if the endpoint has a response.

UserProfilePrivateInfo profileData = sdk.GetBasicApi().UserProfile.GetMyProfileInfoOp
.Execute(sdk.Namespace)
.EnsureSuccess();