Messenger Platform · error code

Messenger error 2018166: Permission not valid to call the SDK API

ConfigurationPermissions, app review & thread control

Last verified against Meta for Developers - Messenger Platform error codes

What Messenger returns
Permission not valid to call the SDK API

What error 2018166 means

Code 2018166 is a Messenger Extensions SDK error: "Permission not valid to call the SDK API." The SDK separates what a webview page can do freely from what requires the person's consent, and it exposes askPermission() to request permission "to do things like retrieve a person's profile information" and getGrantedPermissions() to check what has already been granted. This error means the page called something without a valid permission for it.

The permission in question lives at the person level inside the Messenger client, not in your app's App Review status. That is why it can fail for one user and work for another on the same day with the same deployment: one person granted the permission, the other declined or was never asked.

Do not confuse it with 2018247, the server-side User Profile API error for fields your app lacks access to, or with code 10 on the Graph API. The fix here is a client-side permission request, followed by handling refusals gracefully.

What it looks like

MessengerExtensions.getGrantedPermissions(
  function success(response) { /* response.permissions */ },
  function error(err) { /* error code, e.g. 2018166 */ }
);

Why it happens

  • Calling an SDK method that needs a permission the person has not granted.
  • Skipping askPermission() and assuming permissions from an earlier session still apply.
  • The person declining the permission prompt.
  • Using a permission name that does not match what the SDK expects.

How to fix Messenger error 2018166

  1. 1Call getGrantedPermissions() first and branch on the result.
  2. 2Request the missing permission with askPermission() in response to a user action.
  3. 3Handle a declined prompt by continuing without the protected data.
  4. 4Check the permission names against the Messenger Extensions SDK reference.
  5. 5Log the method name with the error so you know which call needs the permission.

How to stop it recurring

Check before you call: wrap every permission-gated SDK method in a helper that inspects granted permissions, asks if needed, and returns a clear "not available" result instead of throwing. Ask at the moment the person understands why, not on page load, and design the webview so declining still leaves a usable flow.

Official reference: Meta for Developers - Messenger Platform error codes. See all Messenger error codes or the Messenger limits and quotas.

Related codes

Error 2018166 - quick answers

What does Messenger error 2018166 mean?

Code 2018166 is a Messenger Extensions SDK error: "Permission not valid to call the SDK API." The SDK separates what a webview page can do freely from what requires the person's consent, and it exposes askPermission() to request permission "to do things like retrieve a person's profile information" and getGrantedPermissions() to check what has already been granted.

How do I fix Messenger error 2018166?

1. Call getGrantedPermissions() first and branch on the result. 2. Request the missing permission with askPermission() in response to a user action. 3. Handle a declined prompt by continuing without the protected data. 4. Check the permission names against the Messenger Extensions SDK reference. 5. Log the method name with the error so you know which call needs the permission.

Stop debugging Messenger by hand

Connect the channel through Conferbot: tokens, webhooks and retries are handled, failures show as readable status.