Search code examples
active-directorysasoffice365power-automate

Fail to call "When a HTTP request is received" Power Automate flow which has "Specific users in my tenant" from our code


I have created a power automate flow using the "When a HTTP request is received", and i defined that it can only be called using 2 service accounts (the 2 service accounts are internal users inside our office 365 tenant):-

![enter image description here

now when we tried to call this workflow end point from our code:-

HttpRequest req = new HttpRequest();
        req.setEndpoint('
https://prod-10.westus.logic.azure.com:443/workflows/******/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=******');
        req.setMethod('POST');
        req.setHeader('Content-Type','application/json');
        req.setHeader('Authorization', 'Bearer '+ accessToken);
        Map<String, String> reqBody = new Map<String, String>{
******
                };
        req.setBody(JSON.serialize(reqBody));
        HttpResponse res = new Http().send(req);
        system.debug('Power automate status code ----> ' + res.getStatusCode());
        system.debug('Power automate body -----> '+ res.getBody());
 

we got this error :-

{"code":"DirectApiRequestHasMoreThanOneAuthorization","message":"The request has SAS authentication scheme, 'Bearer' authorization scheme or internal token scheme. Only one scheme should be used."}}
  

any advice on this please? now if we define that anyone can call the flow, the flow will be called correctly without issues.


Solution

  • I think the following link may be used for the detailed procedure.

    https://www.bythedevs.com/post/securing-when-an-http-request-is-received-trigger-in-power-automate-part-2