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

400 Bad request - Creating new location

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

Hi, i'm struggling with an issue why when i'm trying to create new location a got an object where all fields populated except location->name = null; Can any body help me? i tried a lot of different ways. I need to get locationId of created instance
Here is var_dump of my location object

object(Google_Service_MyBusiness_Location)#2635 (40) {
["collection_key":protected]=>string(6) "labels"
["internal_gapi_mappings":protected]=>array(0) {}
["adWordsLocationExtensionsType":protected]=>string(51) "Google_Service_MyBusiness_AdWordsLocationExtensions"
["adWordsLocationExtensionsDataType":protected]=>string(0) ""
["additionalCategoriesType":protected]=>string(34) "Google_Service_MyBusiness_Category"
["additionalCategoriesDataType":protected]=>string(5) "array"
["additionalPhones"]=>array(1) {[0]=>
string(14) "(303) 111-2233"
}
["addressType":protected]=>string(33) "Google_Service_MyBusiness_Address"
["addressDataType":protected]=>string(0) ""
["attributesType":protected]=>string(35) "Google_Service_MyBusiness_Attribute"
["attributesDataType":protected]=>string(5) "array"
["labels"]=>array(2) {[0]=>string(15) "Recently opened", [1]=>string(12) "High-traffic"}
["languageCode"]=>string(2) "en"
["latlngType":protected]=>string(32) "Google_Service_MyBusiness_LatLng"
["latlngDataType":protected]=>string(0) ""
["locationKeyType":protected]=>string(37) "Google_Service_MyBusiness_LocationKey"
["locationKeyDataType":protected]=>string(0) ""
["locationName"]=>string(33) "Conditioning"
["locationStateType":protected]=>string(39) "Google_Service_MyBusiness_LocationState"
["locationStateDataType":protected]=>string(0) ""
["metadataType":protected]=>string(34) "Google_Service_MyBusiness_Metadata"
["metadataDataType":protected]=>string(0) ""
["name"]=>
NULL WHY??????????????????????
["openInfoType":protected]=>string(34) "Google_Service_MyBusiness_OpenInfo"
["openInfoDataType":protected]=>string(0) ""
["photosType":protected]=>string(32) "Google_Service_MyBusiness_Photos"
["photosDataType":protected]=>string(0) ""
["primaryCategoryType":protected]=>string(34) "Google_Service_MyBusiness_Category"
["primaryCategoryDataType":protected]=>string(0) ""
["primaryPhone"]=>string(15) "(303) 111-2234"
["regularHoursType":protected]=>string(39) "Google_Service_MyBusiness_BusinessHours"
["regularHoursDataType":protected]=>string(0) ""
["serviceAreaType":protected]=>string(45) "Google_Service_MyBusiness_ServiceAreaBusiness"
["serviceAreaDataType":protected]=>string(0) ""
["specialHoursType":protected]=>string(38) "Google_Service_MyBusiness_SpecialHours"
["specialHoursDataType":protected]=>string(0) ""
["storeCode"]=>string(12) "665377377372"
["websiteUrl"]=>string(28) "http://somesite.com"
["modelData":protected]=>array(6) {
["address"]=>array(5) {["addressLines"]=>
array(1) {
[0]=>string(17) "4900 Some.. St"}
["locality"]=>string(9) "Denver"
["administrativeArea"]=>string(2) "CO"
["country"]=>string(2) "US"
["postalCode"]=>string(5) "80216"
}
["primaryCategory"]=>
array(2) {["name"]=>string(17) "gcid:thrift_store", ["categoryId"]=>string(17) "gcid:thrift_store"}
["additionalCategories"]=>array(6) {[0]=>array(2) {["name"]=>
string(19) "gcid:clothing_store"
["categoryId"]=>
string(19) "gcid:clothing_store"
}
[1]=>
array(2) {
["name"]=>
string(21) "gcid:donations_center"
["categoryId"]=>
string(21) "gcid:donations_center"
}
[2]=>
array(2) {
["name"]=>
string(20) "gcid:furniture_store"
["categoryId"]=>
string(20) "gcid:furniture_store"
}
[3]=>
array(2) {
["name"]=>
string(28) "gcid:non_profit_organization"
["categoryId"]=>
string(28) "gcid:non_profit_organization"
}
[4]=>
array(2) {
["name"]=>
string(21) "gcid:recycling_center"
["categoryId"]=>
string(21) "gcid:recycling_center"
}
[5]=>
array(2) {
["name"]=>
string(21) "gcid:second_hand_shop"
["categoryId"]=>
string(21) "gcid:second_hand_shop"
}
}
["regularHours"]=>
array(1) {
["periods"]=>
array(2) {
[0]=>
array(4) {
["openDay"]=>
string(6) "SUNDAY"
["openTime"]=>
string(5) "11:00"
["closeDay"]=>
string(6) "SUNDAY"
["closeTime"]=>
string(5) "18:00"
}
[1]=>
array(4) {
["openDay"]=>
string(6) "MONDAY"
["openTime"]=>
string(5) "09:00"
["closeDay"]=>
string(6) "MONDAY"
["closeTime"]=>
string(5) "21:00"
}
}
}
["photos"]=>
array(0) {
}
["specialHours"]=>
array(0) {
}
}
["processed":protected]=>
array(0) {
}

 

Here is how i try do it:

 

        $myBusiness = new \Google_Service_MyBusiness($client);
$accounts_locations = $myBusiness->accounts_locations;

$location_data = new \Google_Service_MyBusiness_Location();
$address = new \Google_Service_MyBusiness_Address();
$address->setAddressLines($data['address']['addressLines'][0]);
$address->setLocality($data['address']['locality']);
$address->setAdministrativeArea($data['address']['administrativeArea']);
$address->setCountry($data['address']['country']);
$address->setPostalCode($data['address']['postalCode']);

$location_data->setAddress($address);

$periods = new \Google_Service_MyBusiness_BusinessHours();
$periods->setPeriods($location->regularHours);

$location_data->setRegularHours($periods);
$location_data->setLocationName($location->locationName);
$location_data->setStoreCode($data['storeCode']);
$location_data->setPrimaryPhone($data['primaryPhone']);
$location_data->setLanguageCode('en');
$location_data->setAdditionalCategories($data['additionalCategories']);
$location_data->setAdditionalPhones("(303) 111-2233");
$location_data->setLabels($location->labels);

$category = new \Google_Service_MyBusiness_Category();
$category->setCategoryId($location->primaryCategory['categoryId']);
$category->setName($location->primaryCategory['name']);

$location_data->setPrimaryCategory($category);
$location_data->setWebsiteUrl($data['websiteUrl']);
$location_data->setAdditionalCategories($data['additionalCategories']);

$labels = array("Recently opened", "High-traffic");
$location_data->setLabels($labels);

try {
$createdlocation = $accounts_locations->create(
$gmbAccount->name,
$location_data,
array(
'languageCode'=> 'en',
'validateOnly' => 'true',
'requestId' => uniqid(50))
);
}....

 

 

 

 

 

 

1 Expert replyverified_user

Re: 400 Bad request - Creating new location

Google Employee
# 2
Google Employee

Hi @Native R,

 

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,

The Google My Business API Team