diff --git a/README.md b/README.md index a9f00b37..8008cc0a 100644 --- a/README.md +++ b/README.md @@ -235,6 +235,7 @@ Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- *FingerprintApi* | [**getEvent**](docs/Api/FingerprintApi.md#getevent) | **GET** /events/{request_id} | Get event by request ID *FingerprintApi* | [**getVisits**](docs/Api/FingerprintApi.md#getvisits) | **GET** /visitors/{visitor_id} | Get visits by visitor ID +*FingerprintApi* | [**updateEvent**](docs/Api/FingerprintApi.md#updateevent) | **PUT** /events/{request_id} | Update an event with a given request ID ## Documentation for Models diff --git a/docs/Api/FingerprintApi.md b/docs/Api/FingerprintApi.md index d083e655..e7cfc5e5 100644 --- a/docs/Api/FingerprintApi.md +++ b/docs/Api/FingerprintApi.md @@ -6,6 +6,7 @@ Method | HTTP request | Description ------------- | ------------- | ------------- [**getEvent**](FingerprintApi.md#getEvent) | **GET** /events/{request_id} | Get event by request ID [**getVisits**](FingerprintApi.md#getVisits) | **GET** /visitors/{visitor_id} | Get visits by visitor ID +[**updateEvent**](FingerprintApi.md#updateEvent) | **PUT** /events/{request_id} | Update an event with a given request ID # **getEvent** > [ \Fingerprint\ServerAPI\Model\EventResponse, \Psr\Http\Message\ResponseInterface ] getEvent($request_id) @@ -141,3 +142,66 @@ Array: [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) +# **updateEvent** +> updateEvent($body, $request_id) + +Update an event with a given request ID + +Change information in existing events specified by `requestId` or *flag suspicious events*. When an event is created, it is assigned `linkedId` and `tag` submitted through the JS agent parameters. This information might not be available on the client so the Server API allows for updating the attributes after the fact. **Warning** It's not possible to update events older than 10 days. + +### Example +```php +updateEvent($body, $request_id); +} catch (Exception $e) { + echo 'Exception when calling FingerprintApi->updateEvent: ', $e->getMessage(), PHP_EOL; +} +?> +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**\Fingerprint\ServerAPI\Model\EventUpdateRequest**](../Model/EventUpdateRequest.md)| | + **request_id** | **string**| The unique event [identifier](https://dev.fingerprint.com/docs/js-agent#requestid). | + +### Return type + +Array: +0. null, +1. \Psr\Http\Message\ResponseInterface + + +### Authorization + +[ApiKeyHeader](../../README.md#ApiKeyHeader), [ApiKeyQuery](../../README.md#ApiKeyQuery) + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + diff --git a/res/fingerprint-server-api.yaml b/res/fingerprint-server-api.yaml index de3f289a..65b6f346 100644 --- a/res/fingerprint-server-api.yaml +++ b/res/fingerprint-server-api.yaml @@ -79,6 +79,65 @@ paths: application/json: schema: $ref: '#/components/schemas/ErrorEvent404Response' + put: + tags: + - Fingerprint + operationId: updateEvent + summary: Update an event with a given request ID + description: > + Change information in existing events specified by `requestId` or *flag + suspicious events*. + + + When an event is created, it is assigned `linkedId` and `tag` submitted + through the JS agent parameters. This information might not be available + on the client so the Server API allows for updating the attributes after + the fact. + + + **Warning** It's not possible to update events older than 10 days. + parameters: + - name: request_id + in: path + description: >- + The unique event + [identifier](https://dev.fingerprint.com/docs/js-agent#requestid). + required: true + schema: + type: string + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/EventUpdateRequest' + responses: + '200': + description: OK + '400': + description: Bad request + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorUpdateEvent400Response' + '403': + description: Forbidden + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorCommon403Response' + '404': + description: Not found + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEvent404Response' + '409': + description: Conflict + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorUpdateEvent409Response' /visitors/{visitor_id}: get: tags: diff --git a/src/Api/FingerprintApi.php b/src/Api/FingerprintApi.php index 1be0f18e..97c60e1f 100644 --- a/src/Api/FingerprintApi.php +++ b/src/Api/FingerprintApi.php @@ -30,6 +30,7 @@ use Fingerprint\ServerAPI\ApiException; use Fingerprint\ServerAPI\Configuration; +use Fingerprint\ServerAPI\Model\EventUpdateRequest; use Fingerprint\ServerAPI\ObjectSerializer; use Fingerprint\ServerAPI\SerializationException; use GuzzleHttp\Client; @@ -388,6 +389,172 @@ function ($e) { ); } + /** + * Operation updateEvent. + * + * Update an event with a given request ID + * + * @param EventUpdateRequest $body (required) + * @param string $request_id The unique event [identifier](https://dev.fingerprint.com/docs/js-agent#requestid). (required) + * + * @return array{ null, \Psr\Http\Message\ResponseInterface } + * + * @throws \InvalidArgumentException + * @throws SerializationException + * @throws GuzzleException + */ + public function updateEvent(EventUpdateRequest $body, string $request_id): array + { + $returnType = ''; + $request = $this->updateEventRequest($body, $request_id); + + try { + $options = $this->createHttpClientOption(); + + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + $apiException = new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode() + ); + $apiException->setResponseObject($e->getResponse()); + + throw $apiException; + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + $apiException = new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $request->getUri() + ), + $statusCode + ); + $apiException->setResponseObject($response); + + throw $apiException; + } + + return [null, $response]; + } catch (ApiException $e) { + /** @var ResponseInterface $response */ + $response = $e->getResponseObject(); + + switch ($e->getCode()) { + case 400: + $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorUpdateEvent400Response'); + $e->setErrorDetails($errorDetail); + $e->setResponseObject($response); + + break; + + case 403: + $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorCommon403Response'); + $e->setErrorDetails($errorDetail); + $e->setResponseObject($response); + + break; + + case 404: + $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorEvent404Response'); + $e->setErrorDetails($errorDetail); + $e->setResponseObject($response); + + break; + + case 409: + $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorUpdateEvent409Response'); + $e->setErrorDetails($errorDetail); + $e->setResponseObject($response); + + break; + } + + throw $e; + } + } + + /** + * Operation updateEventAsync. + * + * Update an event with a given request ID + * + * @param EventUpdateRequest $body (required) + * @param string $request_id The unique event [identifier](https://dev.fingerprint.com/docs/js-agent#requestid). (required) + * + * @throws \InvalidArgumentException + * @throws SerializationException + */ + public function updateEventAsync(EventUpdateRequest $body, string $request_id): PromiseInterface + { + $returnType = ''; + $request = $this->updateEventRequest($body, $request_id); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($request) { + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + $apiException = new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $request->getUri() + ), + $statusCode + ); + $apiException->setResponseObject($response); + + throw $apiException; + } + + return [null, $response]; + }, + function ($e) { + /** @var ResponseInterface $response */ + $response = $e->getResponseObject(); + + switch ($e->getCode()) { + case 400: + $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorUpdateEvent400Response'); + $e->setErrorDetails($errorDetail); + $e->setResponseObject($response); + + break; + + case 403: + $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorCommon403Response'); + $e->setErrorDetails($errorDetail); + $e->setResponseObject($response); + + break; + + case 404: + $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorEvent404Response'); + $e->setErrorDetails($errorDetail); + $e->setResponseObject($response); + + break; + + case 409: + $errorDetail = ObjectSerializer::deserialize($response, '\Fingerprint\ServerAPI\Model\ErrorUpdateEvent409Response'); + $e->setErrorDetails($errorDetail); + $e->setResponseObject($response); + + break; + } + + throw $e; + } + ); + } + /** * Create request for operation 'getEvent'. * @@ -539,6 +706,88 @@ protected function getVisitsRequest(string $visitor_id, ?string $request_id = nu ); } + /** + * Create request for operation 'updateEvent'. + * + * @throws \InvalidArgumentException + * @throws SerializationException + */ + protected function updateEventRequest(EventUpdateRequest $body, string $request_id): Request + { + // verify the required parameter 'body' is set + if (null === $body || (is_array($body) && 0 === count($body))) { + throw new \InvalidArgumentException( + 'Missing the required parameter $body when calling updateEvent' + ); + } + // verify the required parameter 'request_id' is set + if (null === $request_id || (is_array($request_id) && 0 === count($request_id))) { + throw new \InvalidArgumentException( + 'Missing the required parameter $request_id when calling updateEvent' + ); + } + + $resourcePath = '/events/{request_id}'; + $headers = []; + $queryParams = ['ii' => $this->integration_info]; + $headerParams = []; + $httpBody = ''; + + // path params + if (null !== $request_id) { + $resourcePath = str_replace( + '{request_id}', + ObjectSerializer::toPathValue($request_id), + $resourcePath + ); + } + + // body params + $_tempBody = null; + if (isset($body)) { + $_tempBody = $body; + } + // for model (json/xml) + if (isset($_tempBody)) { + // $_tempBody is the method argument, if present + $httpBody = json_encode($_tempBody); + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('Auth-API-Key'); + if (null !== $apiKey) { + $headers['Auth-API-Key'] = $apiKey; + } + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if (null !== $apiKey) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = [ + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', + ]; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = http_build_query($queryParams); + + return new Request( + 'PUT', + $this->config->getHost().$resourcePath.($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + /** * Create http client option. *