# Own session management

## Retrieving own session context

> Retrieves a session context associated with the \`sessionId\` derived from the Authorization token used in the call. The session context is created when a cart is created; if none exists yet, the response is 404.\
> Recommended for performing calls on the storefront.

```json
{"openapi":"3.0.0","info":{"title":"Session Context Service","version":"0.0.1"},"tags":[{"name":"Own session management"}],"servers":[{"url":"https://api.emporix.io"}],"security":[{"CustomerAccessToken":[]}],"components":{"securitySchemes":{"CustomerAccessToken":{"type":"http","scheme":"bearer","bearerFormat":"JWT","description":"Customer or anonymous access token. Use the token obtained from the storefront session (e.g. [Requesting an anonymous token](https://developer.emporix.io/api-references/api-guides/companies-and-customers/customer-management/api-reference/authentication-and-authorization#get-customerlogin-auth-anonymous-refresh) or [Logging in a customer](https://developer.emporix.io/api-references/api-guides/companies-and-customers/customer-management/api-reference/authentication-and-authorization#post-customer-tenant-login)).\n"}},"responses":{"200_get_session":{"description":"The request was successful. Session context details are returned.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SessionContext_GET"}}}},"404_session":{"description":"A session context with the provided ID was not found.","content":{"application/json":{"schema":{"allOf":[{"type":"object","properties":{"sessionId":{"type":"string","description":"Unique identifier of the session."}}},{"$ref":"#/components/schemas/ErrorMessage"}]}}}},"500_common":{"description":"A server-side error occurred.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}}},"schemas":{"SessionContext_GET":{"allOf":[{"$ref":"#/components/schemas/SessionContextBase"},{"type":"object","properties":{"context":{"$ref":"#/components/schemas/Context"}}},{"type":"object","properties":{"metadata":{"$ref":"#/components/schemas/Metadata"}}}]},"SessionContextBase":{"title":"SessionContextBase","type":"object","properties":{"sessionId":{"type":"string","description":"Unique identifier of the customer's session."},"customerId":{"type":"string","description":"Customer unique identifier.\n\n**Note**: This field is only applicable to logged-in customers."},"siteCode":{"type":"string","description":"Code of the site, as defined in the Site Settings Service.\n\n**Note**: The default country code for anonymous sessions is based on the home base address country of the default site. In the case of a logged-in customer session, the country code is derived from the customer's shipping address, with the billing address being used as a fallback if the former is not available. If both addresses are not set, the home base address country code from the default site is used."},"currency":{"type":"string","description":"Three-letter currency code, as defined in the Currency Service.\n\n**Note**: During an anonymous session, the default currency of the site serves as the initial currency. Whereas, for a user session, the customer's preferred currency is set as the initial currency."},"cartId":{"type":"string","description":"Unique identifier of the active customer cart, generated when the cart is created through the Cart Service."},"targetLocation":{"type":"string","description":"The country code, as defined in the country service.\n\n\n**Note**: The default country code for anonymous sessions is based on the home base address country of the default site. In the case of a logged-in customer session, the country code is derived from the customer's shipping address, with the billing address being used as a fallback if the former is not available. If both addresses are not set, the home base address country code from the default site is used."}}},"Context":{"title":"Context","type":"object","additionalProperties":{"type":"object"}},"Metadata":{"allOf":[{"$ref":"#/components/schemas/MetadataUpdate"},{"type":"object","properties":{"createdAt":{"type":"string","description":"Date and time when the object was created."},"modifiedAt":{"type":"string","description":"Date and time when the object was last modified."}}}]},"MetadataUpdate":{"title":"Metadata","type":"object","properties":{"version":{"type":"integer","description":"Version of the session context object."}}},"ErrorMessage":{"type":"object","properties":{"code":{"type":"integer","description":"HTTP Status Code"},"message":{"type":"string","description":"Detailed error message"}}}}},"paths":{"/session-context/{tenant}/me/context":{"get":{"tags":["Own session management"],"summary":"Retrieving own session context","operationId":"GET-session-context-retrieve-session-context-by-sessionId","description":"Retrieves a session context associated with the `sessionId` derived from the Authorization token used in the call. The session context is created when a cart is created; if none exists yet, the response is 404.\nRecommended for performing calls on the storefront.","responses":{"200":{"$ref":"#/components/responses/200_get_session"},"404":{"$ref":"#/components/responses/404_session"},"500":{"$ref":"#/components/responses/500_common"}}}}}}
```

## Partially updating own session context

> Partially updates a session context associated with the \`sessionId\` derived from the Authorization token used in the call.\
> Recommended for performing calls on the storefront.\
> \
> \*\*Note\*\*: To update a session context, you need to provide its current \`metadata.version\` value in the request body.\
> \
> \*\*Note\*\*: Only specific fields can be updated this way, and the rest is ignored. The fields allowed to be updated: \`siteCode\`, \`currency\`, \`targetLocation\`, \`context\`.

```json
{"openapi":"3.0.0","info":{"title":"Session Context Service","version":"0.0.1"},"tags":[{"name":"Own session management"}],"servers":[{"url":"https://api.emporix.io"}],"security":[{"CustomerAccessToken":[]}],"components":{"securitySchemes":{"CustomerAccessToken":{"type":"http","scheme":"bearer","bearerFormat":"JWT","description":"Customer or anonymous access token. Use the token obtained from the storefront session (e.g. [Requesting an anonymous token](https://developer.emporix.io/api-references/api-guides/companies-and-customers/customer-management/api-reference/authentication-and-authorization#get-customerlogin-auth-anonymous-refresh) or [Logging in a customer](https://developer.emporix.io/api-references/api-guides/companies-and-customers/customer-management/api-reference/authentication-and-authorization#post-customer-tenant-login)).\n"}},"responses":{"204_update_session":{"description":"The request was successful. The session context has been updated."},"404_session":{"description":"A session context with the provided ID was not found.","content":{"application/json":{"schema":{"allOf":[{"type":"object","properties":{"sessionId":{"type":"string","description":"Unique identifier of the session."}}},{"$ref":"#/components/schemas/ErrorMessage"}]}}}},"500_common":{"description":"A server-side error occurred.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorMessage"}}}}},"schemas":{"ErrorMessage":{"type":"object","properties":{"code":{"type":"integer","description":"HTTP Status Code"},"message":{"type":"string","description":"Detailed error message"}}},"SessionContext_PATCH":{"title":"SessionContextPartialUpdateRequest","description":"Request body for partially updating own session context (PATCH /me/context).\nOnly the following fields can be updated; all other fields are ignored.\n","type":"object","properties":{"siteCode":{"type":"string","description":"Code of the site, as defined in the Site Settings Service."},"currency":{"type":"string","description":"Three-letter currency code, as defined in the Currency Service."},"targetLocation":{"type":"string","description":"The country code, as defined in the country service."},"context":{"$ref":"#/components/schemas/Context","description":"Custom session attributes. Same structure as returned in the response."},"metadata":{"$ref":"#/components/schemas/MetadataUpdate"}},"required":["metadata"]},"Context":{"title":"Context","type":"object","additionalProperties":{"type":"object"}},"MetadataUpdate":{"title":"Metadata","type":"object","properties":{"version":{"type":"integer","description":"Version of the session context object."}}}},"requestBodies":{"sessionId_PATCH":{"description":"Partial update. Only `siteCode`, `currency`, `targetLocation`, and `context` are accepted; include `metadata.version` for optimistic locking.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SessionContext_PATCH"}}}}}},"paths":{"/session-context/{tenant}/me/context":{"patch":{"tags":["Own session management"],"summary":"Partially updating own session context","operationId":"PATCH-session-context-update-attribute-sessionId-storefront","description":"Partially updates a session context associated with the `sessionId` derived from the Authorization token used in the call.\nRecommended for performing calls on the storefront.\n\n**Note**: To update a session context, you need to provide its current `metadata.version` value in the request body.\n\n**Note**: Only specific fields can be updated this way, and the rest is ignored. The fields allowed to be updated: `siteCode`, `currency`, `targetLocation`, `context`.","responses":{"204":{"$ref":"#/components/responses/204_update_session"},"404":{"$ref":"#/components/responses/404_session"},"500":{"$ref":"#/components/responses/500_common"}},"requestBody":{"$ref":"#/components/requestBodies/sessionId_PATCH"}}}}}
```
