0

Identical question here.

I'm invoking an Azure Logic App job via the Azure API. I need to be able to follow up and get the status of the job to know whether it succeeds or fails.

The answer to post above helpfully points to the Workflow Runs - Get API. That looks like just what I need. However, to get the status of the run, I need the runName (sounds like request id?). But when I submit the initial request to the Azure API, I don't get a runName or job id. I just get <Response [202]>. So, I can't subsequently request the status of the run.

To be clear, I'm invoking the logic app by calling the HTTP POST url provided by the trigger of the Logic App. Looks like this:

https://prod-00.northcentralus.logic.azure.com:443/workflows/DELETED/triggers/manual/paths/invoke?api-version=2016-10-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=DELETED

The response to that endpoint is the Response [202] mentioned above. No run name provided.

Any pointers would be appreciated!

208_man
  • 1,440
  • 3
  • 28
  • 59

1 Answers1

1

You do not get the workflow name when you trigger the logic app. You will see it in the response of the Getworkflow list API call. So you can get the workflow list with a filter on date and time and then fire the get workflow runs API call. To call the API, you will need a bearer token. First register an app/service principal with Azure AAD (Link). Give the app/service principal the proper role on the Logic app. You can give a Reader role. Then make a call to the https://login.microsoftonline.com/<tenant_id>/oauth2/token endpoint to fetch the bearer token. You will need the tenant id, client id and client secret. See the snapshot for reference. enter image description here

Add the bearer token under a Authorization header when making the Logic app API call.
enter image description here

But maybe you can check and confirm the necessity of triggering the logic app asynchronously. Instead you can trigger the logic app synchronously. For this you will need to make some changes in the Logic app itself. You can refer to this SO response to get an idea on how to do this.

With this change, you will not need to check the status. You will get a response as soon as the Logic app completes. Of course this depends on how long the Logic app roughly runs for.

Anupam Chand
  • 2,209
  • 1
  • 5
  • 14
  • Thank you very much @anupam-chand. I've been experimenting with making the logic app synchronous. it seems that simply adding a success response operator to the end of the success path and a fail response operator to the end of the fail path. However when I run the app (which calls two runbooks in succession) it seems to tell the caller "all done" after just running the first runbook. Actually it gets 504 from Azure. A bit baffled bc 504 means time out but it hasn't yet reached the caller's 15 min timeout limit. – 208_man Dec 10 '21 at 00:12
  • 1
    Without knowing what your 2 runbooks are doing and how they are called it will be impossible to advise on this. How long does each workflow run for approximately? When you say calls 2 runbooks in succession do you mean 1 calls the other or your app calls one, receives a success response then calls the other? each call should be treated as a separate call correct? – Anupam Chand Dec 10 '21 at 02:12
  • Thanks @anupam_chand. I realized the problem is that azure times out after 120 seconds. Now I'm trying to simply 1) submit asynchronously and then 2) use getworkflow list (like you suggest) to get status updates. But I can't figure out the authentication. The docs just mention 'Azure Active Directory OAuth2 Flow' and 'impersonate'. But the example doesn't explain how to use that. I'll be digging around for understanding that piece. Thanks if you have any tips. – 208_man Dec 10 '21 at 20:28
  • 1
    Check my modified answer. You can use a bearer token. First you need to register an app , assign the Logic app reader role, fetch the bearer token and then make the Logic app API call. – Anupam Chand Dec 11 '21 at 02:26
  • Thanks @anupam-chand. I tried that. Now I get an error saying `Invalid tenant id provided. You can locate your tenant id by following the instructions here: https://learn.microsoft.com/partner-center/find-ids-and-domain-names` this is interesting because the same tenant id works elsewhere. I suspect it is a misleading error msg. Thanks for all your input on this! – 208_man Dec 13 '21 at 14:47
  • A screen shot of the curl command or api call will help to advise on your issue. – Anupam Chand Dec 13 '21 at 16:50