Pass "id" and "duration" as part of request body via AWS API Gateway

I’m a beginner at development otherwise this would probably be easily solved for me. I’m working to build some integrations with services in my AWS account. I was able to create GET request and provide the Bearer Token for Authentication (Finally). Now i’m looking to do some PUT’s. To start simply, i’d just like to start a zone.

When making the PUT request, I get the following error.

{
  "code": "301",
  "error": "field name id required. Error message is invalid path"
}

And here are the logs I receive…

Execution log for request d4803b6a-5696-4782-8a29-8255ad5dadbf
Thu Mar 12 17:38:39 UTC 2020 : Starting execution for request: d4803b6a-5696-4782-8a29-8255ad5dadbf
Thu Mar 12 17:38:39 UTC 2020 : HTTP Method: PUT, Resource Path: /
Thu Mar 12 17:38:39 UTC 2020 : Method request path: {}
Thu Mar 12 17:38:39 UTC 2020 : Method request query string: {}
Thu Mar 12 17:38:39 UTC 2020 : Method request headers: {Authorization=**************************************3bc849}
Thu Mar 12 17:38:39 UTC 2020 : Method request body before transformations: 
Thu Mar 12 17:38:39 UTC 2020 : Endpoint request URI: https://api.rach.io/1/public/zone/start
Thu Mar 12 17:38:39 UTC 2020 : Endpoint request headers: {Authorization=**************************************3bc849, x-amzn-apigateway-api-id=fxdph0ang2, Accept=application/json, User-Agent=AmazonAPIGateway_fxdph0ang2, X-Amzn-Trace-Id=Root=1-5e6a739f-97890e14a730228bf4f9a3d7, Content-Type=application/json}
Thu Mar 12 17:38:39 UTC 2020 : Endpoint request body after transformations: {
"Authorization:": " Bearer **************************************3bc849",
}
Thu Mar 12 17:38:39 UTC 2020 : Sending request to https://api.rach.io/1/public/zone/start
Thu Mar 12 17:38:39 UTC 2020 : Received response. Status: 400, Integration latency: 96 ms
Thu Mar 12 17:38:39 UTC 2020 : Endpoint response headers: {Date=Thu, 12 Mar 2020 17:38:39 GMT, Content-Type=application/json;charset=utf-8, Content-Length=78, Connection=keep-alive, Server=nginx/1.12.1, Cache-Control=no-cache, no-store, max-age=0, must-revalidate, Pragma=no-cache, Expires=0, X-XSS-Protection=1; mode=block, X-Frame-Options=DENY, X-Content-Type-Options=nosniff, X-RateLimit-Limit=1700, X-RateLimit-Remaining=1676, X-RateLimit-Reset=2020-03-13T00:00:00Z}
Thu Mar 12 17:38:39 UTC 2020 : Endpoint response body before transformations: {"code":"301","error":"field name id required. Error message is invalid path"}
Thu Mar 12 17:38:39 UTC 2020 : Method response body after transformations: {"code":"301","error":"field name id required. Error message is invalid path"}
Thu Mar 12 17:38:39 UTC 2020 : Method response headers: {X-Amzn-Trace-Id=Root=1-5e6a739f-97890e14a730228bf4f9a3d7, Content-Type=application/json}
Thu Mar 12 17:38:39 UTC 2020 : Successfully completed execution
Thu Mar 12 17:38:39 UTC 2020 : Method completed with status: 200

Authorizing your request is not enough, you also need to pass the zone information within the POST request.

Now that you have a token, you need to get an account ID for which this token is valid. More on this request here:

Within this response, you will get an id, use it as part of the URL to get the list of devices for this account (replace “:id” with the value of id field you got from previous step):

Within the data returned, you will get a list of devices with a sublist for the zones which are part of that device. You can search for “e02de192-5a2b-4669-95c6-34deea3d23cb” above to see an example of a zone id.

Finally you need to generate a json string with the zone id and the duration you would like the zone to run and create a POST request to the zone start endpoint you’ve tried to use:

Here is an example of the json string you would need to generate and send to the endpoint as part of the POST request:

{ “id” : “d3e99d27-25e4-47dd-b354-1db5a84c99d7”, “duration” : 60 }

You can also start multiple zones with a same request, but all of those zones would need to be part of the same device (as far as I know).

1 Like

Thanks for the assist Gene. I am able to submit the request properly via curl or postman. I’m just not sure how to go about doing it with AWS API Gateway, it’s not very clear where you add the additional parameters.

Sorry, personally I’m not intimately familiar with AWS API Gateway, perhaps their forums (link) are a good place to ask about formatting of the POST request.

When you do find a solution, please take a minute to share it here as well. In case someone in the future would run into a similar problem.

Thank you,
Gene