Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Input is not valid error when I call POST API #101

Open
Rcyyy opened this issue Jan 29, 2024 · 0 comments
Open

Input is not valid error when I call POST API #101

Rcyyy opened this issue Jan 29, 2024 · 0 comments

Comments

@Rcyyy
Copy link
Contributor

Rcyyy commented Jan 29, 2024

I encountered an issue when calling the API of cloudfront. I called a POST API and got a 400 http error code. I print the log of request body in the execute.lua:

<?xml version="1.0" encoding="UTF-8"?>
<input>
  <ResponseHeadersPolicyConfig xmlns="http://cloudfront.amazonaws.com/doc/2020-05-31/">
    <Name>cdn_test</Name>
    <CorsConfig>
      <AccessControlAllowMethods>
        <Items>
          <Method>GET</Method>
          <Method>POST</Method>
        </Items>
        <Quantity>2</Quantity>
      </AccessControlAllowMethods>
      <AccessControlAllowCredentials>false</AccessControlAllowCredentials>
      <AccessControlMaxAgeSec>600</AccessControlMaxAgeSec>
      <AccessControlAllowHeaders>
        <Items>
          <Header>*</Header>
        </Items>
        <Quantity>1</Quantity>
      </AccessControlAllowHeaders>
      <OriginOverride>true</OriginOverride>
      <AccessControlAllowOrigins>
        <Items>
          <Origin>*</Origin>
        </Items>
        <Quantity>1</Quantity>
      </AccessControlAllowOrigins>
    </CorsConfig>
    <CustomHeadersConfig>
      <Items>
        <ResponseHeadersPolicyCustomHeader>
          <Override>true</Override>
          <Value>rcy</Value>
          <Header>name</Header>
        </ResponseHeadersPolicyCustomHeader>
      </Items>
      <Quantity>1</Quantity>
    </CustomHeadersConfig>
  </ResponseHeadersPolicyConfig>
</input>

And the response body returned by AWS server:

<?xml version="1.0"?>
<ErrorResponse xmlns="http://cloudfront.amazonaws.com/doc/2020-05-31/">
    <Error>
        <Type>Sender</Type>
        <Code>MalformedInput</Code>
        <Message>input is not valid, expected ResponseHeadersPolicyConfig</Message>
    </Error>
    <RequestId>cd10f090-22eb-41b3-94df-4264f9d45402</RequestId>
</ErrorResponse>

Then I checked the AWS REST API document, just found that request body shouldn't have the root input tag.
The input tag come from the raw-api api-description files. After I changed the code to remove the input tag, the call succeed.

build.lua#232
    -- encode rest of the body data here
    -- poor_mans_xml_encoding(xml_data, operation.input, "input", body_tbl)

    for name, member in pairs(operation.input.members) do
      if body_tbl[name] then
        poor_mans_xml_encoding(xml_data, member, name, body_tbl[name], 0)
      end
    end

But I'm not sure if I missed something else.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant