amplify-js: Uncaught (in promise) Api does not exist

So I’m trying to use API gateway to put data to the table in the database. I’m using vue.js and whenever I run this function I get an error: Uncaught (in promise) API scenariosCRUD does not exist even if API name is certainly correct.

Here’s my function: post: async function () {

      console.log('adding data to database');
      const response = await API.post('scenariosCRUD', '/scenarios', {
        body: {
          ScenarioId: 1,
          ScenarioName: 'test',
          Graph: {},
          UserId: 1234,
          ConfigurationId: 1234,
        },
      });
      alert(JSON.stringify(response));
    }

`

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 30 (4 by maintainers)

Most upvoted comments

Hey i know its been a long time, but i got this issue recently and managed to solve it by importing the aws-export.js file: import awsConfig from ‘./aws-export.js’ and then API.configure(awsConfig). Hope it still helps 😃

If you look into your aws-exports.js, do you see your API with the very same key (scenariosCRUD )?

Hey i know its been a long time, but i got this issue recently and managed to solve it by importing the aws-export.js file: import awsConfig from ‘./aws-export.js’ and then API.configure(awsConfig). Hope it still helps 😃

This is definitely a workaround but not a solution. I’d like to request this issue be re-opened. I am using aws-amplify 3.3.23, and my code only works by

import Amplify, { API } from 'aws-amplify';
import awsconfig from './aws-exports';

// Amplify init
Amplify.configure(awsconfig);
API.configure(awsconfig);

Otherwise I get an error saying api <api-name> does not exist

I had the same issue surface on a project I had been working for a few months now which had no previous issues with the API.

I was previously configuring Amplify as follows:

Amplify.configure({
  Auth: {
    // REQUIRED - Amazon Cognito Identity Pool ID
    identityPoolId: config.aws_cognito_identity_pool_id,
    // REQUIRED - Amazon Cognito Region
    region: config.aws_cognito_region,
    // OPTIONAL - Amazon Cognito User Pool ID
    userPoolId: config.aws_user_pools_id,
    // OPTIONAL - Amazon Cognito Web Client ID (26-char alphanumeric string)
    userPoolWebClientId: config.aws_user_pools_web_client_id
  },
  API: {
    endpoints: [
      {
        name: 'prod',
        endpoint: '********************',
        custom_header: async () => {
          return { Authorization: `Bearer ${(await Auth.currentSession()).getIdToken().getJwtToken()}` }
        }
      },
      {
        name: 'local',
        endpoint: 'http://127.0.0.1:*******'
      },
      {
        name: '***',
        endpoint: '******************************'
      }
    ],
    aws_appsync_graphqlEndpoint: config.aws_appsync_graphqlEndpoint,
    aws_appsync_region: config.aws_appsync_region,
    aws_appsync_authenticationType: config.aws_appsync_authenticationType

  }
})

This setup was working for me for about 6 months, until a few days the error in this issue resurfaced.

I have used @IsaacTrevino 's solution, but that’s not covering the AppSync API, I’m still getting errors on that API.

@haverchuck Please re-open this issue so that it can be addressed