Last active
September 4, 2019 10:48
-
-
Save ermst4r/1751776833669fca1474f495ccc79a6f to your computer and use it in GitHub Desktop.
Client API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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