Skip to content

Instantly share code, notes, and snippets.

@ermst4r
Last active September 4, 2019 10:48
Show Gist options
  • Save ermst4r/1751776833669fca1474f495ccc79a6f to your computer and use it in GitHub Desktop.
Save ermst4r/1751776833669fca1474f495ccc79a6f to your computer and use it in GitHub Desktop.
Client API
<?php
$json = "JOUW JSON KEY HIER";
$project_id = "JOUW Project ID HIER ";
$entity_type_id = "entity_type_id";
private function entity_create( array $entitie_array)
{
try {
$entityTypesClient = new EntityTypesClient([
'credentials' => public_path($json)
]);
} catch (\Exception $e) {
//
}
$parent = $entityTypesClient->entityTypeName($project_id,
$entity_type_id);
// prepare entity
foreach($entitie_array as $e) {
$entity = new Entity();
$entity->setValue($e);
$entity->setSynonyms([$e]);
$entities[] = $entity;
}
// create entity
$response = $entityTypesClient->batchCreateEntities($parent, $entities);
printf('Entity created: %s' . PHP_EOL, $response->getName());
$entityTypesClient->close();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment