您目前查看的是 Apigee 和 Apigee Hybrid 說明文件。
查看
Apigee Edge 說明文件。
InvalidIndex
錯誤訊息
透過 Apigee 使用者介面或 API 部署 API Proxy 時失敗,並顯示以下錯誤訊息:
Error in deployment for environment [environment] The revision is deployed, but traffic cannot flow. AssignMessage[policy_name]: index must be greater than zero in [attribute].[index]
錯誤訊息範例
Error in deployment for environment test.
The revision is deployed, but traffic cannot flow.
AssignMessage[GenerateStudentsRequest]: index must be greater than zero in id.0
螢幕截圖範例

原因
如果 Assign Message 政策的 <Copy> 和/或 <Remove> 元素中指定的索引為 0 或負數,API Proxy 的部署作業就會失敗。
舉例來說,如果您傳遞多個同名的查詢參數,可以將這些參數做為編列索引的流程變數存取。假設您想以查詢參數的形式傳遞 3 位學生的 ID,可以按照下列方式操作:
https://$EXTERNAL_IP/$PROXY_BASEPATH?school_name=NPS&id=1&id=2&id=3
接著,假設您嘗試在「指派訊息」政策中,使用索引編號 0、1 和 2 存取這些查詢參數,如下所示:
id.0
id.1 and
id.2
在本例中,由於索引必須從 1 開始,因此 Proxy 部署作業會失敗。也就是說,您可以將第一個查詢參數「id=1」存取為「id.1」。如要存取第二個查詢參數「id=2」,您需要使用索引 2,也就是「id.2」。同樣地,如要存取第三個查詢參數「id=3」,可以使用「id.3」。
詳情請參閱「AssignMessage 政策的 Copy 元素說明文件」。
診斷
找出發生錯誤的「指派訊息」政策、屬性名稱和無效索引。您可以在錯誤訊息中找到所有這些項目。舉例來說,在下列錯誤中,政策名稱為
GeneratingGeocodingRequest,屬性名稱為id,索引為0:AssignMessage[GenerateStudentsRequest]: index must be greater than zero in id.0確認失敗的「指派訊息」政策 XML 中使用的屬性名稱和索引,與錯誤訊息中識別的屬性名稱和索引 (上述步驟 1) 相符。舉例來說,下列政策會將屬性
id和索引指定為0,與錯誤訊息中的內容相符:<AssignMessage name="GenerateStudentsRequest"> <AssignTo createNew="true" type="request">StudentsInfoRequest</AssignTo> <Copy source="request"> <QueryParams> <QueryParam name="school_name"/> <QueryParam name="id.0"/> <QueryParam name="id.1"/> <QueryParam name="id.2"/> </QueryParams> </Copy> </AssignMessage>
如果指定的索引為 0 或負數,就會導致錯誤。
在上述「指派訊息」政策範例中,您嘗試使用索引 0 存取查詢參數「id」的第一個值。因此,API Proxy 部署作業會失敗,並顯示下列錯誤:
AssignMessage[GenerateStudentsRequest]: index must be greater than zero in id.0
解析度
在「指派訊息」中,當您存取多個共用相同名稱的標頭、查詢參數或其他參數時,請務必確保索引一律大於零。例如:
<AssignMessage name="GenerateStudentsRequest">
<AssignTo createNew="true" type="request">StudentsInfoRequest</AssignTo>
<Copy source="request">
<QueryParams>
<QueryParam name="school_name"/>
<QueryParam name="id.1"/>
<QueryParam name="id.2"/>
<QueryParam name="id.3"/>
</QueryParams>
</Copy>
</AssignMessage>
InvalidVariableName
錯誤訊息
透過 Apigee 使用者介面或 API 部署 API Proxy 時失敗,並顯示以下錯誤訊息:
Error Saving Revision [revision_number] The revision is deployed, but traffic cannot flow. AssignMessage schema validation failed: invalid variable name - null - in assign variable.
錯誤訊息範例
Error Saving Revision 3
AssignMessage schema validation failed: invalid variable name - null - in assign variable.
螢幕截圖範例

原因
如果子項元素 <Name> 為空,或未在 <AssignVariable> 元素中指定,API Proxy 部署作業就會失敗,因為沒有可指派值的有效變數名稱。必須提供有效的變數名稱。
診斷
檢查發生失敗的特定 API Proxy 中的所有指派訊息政策。如果任何「指派訊息」政策中的子元素 <Name> 為空,或未在 <AssignVariable> 元素中指定,就會導致錯誤。
範例 1:下列「指派訊息」政策未定義 <Name> 元素。
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-1">
<DisplayName>Assign Message-1</DisplayName>
<Properties/>
<AssignVariable>
<Value>abcd1234</Value>
</AssignVariable>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<AssignTo createNew="true" transport="http" type="request">googleBookReq</AssignTo>
</AssignMessage>
範例 2:下列「指派訊息」政策含有空白的 <Name> 元素。
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-1">
<DisplayName>Assign Message-1</DisplayName>
<Properties/>
<AssignVariable>
<Name></Name>
<Value>abcd1234</Value>
</AssignVariable>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<AssignTo createNew="true" transport="http" type="request">googleBookReq</AssignTo>
</AssignMessage>
解析度
請確保在「指派訊息」政策的 <AssignVariable> 元素中,一律指定非空白的子項元素 <Name>。例如:
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-1"> <DisplayName>Assign Message-1</DisplayName> <Properties/> <AssignVariable> <Name>appSecret</Name> <Value>abcd1234</Value> </AssignVariable> <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables> <AssignTo createNew="true" transport="http" type="request">googleBookReq</AssignTo> </AssignMessage>