You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is a common task to add support for a custom (non-standard) SAP OCC API endpoint not covered by the Alokai intergration.
4
-
This guide will show you how can do it using Alokai.
4
+
There are two ways how you can do it:
5
5
6
-
## Prerequisites
6
+
1. Generate new API client based on OpenAPI (swagger) specification.
7
+
2. Add support for a custom endpoint manually.
7
8
8
-
Before we start make sure that you are familiar with [Adding New API Methods](https://docs.alokai.com/storefront/integration-and-setup/storefront-extension#adding-new-api-methods) guide. With that guide, you would be able to
9
+
## Generating new API client
10
+
11
+
Generation of new API client allows you to add support for all custom endpoints at once. You just run a script and all the endpoints will be added to the integration.
12
+
13
+
How to do this is described in the [Generated API guide](/integrations/sapcc/features/generated-api).
14
+
15
+
This should be your default approach, because it is the most scalable and maintainable way.
16
+
17
+
## Adding support for a custom endpoint manually
18
+
19
+
If you don't want or cannot generate a new API client, you can add support for a custom endpoint manually.
20
+
It boils down to adding a new API method to the middleware that calls the custom endpoint. This guide shows how to do it efficiently.
21
+
22
+
When to use this approach?
23
+
24
+
- When for some reason you cannot generate a new API client, e.g. OpenAPI specification is not available.
25
+
- When you are iterating fast both on the API and the front-end and you don't want to regenerate the API client for each change.
26
+
27
+
### Prerequisites
28
+
29
+
Before we start make sure that you are familiar with [Adding New API Methods](/unified-data-layer/integration-and-setup/creating-new-api-methods) guide. With that guide, you would be able to
9
30
communicate with OCC API but it would require manual retrieval of context parameters (baseSiteId, userId, language,
10
31
and currency) and preparation of authorization headers. Read on to see how to streamline that process.
11
32
12
-
## Communicating with OCC API effectively
33
+
###Communicating with OCC API effectively
13
34
14
35
OCC endpoints have a given structure
15
36
@@ -35,74 +56,69 @@ Here's where to find the parameters:
35
56
36
57
-`baseUrl` - is configured in .env file as `SAPCC_API_URI`. The api client already knows it and prepends each URL with it.
37
58
-`baseSiteId` - is defined in the middleware configuration. That configuration is exposed to api method via context.
38
-
-`userId` - can be found in the request cookies under [`AUTH_USER_COOKIE_NAME`](https://docs.alokai.com/integrations/sapcc/api/sapcc-api/AUTH_USER_COOKIE_NAME).
39
-
-`language` - can be found in the request cookies under [`VSF_LOCALE_COOKIE`](https://docs.alokai.com/storefront/features/internationalization/internatialization-support).
40
-
-`currency` - can be found in the request cookies under [`VSF_CURRENCY_COOKIE`](https://docs.alokai.com/storefront/features/internationalization/currency-switching).
41
-
- authorization token - can be found in the request cookies under [`AUTH_USER_TOKEN_COOKIE_NAME`](https://docs.alokai.com/integrations/sapcc/api/sapcc-api/AUTH_USER_TOKEN_COOKIE_NAME)
59
+
-`userId` - can be found in the request cookies under [`AUTH_USER_COOKIE_NAME`](/integrations/sapcc/api/sapcc-api/AUTH_USER_COOKIE_NAME).
60
+
-`language` - can be found in the request cookies under [`VSF_LOCALE_COOKIE`](/storefront/features/internationalization/internatialization-support).
61
+
-`currency` - can be found in the request cookies under [`VSF_CURRENCY_COOKIE`](/storefront/features/internationalization/currency-switching).
62
+
- authorization token - can be found in the request cookies under [`AUTH_USER_TOKEN_COOKIE_NAME`](/integrations/sapcc/api/sapcc-api/AUTH_USER_TOKEN_COOKIE_NAME)
42
63
43
64
You don't have to parse the cookies yourself. Alokai provides helper methods for that. Here’s a code example of how to do it:
Here's an example implementation of the product interest feature. This feature is available in OCC API, but not in the middleware and SDK integration.
113
+
Here's an example implementation of the product interest feature.
92
114
Let's add support for it.
93
115
94
-
First, you need to add a new API method in the middleware. (For simplicity, this guide shows how to do it in one file, but we recommend splitting it into multiple files to maintain cleaner code.)
116
+
First, you need to add a new API method in the middleware.
0 commit comments