I am trying to run the a simple Smartsheet API test program to list sheets using the Smartsheet API SDK for java. Below is my code. I am copying and pasting my token after creating a token from my Smartsheet account. I am always getting the following error: Thanks in advance for any help.
java -ea -jar build/jar/test_applications/Test.jar
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
com.smartsheet.api.AuthorizationException: Your Access Token is invalid.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.smartsheet.api.internal.AbstractResources$ErrorCode.getException(AbstractResources.java:148)
at com.smartsheet.api.internal.AbstractResources.handleError(AbstractResources.java:895)
at com.smartsheet.api.internal.AbstractResources.listResourcesWithWrapper(AbstractResources.java:503)
at com.smartsheet.api.internal.SheetResourcesImpl.listSheets(SheetResourcesImpl.java:178)
at Test.main(Test.java:29)
// Library includes.
import com.smartsheet.api.*;
import com.smartsheet.api.models.*;
import com.smartsheet.api.models.enums.*;
import java.util.*;
// Class definition.
public class Test
{
public static void main(String[] args)
{
try
{
Smartsheet smartsheet = SmartsheetFactory.createDefaultClient("mytoken");
PagedResult<Sheet> sheets = smartsheet.sheetResources().listSheets(null, null, null);
System.out.println("\nFound " + sheets.getTotalCount() + " sheets\n");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
This error will occur if you're using the API with a Smartsheet EU account or a Smartsheet GOV account and haven't correctly set the base URI within the SDK config file(s).
If you're using the Smartsheet API with a Smartsheet EU account or a Smartsheet GOV account, then you'll need to modify the base URI in the SDK's config file(s) to point to api.smartsheet.eu
or api.smartsheetgov.com
.
Base URI for Smartsheet EU: https://api.smartsheet.eu/2.0
Base URI for Smartsheet GOV: https://api.smartsheetgov.com/2.0
In the API docs, this is mentioned here:
Smartsheet EU: https://smartsheet.redoc.ly/#section/Smartsheet-Regions-Europe
Smartsheet GOV: https://smartsheet.redoc.ly/#section/Smartsheet-Gov
There are instructions specific to each SDK on how to modify the base URI in the config file(s). For the Smartsheet Java SDK, this information can be found here: