Generic Service

In case there is no "typed" support for a particular service, you can always use the Generic Service to interact with the 3DEXPERIENCE™ REST services.

When using the Generic Service you need to construct the request payload and parse the response on your own.

Example:

const input = {  };
const response = spaceService
    .getGenericService()
    .post(session, '/api/foo/bar', JSON.stringify(input));
if (response.succeeded()) {
    const data = JSON.parse(response.bodyText());

}
The generic service will still help you to deal with CSRF tokens and the authorization exchange.

The Generic Service interface is defined like this:

public interface GenericService {

    default String get(TenantSession session, String uri) {
        return call(session, uri, HttpMethod.GET.toString(), false, true, true, null, null, null);
    }

    default String post(TenantSession session, String uri, String body) {
        return call(session, uri, HttpMethod.POST.toString(), true, true, true, null, null, body);
    }

    default String patch(TenantSession session, String uri, String body) {
        return call(session, uri, HttpMethod.PATCH.toString(), true, true, true, null, null, body);
    }

    default String put(TenantSession session, String uri, String body) {
        return call(session, uri, HttpMethod.PUT.toString(), true, true, true, null, null, body);
    }

    default String delete(TenantSession session, String uri) {
        return call(session, uri, HttpMethod.DELETE.toString(), true, true, true, null, null, null);
    }

    /**
     * <p>
     * Generic method to call an arbitrary REST end point.
     * </p>
     *
     * @param session The current session
     * @param uri The URI of the service, example:
     *        <code>/resources/v1/modeler/dscm/changerequest</code>
     * @param method The method, e.g. any of GET,POST,PATCH,DELETE etc.
     * @param csrf True if the service requires a CSRF token to be obtained for the
     *        call.
     * @param tenant True if to include the tenant as a request parameter. Note that
     *        this value is not added in case we use openness agents
     * @param securityContext True if to include the security context request header
     * @param headers Optional extra headers to be passed in. Null is allowed.
     * @param queryParams Optional extra query string parameters to be passed in.
     *        Null is allowed.
     * @param body Optional JSON body to be sent. Null is allowed.
     * @return The response from the 3DEXPERIENCE server.
     */
    String call(TenantSession session,
                String uri,
                String method,
                boolean csrf,
                boolean tenant,
                boolean securityContext,
                Map<String, String> headers,
                Map<String, Object> queryParams,
                String body);
}