Meta APIs

Implementing Meta's Data Deletion Callback the Right Way

Implementing Meta's Data Deletion Callback the Right Way

Every app that uses Facebook Login needs a way for users to delete their data. How I build the data deletion callback, status page, and backend job behind it.

Data deletion instructions URL vs data deletion callback

Meta requires apps that use Facebook Login to give users a way to delete their data. An app can provide either a data deletion instructions URL or a data deletion callback URL. Instructions are a page explaining how users can request deletion. A callback is an endpoint Meta calls when a user removes the app and requests deletion of their data.

For products I build, I prefer the callback because it turns a manual support request into an automated, auditable workflow. It also makes the privacy policy simpler, because the deletion process is concrete.

How Meta's data deletion callback works

  • Meta sends a POST request to your callback URL with a form parameter called signed_request.
  • The signed request has two base64url-encoded parts separated by a dot: a signature and a JSON payload.
  • The backend verifies the HMAC-SHA256 signature of the payload using the app secret.
  • The payload contains the app-scoped user ID of the person requesting deletion.
  • The backend schedules deletion and responds with JSON containing a status URL and a confirmation code.

Verifying the signed_request in Python

This is a minimal FastAPI-style example. The important parts are the constant-time signature comparison and the fact that no data is deleted inside the request.

import base64, hashlib, hmac, json, secrets

def b64url_decode(value: str) -> bytes:
    return base64.urlsafe_b64decode(value + "=" * (-len(value) % 4))

def parse_signed_request(signed_request: str, app_secret: str) -> dict:
    encoded_sig, payload = signed_request.split(".", 1)
    expected = hmac.new(app_secret.encode(), payload.encode(), hashlib.sha256).digest()
    if not hmac.compare_digest(b64url_decode(encoded_sig), expected):
        raise ValueError("invalid signature")
    data = json.loads(b64url_decode(payload))
    if data.get("algorithm", "").upper() != "HMAC-SHA256":
        raise ValueError("unexpected algorithm")
    return data

@app.post("/meta/data-deletion")
async def data_deletion(signed_request: str = Form(...)):
    data = parse_signed_request(signed_request, settings.META_APP_SECRET)
    code = secrets.token_urlsafe(12)
    await deletion_requests.create(user_id=data["user_id"], code=code)
    await queue.enqueue("delete_meta_user_data", data["user_id"], code)
    return {"url": f"https://example.com/deletion-status?code={code}",
            "confirmation_code": code}

Designing the deletion job

The callback stores a deletion request record with the confirmation code and pushes a job to a background queue. The worker removes data linked to that user, then marks the request as completed. This keeps the endpoint fast and makes retries safe.

  • Revoke and delete stored access tokens first, so nothing new is fetched during deletion.
  • Delete profile data, messages, comments, and cached media linked to the app-scoped user ID.
  • Make the job idempotent, so a repeated request for the same user does not fail.
  • Log what categories were deleted and when, without logging the deleted content.
  • Keep only what the law requires you to retain, and document that in the privacy policy.

Building the deletion status page

The status URL returned to Meta should open a simple public page where the user can see whether deletion is pending or complete for their confirmation code. It needs no login. Show the code, the status, and the date of completion. Reviewers do check that this page exists and loads, so include it in your App Review checklist.

Testing the callback before App Review

  • Generate a signed request in a test using your app secret and confirm the endpoint accepts it.
  • Send a request with a modified payload and confirm it is rejected.
  • Confirm the response is valid JSON with url and confirmation_code fields.
  • Run the worker against test data and confirm every related table is cleaned up.
  • Open the status URL in a private window and confirm it loads without login.

Common mistakes with data deletion callbacks

  • Verifying the signature against the decoded JSON instead of the raw base64url payload string.
  • Using a normal string comparison instead of a constant-time comparison for the signature.
  • Deleting data synchronously and timing out on users with large histories.
  • Returning a status URL that requires login or returns a 404 for unknown codes.
  • Deleting only the user record while leaving messages, media, or tokens in other tables.
  • Forgetting that one person may have connected several Pages, Instagram accounts, or tenants.

I write an automated test for each of these cases. Data deletion is rarely exercised in normal use, so tests are the only reliable way to know it still works after schema changes.

Handling deauthorization separately

Meta also supports a deauthorize callback, called when a user removes the app. Deauthorization does not always mean the user wants their data deleted, but it does mean the tokens are no longer valid. I mark the integration as disconnected, stop background jobs for that user, and keep data only as long as the privacy policy allows.

Frequently asked questions

Is the data deletion callback required?

Apps using Facebook Login must provide either a data deletion callback URL or a data deletion instructions URL. The callback is optional if you provide clear instructions instead.

What user ID does Meta send?

The payload contains the app-scoped user ID, which is the same ID your app received when the user logged in.

Should I delete data inside the callback request?

No. Store the request, queue a background job, and respond quickly. This avoids timeouts and makes retries safe.

Does the status page need authentication?

No. It should be publicly reachable with the confirmation code so users and reviewers can check the status.