---
title: "cookieGenerateByAccessToken"
description: "根据AccessToken生成cookie（要求：该接口仅对白名单店铺可用，您需要提交工单以获取申请调用说明）"
doc_type: graphql
doc_category: storefront
doc_version: v20270301
source_url:
  html: 'https://developer.shopline.com/zh-hans-cn/docs/storefront-api/customers/mutations/cookie-generate-by-access-token'
  md: 'https://developer.shopline.com/zh-hans-cn/docs/storefront-api/customers/mutations/cookie-generate-by-access-token.md'
---
# cookieGenerateByAccessToken

根据AccessToken生成cookie（要求：该接口仅对白名单店铺可用，您需要提交工单以获取申请调用说明）

- **API Version:** v20270301
- **API Type:** Storefront
- **API Protocol:** GraphQL
- **Operation Type:** Mutation

## Type Signature

`CookieGenerateByAccessTokenPayload`

## Arguments

* `accessToken`

  [String!](https://developer.shopline.com/zh-hans-cn/docs/storefront-api/common/scalars/string.md)

  客户访问令牌

## Returns

* `cookieDomainLevel`

  [Int](https://developer.shopline.com/zh-hans-cn/docs/storefront-api/common/scalars/int.md)

  cookie写入域名级别，1：写入一级域名下，2：写入二级域名下

* `cookies`

  [[CookieInfo]](https://developer.shopline.com/zh-hans-cn/docs/storefront-api/common-objects/objects/cookie-info.md)

  cookie 内容

* `customerUserErrors`

  [[CustomerUserError!]!](https://developer.shopline.com/zh-hans-cn/docs/storefront-api/customers/objects/customer-user-error.md)

  错误信息

* `httpOnly`

  [Boolean](https://developer.shopline.com/zh-hans-cn/docs/storefront-api/common/scalars/boolean.md)

  是否需要写入httpOnly

* `maxAge`

  [Int](https://developer.shopline.com/zh-hans-cn/docs/storefront-api/common/scalars/int.md)

  cookie有效期，单位秒

* `uid`

  [ID](https://developer.shopline.com/zh-hans-cn/docs/storefront-api/common/scalars/id.md)

  客户uid

## Code Example

```graphql
mutation cookieGenerateByAccessToken($accessToken: String! ) {
	cookieGenerateByAccessToken(accessToken: $accessToken ) 
		 {
			# CookieGenerateByAccessTokenPayload fields
		}
		
	}

```

## Variables

```json
{
  "accessToken": {}
}
```

## Examples

### 根据accessToken生成cookie

根据客户访问令牌AccessToken换取登录态cookie内容

**Request:**

```json
{
  "accessToken":"#A01#SID0000103BCFaf1/QOpLLIpYAcfByRgcExJiFJXjQrLxfHstVmsKu9C2QrsTALmOxRixBu7/lCVAsc6oLxbvQ9DpO8cwoDALzOHRfSD6ay/L4QJRy/CYWePa91yTIc+aZAIdsWOMRxfslDniMTO9TdkHaTT10slueGgfBCW6wmshzOUxGYKwykUE+s/lUIs8b+KD1mosZ0w"
}
```

**Response:**

```json
{
  "data": {
    "data": {
      "cookieGenerateByAccessToken": {
        "customerUserErrors": [],
        "httpOnly": true,
        "maxAge": 2073600,
        "uid": "gid://shopline/Customer/4217271901",
        "cookieDomainLevel": 2,
        "cookies": [
          {
            "cookieKey": "osudb_subappid",
            "cookieValue": "1671771213310"
          },
          {
            "cookieKey": "osudb_uid",
            "cookieValue": "4217271901"
          },
          {
            "cookieKey": "osudb_oar",
            "cookieValue": "#01#SID0000103BMjvullo3DELn47IG9TRkhhA5WiXq+tlrnXDKbs/L5KMSX4O1ijF7CcpTsThgAqDlECqwVYhs8NHoqtPFv+Eul+R4AUJHnWazTnjInS25BiGniV2DD8EhSK6s1aTwKbiEIA1LwJ7wByXO4Ii5pUw54vRXUiEbGwy/9Dhgg"
          },
          {
            "cookieKey": "osudb_appid",
            "cookieValue": "1163336839"
          }
        ]
      }
    },
    "extensions": {
      "dataloader": {
        "individual-statistics": {
          "LD-com.shopline.pixiu.pcq.storefront.api.CollectionStorefrontQueryService-queryCollectionByProduct": {
            "batchLoadCount": 0,
            "batchLoadExceptionCount": 0,
            "cacheHitCount": 0,
            "cacheHitRatio": 0,
            "loadErrorCount": 0,
            "loadErrorRatio": 0,
            "batchInvokeCount": 0,
            "batchLoadExceptionRatio": 0,
            "batchLoadRatio": 0,
            "loadCount": 0
          },
          "LD-com.shopline.pixiu.pcq.storefront.api.ProductStorefrontQueryV2Service-publishedAtForLoader": {
            "batchInvokeCount": 0,
            "batchLoadCount": 0,
            "batchLoadExceptionCount": 0,
            "batchLoadExceptionRatio": 0,
            "cacheHitCount": 0,
            "cacheHitRatio": 0,
            "loadCount": 0,
            "batchLoadRatio": 0,
            "loadErrorCount": 0,
            "loadErrorRatio": 0
          },
          "LD-com.shopline.pixiu.pcq.storefront.api.ProductStorefrontQueryV2Service-variants": {
            "loadCount": 0,
            "batchLoadExceptionCount": 0,
            "batchLoadExceptionRatio": 0,
            "batchLoadRatio": 0,
            "loadErrorCount": 0,
            "loadErrorRatio": 0,
            "batchInvokeCount": 0,
            "batchLoadCount": 0,
            "cacheHitCount": 0,
            "cacheHitRatio": 0
          },
          "LD-com.shopline.merchant.website.openapi.interfaces.OnlineStorefrontApi-commentsQuery": {
            "batchLoadCount": 0,
            "batchLoadExceptionCount": 0,
            "batchLoadExceptionRatio": 0,
            "batchLoadRatio": 0,
            "cacheHitCount": 0,
            "cacheHitRatio": 0,
            "loadCount": 0,
            "loadErrorCount": 0,
            "batchInvokeCount": 0,
            "loadErrorRatio": 0
          },
          "LD-com.shopline.pixiu.pcq.storefront.api.DescriptionQueryService-query": {
            "batchInvokeCount": 0,
            "batchLoadRatio": 0,
            "cacheHitRatio": 0,
            "batchLoadCount": 0,
            "batchLoadExceptionCount": 0,
            "batchLoadExceptionRatio": 0,
            "cacheHitCount": 0,
            "loadCount": 0,
            "loadErrorCount": 0,
            "loadErrorRatio": 0
          },
          "LD-com.shopline.pixiu.pcq.storefront.api.ProductStorefrontQueryV2Service-images": {
            "batchLoadExceptionRatio": 0,
            "cacheHitCount": 0,
            "cacheHitRatio": 0,
            "loadCount": 0,
            "loadErrorCount": 0,
            "loadErrorRatio": 0,
            "batchInvokeCount": 0,
            "batchLoadCount": 0,
            "batchLoadExceptionCount": 0,
            "batchLoadRatio": 0
          },
          "LD-com.shopline.pixiu.pcq.storefront.api.ProductStorefrontQueryV2Service-onlineStoreUrl": {
            "loadErrorRatio": 0,
            "batchInvokeCount": 0,
            "batchLoadRatio": 0,
            "loadErrorCount": 0,
            "batchLoadCount": 0,
            "batchLoadExceptionCount": 0,
            "batchLoadExceptionRatio": 0,
            "cacheHitCount": 0,
            "cacheHitRatio": 0,
            "loadCount": 0
          },
          "LD-com.shopline.pixiu.pcq.storefront.api.ProductStorefrontQueryV2Service-options": {
            "loadErrorCount": 0,
            "loadErrorRatio": 0,
            "batchLoadCount": 0,
            "batchLoadRatio": 0,
            "cacheHitRatio": 0,
            "loadCount": 0,
            "batchInvokeCount": 0,
            "batchLoadExceptionCount": 0,
            "batchLoadExceptionRatio": 0,
            "cacheHitCount": 0
          },
          "LD-com.shopline.pixiu.pcq.storefront.api.ProductStorefrontQueryV2Service-tagsForLoader": {
            "cacheHitRatio": 0,
            "loadErrorCount": 0,
            "loadErrorRatio": 0,
            "batchInvokeCount": 0,
            "batchLoadCount": 0,
            "batchLoadExceptionCount": 0,
            "batchLoadExceptionRatio": 0,
            "loadCount": 0,
            "batchLoadRatio": 0,
            "cacheHitCount": 0
          },
          "LD-com.shopline.pixiu.pcq.storefront.api.ProductStorefrontQueryV2Service-template": {
            "loadCount": 0,
            "loadErrorCount": 0,
            "batchLoadExceptionCount": 0,
            "loadErrorRatio": 0,
            "batchInvokeCount": 0,
            "batchLoadCount": 0,
            "batchLoadExceptionRatio": 0,
            "batchLoadRatio": 0,
            "cacheHitCount": 0,
            "cacheHitRatio": 0
          }
        },
        "overall-statistics": {
          "batchLoadExceptionCount": 0,
          "batchLoadRatio": 0,
          "cacheHitCount": 0,
          "cacheHitRatio": 0,
          "loadCount": 0,
          "loadErrorCount": 0,
          "loadErrorRatio": 0,
          "batchInvokeCount": 0,
          "batchLoadCount": 0,
          "batchLoadExceptionRatio": 0
        }
      },
      "metrics": {
        "dataFetcherMetrics": [
          {
            "dfErrorCode": null,
            "dfProtocol": "dubbo",
            "dfRootCoordinate": "/cookieGenerateByAccessToken",
            "dfRt": 123,
            "dfServiceIdentity": "com.shopline.ec.openapi.interfaces.CustomerStoreFrontV2Api@generateCookieByAccessToken",
            "dfStartTime": 1716948250368
          }
        ],
        "graphQLMetrics": {
          "clientIp": "157.119.232.37",
          "countryCode": null,
          "merchantId": "4200333804",
          "rt": 134,
          "endParseTimeMillis": 1716948250363,
          "ratelimitPermits": 1,
          "successType": "SUCCESS",
          "traceId": "93f9da3f1224ea1680caa3b9409b5954",
          "customizedClientIp": "157.119.232.37",
          "deepLevel": 3,
          "fieldCount": 29,
          "namespace": "storefront",
          "operation": "MUTATION",
          "startTimeMillis": 1716948250359,
          "loaderCount": 0,
          "parseRt": 4,
          "errorFieldsCount": 0,
          "executionId": "4de60267-b8b0-440f-872b-d41eb7519325",
          "ratelimitRemaining": 1,
          "startParseTimeMillis": 1716948250359,
          "storeId": "1671771213310",
          "storePlus": false,
          "tenant": "ec20",
          "appId": "264149",
          "includeDeprecatedField": false,
          "includeQuery": false,
          "languageCode": null,
          "version": "v20240601",
          "appKey": "ac46139a45013c6d13b3bdb53ba7b12b2af6d35f",
          "saleChannel": null
        }
      },
      "tracing": {
        "version": 1,
        "duration": 133754226,
        "endTime": "2024-05-29T02:04:10.493Z",
        "execution": {
          "resolvers": [
            {
              "returnType": "CookieGenerateByAccessTokenPayload",
              "startOffset": 8276898,
              "duration": 124036680,
              "fieldName": "cookieGenerateByAccessToken",
              "parentType": "Mutation",
              "path": [
                "cookieGenerateByAccessToken"
              ]
            },
            {
              "startOffset": 132563712,
              "duration": 27067,
              "fieldName": "uid",
              "parentType": "CookieGenerateByAccessTokenPayload",
              "path": [
                "cookieGenerateByAccessToken",
                "uid"
              ],
              "returnType": "ID"
            },
            {
              "path": [
                "cookieGenerateByAccessToken",
                "cookieDomainLevel"
              ],
              "returnType": "Int",
              "startOffset": 132653582,
              "duration": 17128,
              "fieldName": "cookieDomainLevel",
              "parentType": "CookieGenerateByAccessTokenPayload"
            },
            {
              "startOffset": 132737912,
              "duration": 14625,
              "fieldName": "maxAge",
              "parentType": "CookieGenerateByAccessTokenPayload",
              "path": [
                "cookieGenerateByAccessToken",
                "maxAge"
              ],
              "returnType": "Int"
            },
            {
              "path": [
                "cookieGenerateByAccessToken",
                "httpOnly"
              ],
              "returnType": "Boolean",
              "startOffset": 132788525,
              "duration": 14559,
              "fieldName": "httpOnly",
              "parentType": "CookieGenerateByAccessTokenPayload"
            },
            {
              "duration": 15535,
              "fieldName": "cookies",
              "parentType": "CookieGenerateByAccessTokenPayload",
              "path": [
                "cookieGenerateByAccessToken",
                "cookies"
              ],
              "returnType": "[CookieInfo]",
              "startOffset": 132921340
            },
            {
              "duration": 15481,
              "fieldName": "cookieKey",
              "parentType": "CookieInfo",
              "path": [
                "cookieGenerateByAccessToken",
                "cookies",
                0,
                "cookieKey"
              ],
              "returnType": "String",
              "startOffset": 133019704
            },
            {
              "parentType": "CookieInfo",
              "path": [
                "cookieGenerateByAccessToken",
                "cookies",
                0,
                "cookieValue"
              ],
              "returnType": "String",
              "startOffset": 133071551,
              "duration": 12292,
              "fieldName": "cookieValue"
            },
            {
              "duration": 13592,
              "fieldName": "cookieKey",
              "parentType": "CookieInfo",
              "path": [
                "cookieGenerateByAccessToken",
                "cookies",
                1,
                "cookieKey"
              ],
              "returnType": "String",
              "startOffset": 133171192
            },
            {
              "duration": 12914,
              "fieldName": "cookieValue",
              "parentType": "CookieInfo",
              "path": [
                "cookieGenerateByAccessToken",
                "cookies",
                1,
                "cookieValue"
              ],
              "returnType": "String",
              "startOffset": 133217487
            },
            {
              "startOffset": 133284481,
              "duration": 12897,
              "fieldName": "cookieKey",
              "parentType": "CookieInfo",
              "path": [
                "cookieGenerateByAccessToken",
                "cookies",
                2,
                "cookieKey"
              ],
              "returnType": "String"
            },
            {
              "fieldName": "cookieValue",
              "parentType": "CookieInfo",
              "path": [
                "cookieGenerateByAccessToken",
                "cookies",
                2,
                "cookieValue"
              ],
              "returnType": "String",
              "startOffset": 133326825,
              "duration": 13328
            },
            {
              "fieldName": "cookieKey",
              "parentType": "CookieInfo",
              "path": [
                "cookieGenerateByAccessToken",
                "cookies",
                3,
                "cookieKey"
              ],
              "returnType": "String",
              "startOffset": 133407634,
              "duration": 13593
            },
            {
              "duration": 12861,
              "fieldName": "cookieValue",
              "parentType": "CookieInfo",
              "path": [
                "cookieGenerateByAccessToken",
                "cookies",
                3,
                "cookieValue"
              ],
              "returnType": "String",
              "startOffset": 133455069
            },
            {
              "duration": 13603,
              "fieldName": "customerUserErrors",
              "parentType": "CookieGenerateByAccessTokenPayload",
              "path": [
                "cookieGenerateByAccessToken",
                "customerUserErrors"
              ],
              "returnType": "[CustomerUserError!]!",
              "startOffset": 133560072
            }
          ]
        },
        "parsing": {
          "duration": 3828853,
          "startOffset": 3947330
        },
        "startTime": "2024-05-29T02:04:10.359Z",
        "validation": {
          "duration": 938224,
          "startOffset": 5238576
        }
      }
    }
  }
}
```

## Error Handling

关于更多通用错误码说明，参考：[状态码和错误码](https://developer.shopline.com/zh-hans-cn/docs/apps/api-instructions-for-use/storefront-api/overview.md#status-and-error-codes)。

