Error when trying to set token for platformClient Java SDK

Hello, I’m trying to use the catalog methods to list some products and before calling them, I am trying to set a token for platformConfig with this code block

platformConfig = new PlatformConfig(
     "companyId",
     "apiKey",
     "apiSecret"
);
AccessTokenDto token = platformConfig.getPlatformOauthClient().getAccessTokenObj("client_credentials");
platformConfig.getPlatformOauthClient().setToken(token);

But in the getToken method I get this error
[size=98 text={"error":"unauthorized_client","error_description":"Unauthorized…]
Please help me on how to get and set the token before using catalog methods.

@Caglar_Ersin try passing your “domain” in the platformConfig.

I do not pass any domain so it uses “https://api.fynd.com

Which “domain” do you mean? If extension url, it does not work as well.

You can call the platformClient method using the extension’s API key and API secret within the extension. That’s why it is giving the error ‘unauthorized client’.

You can create clients in the developer section of that company’s ID. You can pass the clientID as the API key and the client secret as the API secret in the platformConfig constructor. Then, you can call the platformClient SDK method directly.

1 Like

I have created a client and i get this error trying to get the access token [size=99 text={"error":"unauthorized_client","error_description":"Unauthorized…]
here is my implementation

platformConfig = new PlatformConfig(
        "companyId",
        "clientId",
        "clientSecret"
);
AccessTokenDto token = platformConfig.getPlatformOauthClient().getAccessTokenObj("client_credentials");
platformConfig.getPlatformOauthClient().setToken(token);
if(Objects.nonNull(platformConfig)) {
    PlatformClient platformClient = new PlatformClient(platformConfig);

    // API's with application_id
    Object response = platformClient.application("application_id_for_sales_channel").catalog.getAppProducts(
            null, null,null, null, null, 1, 10, ""
    );
    return response;}

ah I see, I created the client within the account and that worked, previously I created the client within the organization. thanks for helping!!