question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Amplify API get request example for listing all items throws an error

See original GitHub issue

I followed all the steps in the official doc and when used the code in the example as below replacing the API name and path, it doesn’t return the list, instead it throws 404 error. I haven’t made any manual changes in the API or related Lambda function.

async getData() { 
    let apiName = 'MyApiName';
    let path = '/path';
    let myInit = { // OPTIONAL
        headers: {} // OPTIONAL
    }
    return await API.get(apiName, path, myInit);
}

getData();

But, if I pass an id of an existing record with the same request, it returns the object.

Ex.

async getData() { 
    let apiName = 'MyApiName';
    let path = '/path/<id>';
    let myInit = { // OPTIONAL
        headers: {} // OPTIONAL
    }
    return await API.get(apiName, path, myInit);
}

getData();

Is there a different way of loading all items?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:22 (1 by maintainers)

github_iconTop GitHub Comments

13reactions
sam-webchefcommented, Oct 9, 2018

Actually, I found out that it is required to add my own get method to scan the database. Added the following function in the app.js file of the Lambda Function. IT IS REQUIRED TO ADD THIS FUNCTION ABOVE OTHER get FUNCTIONS.

app.get('/<YOUR_PATH>', function (req, res) {
  var params = {
    TableName: tableName,
    Select: 'ALL_ATTRIBUTES',
  };
  dynamodb.scan(params, (err, data) => {
    if (err) {
      res.json({ error: 'Could not load items: ' + err.message });
    }
    res.json({
      data: data.Items.map(item => {
        return item;
      })
    });
  });
9reactions
mimeonlinecommented, Nov 2, 2019

Why is the issue is closed. The behavior is still present. I can’t get a collection of items without the fix which is described in this thread.

Read more comments on GitHub >

github_iconTop Results From Across the Web

API (REST) - Fetching data - JavaScript - AWS Amplify Docs
API status code response > 299 are thrown as an exception. If you need to handle errors managed by your API, work with...
Read more >
Cannot reach Amplify CLI-generated Express GET handler ...
So I've created this Amplify REST API with a route called /device . I generated the API with the CRUD function for DynamoDB...
Read more >
Troubleshooting and Common Mistakes - AWS AppSync
This section discusses some common errors and how to troubleshoot them. Incorrect DynamoDB Key Mapping. If your GraphQL operation returns the following ...
Read more >
HTTP status and error codes for JSON | Cloud Storage
Cloud Storage uses the standard HTTP error reporting format for the JSON API. Successful requests return HTTP status codes in the 2xx range....
Read more >
Batching Requests with AWS Amplify and AppSync
Think about the storefront for example: A store owner may need the ... If you're wanting to get up to speed on what...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found