My Business
2.1K members online now
2.1K members online now
For developers who are using the Google My Business API to manage locations
Guide Me
star_border
Reply

Unable to create new location

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Trying to create a new Location as shown below.  Response is "Request contains an invalid argument."  I've reviewed others with similar issue here but cannot determine what the issue is.  (The setAddressLines statement is redacted intentionally)

 

$locations = $mybusinessService->accounts_locations;

$address = new \Google_Service_Mybusiness_Address();
$address->setAddressLines("<street address>");
$address->setLocality("Portland");
$address->setAdministrativeArea("OR");
$address->setCountry("US");
$address->setPostalCode("97210");

$category = new \Google_Service_Mybusiness_Category();
$category->setName('Cell Phone Store');
$category->setCategoryId('gcid:cell_phone_store');

$latlng = new \Google_Service_Mybusiness_LatLng();
$latlng->setLatitude('45.5231885');
$latlng->setLongitude('-122.69901099999998');

$newLocation = new \Google_Service_Mybusiness_Location();
$newLocation->setName('Cell Phone Market');
$newLocation->setLocationName('Location01');
$newLocation->setStoreCode('NS-001');
$newLocation->setLatlng($latlng);
$newLocation->setWebsiteUrl('http://www.mystore.com/');
$newLocation->setPrimaryCategory($category);
$newLocation->setAddress($address);
$newLocation->setLanguageCode('en-US');
$newLocation->setPrimaryPhone('650-555-1212');

$location = $locations->create($accountName, $newLocation);

 

1 Expert replyverified_user

Re: Unable to create new location

Google Employee
# 2
Google Employee

Hi @David L,

 

Judging from the source code you provided, I notice that you are missing couple of parameters in your code when creating a new location. You didn’t add validateOnly and requestId in your code. I suggest you please add the following parameters in your code to see if it fixes your issue:

 

$newLocation->setLanguageCode('en-US');
$newLocation->setValidateOnly(false);
$newLocation->setRequestId("unique request ID");

 

Since the PHP client library doesn’t currently support the display of detailed error messages, so I suggest you follow the Make a simple HTTP request step-by-step guide on the Google Developers site and try use the OAuth 2.0 Playground to step through the auth flow, and examine the HTTP request/response at each step. This usually helps pinpoint where an application is passing the incorrect info.

 

Thanks,

Shalini

Unable to create new location

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Shalini,

 

Thanks again as always for your response.  We will give your suggestions a try.

 

Is there any documentation on what fields are required for new location creation?  I tried to access the discovery document for the GMB API using the recommended URI of:

https://mybusiness.googleapis.com/$discovery/rest?version=v3&key=<my key here>

 

and I get:

{
 
"error": {
   
"status": "NOT_FOUND",
   
"message": "Discovery document not found for API service: mybusiness.googleapis.com format: rest version: v3",
   
"code": 404
 
}
}

Unable to create new location

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭

Hi Shalini,

 

We tried your recommendations:

 

--setValidateOnly() is not a method defined on the Google_Service_Mybusiness_Location class nor the Google_Service_Mybusiness_LocationKey class.  I am using the API client library recommended by Terry (dev-v1-master).

 

We did find the setRequestId() method on the Google_Service_Mybusiness_LocationKey class, instantiated an object, assigned a unique string using this method and set the LocationKey object on the Google_Service_Mybusiness_Location object and are again getting "response contains an invalid argument".

 

As far as using the OAuth playground to troubleshoot this, is there any guidance on how to construct the POST payload using the playground?  I'm not clear how to determine the required field names, for example, to create a new Location via the GMB API.  Any guidance would be greatly appreciated.

 

Many thanks,

David

Re: Unable to create new location

Google Employee
# 5
Google Employee

Hi @David L,

 

Please checkout this document for the query parameters that are required when you create a location using the Google My Business API. I suggest you checkout this accepted solution for creating a new location with the PHP client library via the Google My Business API. Please let me know if you have any other questions about Google My Business API.

 

I hope this helps!

 

Thanks,

Shalini

Unable to create new location

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭

Hi Shalini,

 

We followed the 'accepted solution' you recommended, and the api appears to be returning success now--no error is thrown, and the location object following the create() call looks legit.

 

However, when I list locations for my account at business.google.com, the location doesn't appear, nor does it show in the results of a subsequent Google_Service_Mybusiness->accounts_locations->listAccountsLocations($accountName) call.

 

Do newly created locations take time to appear in results?

 

Here is the updated code I am using:

 

$newLocation = new \Google_Service_Mybusiness_Location();

//////////////////////////
//configure address info//
//////////////////////////
$address = new \Google_Service_Mybusiness_Address();
$address->setAddressLines("street address");
$address->setLocality("Portland");
$address->setAdministrativeArea("OR");
$address->setCountry("US");
$address->setPostalCode("97210");
//$newLocation->setLanguageCode('en-US');

$newLocation->setAddress($address);

/////////////////////////////////////////
//configure location hours of operation//
/////////////////////////////////////////

$businessHours = new \Google_Service_Mybusiness_BusinessHours();
$timePeriods = array();
$days = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday");

foreach ($days as $day) {
$timePeriod = new \Google_Service_Mybusiness_TimePeriod();
$timePeriod->setOpenDay($day);
$timePeriod->setOpenTime("9:00");
$timePeriod->setCloseTime("17:00");
$timePeriod->setCloseDay($day);
$timePeriods[] = $timePeriod;
}

