[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-01。"],[],[],null,["# API code samples\n\nThis page contains code samples for the Google Spectrum Access System (SAS) Portal API.\n\nBefore you begin\n----------------\n\nFor the following examples, ensure that you complete the following prerequisites:\n\n- [Obtain a token with your service account](/spectrum-access-system/docs/authorization-and-authentication) `TOKEN=$(gcloud auth print-access-token)`.\n- Set \u003cvar translate=\"no\"\u003e${CLIENT_PROJECT}\u003c/var\u003e to the project ID of the Google Cloud project.\n\nList current customers\n----------------------\n\n1. Return all of the customers that the caller has access to:\n\n ```\n curl -X GET -H \"X-Goog-User-Project: ${CLIENT_PROJECT}\" \\\n -H \"Content-Type: application/json\" \\\n -H \"Authorization: Bearer ${TOKEN}\" \\\"https://sasportal.googleapis.com/v1alpha1/customers\"\n ```\n2. Save the customer name that is returned as a variable:\n\n ```\n CUSTOMER_NAME=customers/...\n ```\n\nCreate a new device configuration\n---------------------------------\n\n1. Set the \u003cvar translate=\"no\"\u003e${FCCID}\u003c/var\u003e and \u003cvar translate=\"no\"\u003e${SN}\u003c/var\u003e of the device\n that you want to create:\n\n ```\n FCCID=f1\n SN=sn1\n ```\n2. Create the device configuration:\n\n ```\n curl -X POST -H \"X-Goog-User-Project: ${CLIENT_PROJECT}\" \\\n -H \"Content-Type: application/json\" \\\n -H \"Authorization: Bearer ${TOKEN}\" \\ \"https://sasportal.googleapis.com/v1alpha1/${CUSTOMER_NAME}/devices\" \\\n -d \"{ \\\"fcc_id\\\": \\\"$FCCID\\\", \\\"serial_number\\\": \\\"$SN\\\", \\\"preloaded_config\\\": { \\\"call_sign\\\": \\\"cs1\\\", \\\"category\\\": \\\"DEVICE_CATEGORY_A\\\"}}\"\n ```\n\n The command returns a newly created device configuration.\n3. Save the device name as a variable:\n\n ```\n DEVICE_NAME=customers/.../devices/...\n ```\n\nList current devices\n--------------------\n\n```\ncurl -X GET -H \"X-Goog-User-Project: ${CLIENT_PROJECT}\" \\\n -H \"Content-Type: application/json\" \\\n -H \"Authorization: Bearer $TOKEN\" \\ \"https://sasportal.googleapis.com/v1alpha1/${CUSTOMER_NAME}/devices\"\n```\n\nRetrieve devices by name\n------------------------\n\n```\ncurl -X GET -H \"X-Goog-User-Project: ${CLIENT_PROJECT}\" \\\n -H \"Content-Type: application/json\" \\\n -H \"Authorization: Bearer $TOKEN\" \\\n \"https://sasportal.googleapis.com/v1alpha1/${DEVICE_NAME}\"\n```\n\nUpdate an existing device\n-------------------------\n\n```\ncurl -X PATCH -H \"X-Goog-User-Project: ${CLIENT_PROJECT}\" \\\n -H \"Content-Type: application/json\" \\\n -H \"Authorization: Bearer $TOKEN\" \\\n \"https://sasportal.googleapis.com/v1alpha1/${DEVICE_NAME}\" \\\n```\n\nValidate your Certified Professional Installer (CPI) identity and certification\n-------------------------------------------------------------------------------\n\n1. Generate the secret string:\n\n ```\n curl -X POST -H \"X-Goog-User-Project: ${CLIENT_PROJECT}\" \\\n -H \"Content-Type: application/json\" \\\n -H \"Authorization: Bearer $TOKEN\" \\ \"https://sasportal.googleapis.com/v1alpha1/installer:generateSecret\" \\\n -d \"{}\"\n ```\n\n The output is similar to the following: \n\n ```\n {\n \"secret\": \"\u003cgenerated secret\u003e\"\n }\n ```\n2. Use the [JSON Web Token format](/spectrum-access-system/docs/json-web-token-format)\n to encode the secret string into a JWT.\n\n3. Set the following:\n\n 1. \u003cvar translate=\"no\"\u003e${SECRET}\u003c/var\u003e to the secret string\n 2. \u003cvar translate=\"no\"\u003e${ENCODED_SECRET}\u003c/var\u003e to the JWT string\n 3. \u003cvar translate=\"no\"\u003e${CPI_ID}\u003c/var\u003e to the ID of the CPI\n4. Validate the identity and certification of the CPI:\n\n ```\n curl -X POST -H \"X-Goog-User-Project: ${CLIENT_PROJECT}\" \\\n -H \"Content-Type: application/json\" \\\n -H \"Authorization: Bearer $TOKEN\" \\ \"https://sasportal.googleapis.com/v1alpha1/installer:validate\" \\\n -d \"{ \\\"installer_id\\\": \\\"${CPI_ID}\\\", \\\"secret\\\": \\\"${SECRET}\\\", \\\"encoded_secret\\\": \\\"${ENCODED_SECRET}\\\" }\"\n ```\n\nNow the CPI can install a Citizens Broadband Radio Service Device (CBSD) that has all the required parameters.\n\nMultistep CBSD registration\n---------------------------\n\nYou can perform multistep CBSD registration with device parameters\npreviously signed by a CPI or with a CPI account.\n\n### Device parameters previously signed by a CPI\n\nThis sample shows how to create an inactive device configuration with\nCBSD installation parameters previously encoded by a CPI. As a\nresult, the non-CPI users can also create the configuration.\n\n1. Use the CPI's private key to encode the CBSD parameters. We recommend that you use the [JSON Web Token format](/spectrum-access-system/docs/json-web-token-format).\n2. Set \u003cvar translate=\"no\"\u003e${ENCODED_DEVICE}\u003c/var\u003e to the JWT string and \u003cvar translate=\"no\"\u003e${CPI_ID}\u003c/var\u003e to the ID of the CPI.\n3. Create the inactive device configuration:\n\n ```\n curl -X POST -H \"X-Goog-User-Project: ${CLIENT_PROJECT}\" \\\n -H \"Content-Type: application/json\" \\\n -H \"Authorization: Bearer ${TOKEN}\" \\ \"https://sasportal.googleapis.com/v1alpha1/${CUSTOMER_NAME}/devices:createSigned\" \\\n -d \"{ \\\"installer_id\\\": \\\"${CPI_ID}\\\", \\\"encoded_device\\\": \\\"${ENCODED_DEVICE}\\\", \\\"parent\\\": \\\"${CUSTOMER_NAME}\\\" }\"\n ```\n\nThe CBSD must then send a registration request to SAS to complete its registration.\n\n### CPI account\n\nThe CPI's identity must be validated *before* you [validate](/spectrum-access-system/docs/validate-cpi-identity)\na device configuration. When that is done, use the following command to create an inactive device configuration: \n\n```\n curl -X POST -H \"X-Goog-User-Project: ${CLIENT_PROJECT}\" \\\n -H \"Content-Type: application/json\" \\\n -H \"Authorization: Bearer $TOKEN\" \\ \"https://sasportal.googleapis.com/v1alpha1/${DEVICE_NAME}:signDevice\" \\\n -d \"${DEVICE}\"\n```\n\nReplace \u003cvar translate=\"no\"\u003e${DEVICE}\u003c/var\u003e with the JSON representation of the\nCBSD registration parameters. For more information about the\nformat, see [REST Resource: customers.devices](/spectrum-access-system/docs/reference/rest/customers.devices).\n\nThe CBSD must then send a registration request to SAS to complete its registration.\n\nWhat's next\n-----------\n\n- To get an overview of the SAS Portal API, see [Google SAS Portal API overview](/spectrum-access-system/docs/overview-api).\n- For information about each API, see [Customers API](/spectrum-access-system/docs/customers-api) and [Device Manager API](/spectrum-access-system/docs/device-manager-api).\n- For reference documentation, see [APIs and reference](/spectrum-access-system/docs/apis)."]]