public function setDynamicMetadata($dynamicMetadata, $hash, $organization = '', $options = [])
    {
        if (!\is_array($dynamicMetadata)) {
            $dynamicMetadata = [$dynamicMetadata];
        }

        $count = 0;
        $response = null;
        foreach ($dynamicMetadata as $value => $data) {
            $callOptions = [];
            if ($data instanceof DynamicMetadataInterface) {
                $name = $data::getName();
                $callOptions['json'] = $data->getForJson();
            } else {
                $name = $value;
                $callOptions['json'] = $data;
            }

            $path = implode('/', [
                self::SOURCEIMAGE_RESOURCE,
                $this->getOrganizationName($organization),
                $hash,
                self::DYNAMIC_META_RESOURCE,
                $name,
            ]);

            // delete the previous, if we're not on the first one anymore, or if we want to delete it.
            if ($count > 0 || (0 === $count && isset($options['deletePrevious']) && $options['deletePrevious'])) {
                $callOptions['query'] = ['deletePrevious' => 'true'];
            }

            ++$count;
            $response = $this->call('PUT', $path, $callOptions);
            if (!($response->getStatusCode() >= 200 && $response->getStatusCode() < 300)) {
                throw new \LogicException($response->getBody()->getContents(), $response->getStatusCode());
            }
            $hash = $this->extractHashFromLocationHeader($response->getHeader('Location'));
        }
        if ($response instanceof ResponseInterface) {
            if ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300) {
                return $hash;
            }
            // Throw an exception to be handled by the caller.
            throw new \LogicException($response->getBody()->getContents(), $response->getStatusCode());
        }

        throw new \LogicException('Something went wrong with the call/response to the rokka API', 0);
    }