function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Umur Ak 10Umur Ak 10 

REST API Sandbox problem

Hello everyone, I am new to salesforce and barely know half of it's cool features!

I am having this strange problem with my company's sandbox org.

I ran through the basic REST-API example code in JAVA, simple OAuth and everything, just to see if I am able to connect to the sandbox using the REST API.

It appears to be that the login failed and showed me the error code 400. 

However, on my personal org, that I can set up after signgin up with an developer-account, the same code appears to work JUST fine. I get no error messages at all, I can even run some basic queries on that.

NOTE: I have configured the JAVA-Code for the REST-API example to the sandbox environment, it's basically like this:
* Login credentials have been replaced with ' * '.
public class sbRest {

    private static final String USERNAME     = "************";
    private static final String PASSWORD     = "************";
    private static final String LOGINURL     = "https://test.salesforce.com";
    private static final String GRANTSERVICE = "/services/oauth2/token?grant_type=password";
    private static final String CLIENTID     = "*********************";
    private static final String CLIENTSECRET = "*****************";
    
    
    public static void main(String[]args) throws UnsupportedEncodingException {

        HttpClient httpclient = HttpClientBuilder.create().build();
 
        // Assemble the login request URL
        String loginURL = LOGINURL +
                          GRANTSERVICE +
                          "&client_id=" + CLIENTID +
                          "&client_secret=" + CLIENTSECRET +
                          "&username=" + USERNAME +
                          "&password=" + PASSWORD;
 
        // Login requests must be POSTs
        HttpPost httpPost = new HttpPost(loginURL);
        HttpResponse response = null;
 
        try {
            // Execute the login POST request
            response = httpclient.execute(httpPost);
        } catch (ClientProtocolException cpException) {
            cpException.printStackTrace();
        } catch (IOException ioException) {
            ioException.printStackTrace();
        }
 
        // verify response is HTTP OK
        final int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            System.out.println("Error authenticating to Force.com: "+statusCode);
            // Error is in EntityUtils.toString(response.getEntity())
            return;
        }
 
        String getResult = null;
        try {
            getResult = EntityUtils.toString(response.getEntity());
        } catch (IOException ioException) {
            ioException.printStackTrace();
        }
        JSONObject jsonObject = null;
        String loginAccessToken = null;
        String loginInstanceUrl = null;
        try {
            jsonObject = (JSONObject) new JSONTokener(getResult).nextValue();
            loginAccessToken = jsonObject.getString("access_token");
            loginInstanceUrl = jsonObject.getString("instance_url");
        } catch (JSONException jsonException) {
            jsonException.printStackTrace();
        }
        System.out.println(response.getStatusLine());
        System.out.println("Successful login");
        System.out.println("  instance URL: "+loginInstanceUrl);
        System.out.println("  access token/session ID: "+loginAccessToken);
 
        // release connection
        httpPost.releaseConnection();    
    } 
}

Is there any additional configuration I need to make, or any changes on the "network access" on the sandbox platform? I really don't know what could be causing this issue, as for my own personal org, it works just fine, using the exact same code.

I would appreciate any help!

Thank you.