Skip to content

Test Notifications doesn't work - httpStatusCode: 404, apiError: 4040008 #305

@farynaio

Description

@farynaio

I try to test provided examples with following code, it's wrapped with expressjs endpoint, also following wwdc2023 tutorial:

router.get('/test', async (req: Request, res: Response) => {
  try {
    const encodedKey = await readFile(
      `${kpiDir}/SubscriptionKey_F7M89F44D8_first.p8`,
      'utf8'
    )
    const client = new AppStoreServerAPIClient(
      encodedKey,
      Config.APPLE_KEY_ID,
      Config.APPLE_ISSUER_ID,
      Config.APPLE_BUNDLE_ID,
      environment
    )

    const testNotificationResponse = await client.requestTestNotification()

    const testNotificationResponseStatus =
      await client.getTestNotificationStatus(
        testNotificationResponse.testNotificationToken
      )

    console.log(
      `SendTestNotificationResponse response: ${JSON.stringify(testNotificationResponseStatus)}`
    )

    console.log(
      `SendTestNotificationResponse: ${testNotificationResponseStatus.signedPayload.substring(0, 20)}`
    )
  } catch (e) {
    console.error(e)
  }

  res.sendStatus(200)
})

But get this error, every time no matter if environment is SANDBOX or PRODUCTION:

APIException [Error]
    at AppStoreServerAPIClient.makeRequest (/app/node_modules/@apple/app-store-server-library/index.ts:167:23)
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async AppStoreServerAPIClient.getTestNotificationStatus (/app/node_modules/@apple/app-store-server-library/index.ts:271:16) {
  httpStatusCode: 404,
  apiError: 4040008,
  errorMessage: 'The test notification token is expired or the notification and status are not yet available.'
}

Is testing endpoint is disabled, or something is missing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions