Stay organized with collections
Save and categorize content based on your preferences.
Merchant API code sample to get a LFP merchant state.
Java
// Copyright 2025 Google LLC// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at//// https://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.packageshopping.merchant.samples.lfp.v1;importcom.google.api.gax.core.FixedCredentialsProvider;importcom.google.auth.oauth2.GoogleCredentials;importcom.google.shopping.merchant.lfp.v1.GetLfpMerchantStateRequest;importcom.google.shopping.merchant.lfp.v1.LfpMerchantState;importcom.google.shopping.merchant.lfp.v1.LfpMerchantStateName;importcom.google.shopping.merchant.lfp.v1.LfpMerchantStateServiceClient;importcom.google.shopping.merchant.lfp.v1.LfpMerchantStateServiceSettings;importshopping.merchant.samples.utils.Authenticator;importshopping.merchant.samples.utils.Config;/** This class demonstrates how to get the LFP state for a given Merchant Center account */publicclassGetLfpMerchantStateSample{publicstaticvoidgetLfpMerchantState(Configconfig,StringtargetMerchantId)throwsException{// Obtains OAuth token based on the user's configuration.GoogleCredentialscredential=newAuthenticator().authenticate();// Creates service settings using the credentials retrieved above.LfpMerchantStateServiceSettingslfpMerchantStateServiceSettings=LfpMerchantStateServiceSettings.newBuilder().setCredentialsProvider(FixedCredentialsProvider.create(credential)).build();// Gets the LFP account ID from the user's configuration.StringlfpAccountId=config.getAccountId().toString();// Calls the API and catches and prints any network failures/errors.try(LfpMerchantStateServiceClientlfpMerchantStateServiceClient=LfpMerchantStateServiceClient.create(lfpMerchantStateServiceSettings)){GetLfpMerchantStateRequestrequest=GetLfpMerchantStateRequest.newBuilder().setName(LfpMerchantStateName.of(lfpAccountId,targetMerchantId).toString()).build();System.out.println("Sending get LFP merchant state request:");LfpMerchantStateresponse=lfpMerchantStateServiceClient.getLfpMerchantState(request);System.out.println("Retrieved LFP merchant state below:");System.out.println(response);}catch(Exceptione){System.out.println(e);}}publicstaticvoidmain(String[]args)throwsException{Configconfig=Config.load();// The Merchant Center account ID.StringtargetMerchantId="{target_merchant}";getLfpMerchantState(config,targetMerchantId);}}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-13 UTC."],[],[],null,["# Get a LFP merchant state\n\nMerchant API code sample to get a LFP merchant state. \n\n### Java\n\n // Copyright 2025 Google LLC\n\n // Licensed under the Apache License, Version 2.0 (the \"License\");\n // you may not use this file except in compliance with the License.\n // You may obtain a copy of the License at\n //\n // https://www.apache.org/licenses/LICENSE-2.0\n //\n // Unless required by applicable law or agreed to in writing, software\n // distributed under the License is distributed on an \"AS IS\" BASIS,\n // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n // See the License for the specific language governing permissions and\n // limitations under the License.\n\n package shopping.merchant.samples.lfp.v1;\n\n import com.google.api.gax.core.FixedCredentialsProvider;\n import com.google.auth.oauth2.GoogleCredentials;\n import com.google.shopping.merchant.lfp.v1.GetLfpMerchantStateRequest;\n import com.google.shopping.merchant.lfp.v1.LfpMerchantState;\n import com.google.shopping.merchant.lfp.v1.LfpMerchantStateName;\n import com.google.shopping.merchant.lfp.v1.LfpMerchantStateServiceClient;\n import com.google.shopping.merchant.lfp.v1.LfpMerchantStateServiceSettings;\n import shopping.merchant.samples.utils.Authenticator;\n import shopping.merchant.samples.utils.Config;\n\n /** This class demonstrates how to get the LFP state for a given Merchant Center account */\n public class GetLfpMerchantStateSample {\n\n public static void getLfpMerchantState(Config config, String targetMerchantId) throws Exception {\n\n // Obtains OAuth token based on the user's configuration.\n GoogleCredentials credential = new Authenticator().authenticate();\n\n // Creates service settings using the credentials retrieved above.\n LfpMerchantStateServiceSettings lfpMerchantStateServiceSettings =\n LfpMerchantStateServiceSettings.newBuilder()\n .setCredentialsProvider(FixedCredentialsProvider.create(credential))\n .build();\n\n // Gets the LFP account ID from the user's configuration.\n String lfpAccountId = config.getAccountId().toString();\n // Calls the API and catches and prints any network failures/errors.\n try (LfpMerchantStateServiceClient lfpMerchantStateServiceClient =\n LfpMerchantStateServiceClient.create(lfpMerchantStateServiceSettings)) {\n\n GetLfpMerchantStateRequest request =\n GetLfpMerchantStateRequest.newBuilder()\n .setName(LfpMerchantStateName.of(lfpAccountId, targetMerchantId).toString())\n .build();\n\n System.out.println(\"Sending get LFP merchant state request:\");\n LfpMerchantState response = lfpMerchantStateServiceClient.getLfpMerchantState(request);\n\n System.out.println(\"Retrieved LFP merchant state below:\");\n System.out.println(response);\n } catch (Exception e) {\n System.out.println(e);\n }\n }\n\n public static void main(String[] args) throws Exception {\n Config config = Config.load();\n\n // The Merchant Center account ID.\n String targetMerchantId = \"{target_merchant}\";\n\n getLfpMerchantState(config, targetMerchantId);\n }\n } \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/java/src/main/java/shopping/merchant/samples/lfp/v1/GetLfpMerchantStateSample.java"]]