$businessHours->setPeriods($timePeriods);

$newLocation->setRegularHours($businessHours);

///////////////////////////
//configure location info//
///////////////////////////

$newLocation->setName('company name');
$newLocation->setLocationName('company name');
$newLocation->setStoreCode('NS-001');
$newLocation->setPrimaryPhone('phone number');
$newLocation->setWebsiteUrl('http://www.website.com/');

///////////////////////////
//configure category info//
///////////////////////////

$primaryCategory = new \Google_Service_Mybusiness_Category();
$primaryCategory->setName("Software Company");
$primaryCategory->setCategoryId("gcid:software_company");
$newLocation->setPrimaryCategory($primaryCategory);

////////////////////
//configure labels//
////////////////////

$labels = array("Recently opened");
$newLocation->setLabels($labels);

///////////////////////////////
//configure location lat/long//
///////////////////////////////

$latlng = new \Google_Service_Mybusiness_LatLng();
$latlng->setLatitude('45.5231885');
$latlng->setLongitude('-122.69901099999998');
$newLocation->setLatlng($latlng);

$location = $locations->create($account->name, $newLocation,
[
'languageCode'=>'en-US',
'validateOnly'=>FALSE,
'requestId'=>uniqid()
]);

dd($location);

Re: Unable to create new location

Google Employee
# 7
Google Employee

Hi @David L,

 

No, when you create a new location via the Google My Business API it should display in your account right away. Please make sure that you are logged into the same account you are using for the Google My Business API, also just perform a simple locations.list to see if the location is in the account via the Google My Business API.

 

Thanks,

The Google My Business API team

Unable to create new location

Visitor ✭ ✭ ✭
# 8
Visitor ✭ ✭ ✭

Hi Shalini,

 

We are not clear how to perform a "simple locations.list" call as you suggest.

 

This code fails to show the new location in the account after performing the new location steps detailed above in this thread:

$mybusinessService = new \Google_Service_Mybusiness($client);
$locations = $mybusinessService->accounts_locations->listAccountsLocations($accountName);

var_dump($locations);

Other locations for the given account are found with this call.

Unable to create new location

Visitor ✭ ✭ ✭
# 9
Visitor ✭ ✭ ✭

Hi Shalini,

 

We are still struggling to create new locations per your suggestions.  This is the code we are currently using to attempt to create a new location:

 

$newLocation = new \Google_Service_Mybusiness_Location();

//////////////////////////
//configure address info//
//////////////////////////
$address = new \Google_Service_Mybusiness_Address();
$address->setAddressLines("123 Maple St");
$address->setLocality("Portland");
$address->setAdministrativeArea("OR");
$address->setCountry("US");
$address->setPostalCode("97210");
//$newLocation->setLanguageCode('en-US');

$newLocation->setAddress($address);

/////////////////////////////////////////
//configure location hours of operation//
/////////////////////////////////////////

$businessHours = new \Google_Service_Mybusiness_BusinessHours();
$timePeriods = array();
$days = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday");

foreach ($days as $day) {
$timePeriod = new \Google_Service_Mybusiness_TimePeriod();
$timePeriod->setOpenDay($day);
$timePeriod->setOpenTime("9:00");
$timePeriod->setCloseTime("17:00");
$timePeriod->setCloseDay($day);
$timePeriods[] = $timePeriod;
}

$businessHours->setPeriods($timePeriods);

$newLocation->setRegularHours($businessHours);

///////////////////////////
//configure location info//
///////////////////////////

$newLocation->setName('My Market');
$newLocation->setStoreCode('NS-001');
$newLocation->setPrimaryPhone('650-787-4222');
$newLocation->setWebsiteUrl('http://www.mywebsite.com/');

///////////////////////////
//configure category info//
///////////////////////////

$primaryCategory = new \Google_Service_Mybusiness_Category();
$primaryCategory->setName("Software Company");
$primaryCategory->setCategoryId("gcid:software_company");
$newLocation->setPrimaryCategory($primaryCategory);

////////////////////
//configure labels//
////////////////////

$labels = array("Recently opened");
$newLocation->setLabels($labels);

///////////////////////////////
//configure location lat/long//
///////////////////////////////

$latlng = new \Google_Service_Mybusiness_LatLng();
$latlng->setLatitude('45.5231885');
$latlng->setLongitude('-122.69901099999998');
$newLocation->setLatlng($latlng);

$location = $locations->create($account->name, $newLocation,
[
'languageCode'=>'en-US',
'validateOnly'=>FALSE,
'requestId'=>uniqid()
]);



Following this call to the create method, when we perform a call to $account->locations using the same account as was used to create the location, we do see all other locations on the account that have been previously created, but not this new location. The create() call does not appear to be throwing an error and appears to complete successfully, but we can't be sure with the php library we are using since it doesn't report errors.

Can you take a close look at this code and point out anything you see that could be causing this issue? I was able to see the list of query parameters for location creation that you pointed us, but it isn't clear which fields are required. Are all the fields as listed here (https://developers.google.com/my-business/reference/rest/v3/accounts.locations#Location) required to create a new location?

TIA,
David

Unable to create new location

Visitor ✭ ✭ ✭
# 10
Visitor ✭ ✭ ✭

Shalini--please disregard...code is working, I had a debug statement that was preventing the create operation from occurring.