ETLMCPData Conveyance Works
Log in Start free
Guides

Why Microsoft Ads connections drop

Why Microsoft Advertising refuses a stored sign-in with invalid_grant after a password change or revoked consent, and how one reconnect fixes it.

Coming This connector is coming.

A Microsoft Advertising connection drops when Microsoft stops honoring the refresh token behind it. Microsoft says a refresh token can be invalidated at any moment, and names the usual triggers: the person who connected changed their password, removed a device from their trusted devices, or withdrew the app's permission. Microsoft can also decide on its own, with no warning, that consent has to be given again. In each case the token endpoint answers invalid_grant, and the only fix is for someone to sign in again. When the Microsoft connector is available in etlmcp, that is one press of Reconnect on the sources page.

What Microsoft says about token lifetimes

  • Access tokens are short-lived. The token response gives their life in seconds as expires_in, about an hour in Microsoft's own examples, and an app is expected to refresh before they run out.
  • Refresh tokens have no fixed lifetime. They usually last a long time, and the guide gives 90 days for public clients as an example, but it tells apps not to count on any period.
  • The only way to learn whether a refresh token still works is to try it. A failed attempt returns invalid_grant with a description saying the sign-in could not be verified or the grant has run out.
  • When a refresh returns a new refresh token, the app should keep the new one and discard the old.

Microsoft's error-handling guide adds a few more causes of invalid_grant: a refresh token that expired, a refresh that asks for a scope the user never consented to, and a token that was revoked some other way.

Multi-factor authentication and the msads.manage scope

From June 1, 2022, Microsoft began requiring multi-factor authentication, step by step, for people who sign in to the Microsoft Advertising API through third-party applications. To comply, an app has to ask for consent with the msads.manage scope, and every user has to give that consent again, whether or not they had already turned MFA on. Once MFA is enforced, the API refuses access tokens that were issued or refreshed without msads.manage. Older grants made with ads.manage, or with bingads.manage through the Live Connect endpoint, which Microsoft has deprecated, stop working.

The person who connects Microsoft Advertising completes a second verification step at sign-in, so set up an MFA method on that login before you connect.

What etlmcp does with your Microsoft sign-in

When the connector is available, it signs in through the Microsoft identity platform and asks for two scopes: msads.manage, the only scope that reaches the Ads API, and offline_access, the same pair Microsoft's own token example requests. It sends msads.manage again on every refresh, so a renewed token is never one the API will refuse for its scope. The sign-in page always asks which Microsoft account to use, so a browser already signed in as someone else does not connect the wrong login by accident.

During a sync on an available connector, etlmcp refreshes the access token shortly before it runs out. When Microsoft returns a new refresh token with the renewed access token, etlmcp stores it in place of the old one, as Microsoft asks.

If the Ads API rejects a token mid-sync (error 105 or 109), etlmcp refreshes once and tries the call again. Microsoft's own guide notes that error 105 can also mean a wrong developer token or a production and sandbox mix-up, which no reconnect can fix. When a refreshed token is still refused with a bare 105, etlmcp fails that run as a setup problem on the etlmcp side and does not ask you to reconnect.

When the refresh token is refused

When the connector is available and Microsoft answers a refresh with invalid_grant, or another code that says consent must be given again, etlmcp stops asking. The run fails with Microsoft Advertising needs reconnecting and is not retried, because waiting will not bring the grant back. etlmcp marks the connection and every account on it as needing a reconnect, shows the reason access was revoked or has expired on the sources page, and emails your organization's owners once, with the subject "Reconnect Microsoft Advertising".

The scheduler skips its pipelines until you reconnect. See source states for what each state blocks.

How to reconnect

Once the connector is available:

  1. Open Sources in the app and press Reconnect next to the Microsoft Advertising connection.
  2. Sign in with the same Microsoft login that made the original connection and complete the MFA prompt. A different login changes nothing, and the page says Reconnect with the original login.
  3. Grant the permission Microsoft asks for. etlmcp then checks every account on the connection again.

You do not need to backfill the days the connection was down. The first scheduled sync after a reconnect starts where the last successful sync's window started, so it covers the gap. Routine Microsoft syncs re-pull the last 31 days in any case.

Keeping the connection alive

  • Connect with a Microsoft login that belongs to your company and will stay, not with a personal login of someone who may leave or change jobs.
  • After a password reset on that login, reconnect right away instead of waiting for the next failed sync.
  • Do not remove etlmcp from the login's list of apps with access: that withdraws consent.

For the other Microsoft errors a run can end with, see Microsoft Advertising connector errors. The general reconnect flow for every platform is on needs reconnecting.

Related

Sources

  1. Get access and refresh tokens - Microsoft Advertising API — learn.microsoft.com, checked
  2. Multi-factor authentication requirement - Microsoft Advertising API — learn.microsoft.com, checked
  3. Handling Service Errors and Exceptions - Microsoft Advertising API — learn.microsoft.com, checked