Microsoft Graph API, Region is required when request with application permission - azure

I am trying to access Microsoft Graph API to search the list items present in tenant. I am having no problem when GET request is executed for users or groups.
When I post the request for search using HttpClient as described on MS site. I am getting below error.
Failed to call the web API: BadRequest
Content: {"error":{"code":"System.Exception","message":"SearchRequest Invalid (Region is required when request with application permission.)\r\nRegion is required when request with application permission.","target":"","details":null,"warnings":null,"level":"Error","httpCode":400},"Instrumentation":{"TraceId":null}}
I tried with .Net core as well. same error.
If i paste access code on HTML file, calling api for search using Ajax is working fine.
what code i am missing in my c# code.

The reason should be this endpoint you use not support application permission.
Usually this error message is encountered, indicating that application permission is not supported, you can use delegated permissions.

Related

Calling Azure CDN Purge's REST API from Flow returns Unauthorized

I want to purge an Azure CDN endpoint from Microsoft Flow. The CDN Profile's Pricing Ties is Standard Verzion.
I have created a Microsoft Flow with an HTTP - HTTP action.
I used an URL generated by the tool shown by clicking on Try it on https://learn.microsoft.com/en-us/rest/api/cdn/endpoints/purgecontent and filling the necessary fields.
I want to purge all CDN content so I put the following as a body (I hope this is the right way as the official docs were silent about this use case).
{
"contentPaths": [
"/*"
]
}
I have created a Registered application in the Azure Active Directory and used that to fill in Active Directory OAuth fields of the HTTP - HTTP action. I presume that the OAuth authentication is succeeding as if I put wrong values in any of the fields I get a respective error message.
So the HTTP - HTTP action is filled as on the following image. The image mostly shows where I got the values I used on the real flow.
When I run the flow it fails and shows just Unauthorized. inside the failed HTTP - HTTP action.
I have tried to add the app as a Contributor role of the CDN Profile but the error stayed the same.
How to get it working?
According to the error message, it seems that you missed the access token in the request.
If you want to generate the token for your azure ad app(service principal), you could refer to this article and the thread of generating the access token via postman.
Also, you could try to add the app as a role in the logic app.

Authentication within Azure cloud

I'm trying to implement authentication to my web API. I need to firstly authenticate one user to access some methods. I use the Azure AD, an automatic tool in Azure. The problem is that when I try it in Soap UI, I get the error bellow:
Org.apache.xmlbeans.XmlException: org.apache.xmlbeans.XmlException:
Error: Unexpected element: CDATA
And I guess the problem is that it returns the login page of Microsoft.
I'm sorry for not putting some code here or maybe any other detail, but I am really messy about this.
Thanks!

How to get price data from Azure API for individual resources?

I am using the API mentioned on https://msdn.microsoft.com/en-us/library/azure/mt219004.aspx to get the information on how much individual Azure resources is charging.
However I am getting a 401 response with error message as
The 'Authorization' header is missing."
There seems to be lack of documentation on how to make the API call with proper authentication.
Thanks for any help in advance.
If you are making the call interactively, you can use the same AuthenticationContext.AcquireToken method the billing reference application is using to authenticate example source.
If you want to call the billing API unattended from a service for instance, I have an example here using a service principal.

Why would my API App swagger be unavailable to my Azure App Service Logic App?

I have created a simple api with a test controller and published it as an Azure Api App. I have public (anonymous) access enabled, the swagger ui works well in the browser and the swagger validates correctly, and I have added to it the default response setting that Logic Apps require.
When I try to add the Api App to my Logic App, however, I encounter a fault: "Error fetching swagger api definition".
If I try to browse the API definition in the portal I encounter another fault "Cannot get the API definition. It may require additional configuration or authentication on the API app."
If I try to download the swagger data from the portal link this fails with Http 400: Bad Request.
What am I missing here and how do I get this simple Api App working in the portal?
Public URI: https://microsoft-apiappf6c70a179b1b408c99e3f2536467ff39.azurewebsites.net
Swagger UI: https://microsoft-apiappf6c70a179b1b408c99e3f2536467ff39.azurewebsites.net/swagger/ui/index
Raw Swagger:
{"swagger":"2.0","info":{"version":"v1","title":"PE.Services.Idml"},"host":"microsoft-apiappf6c70a179b1b408c99e3f2536467ff39.azurewebsites.net:443","schemes":["https"],"paths":{"/api/ToEpl":{"get":{"tags":["ToEpl"],"operationId":"ToEpl_Get","consumes":[],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"OK","schema":{"type":"array","items":{"type":"string"}}},"default":{"description":"OK","schema":{"type":"array","items":{"type":"string"}}}},"deprecated":false},"post":{"tags":["ToEpl"],"operationId":"ToEpl_Post","consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"produces":["application/json","text/json","application/xml","text/xml"],"parameters":[{"name":"value","in":"body","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/Object"}},"default":{"description":"OK","schema":{"$ref":"#/definitions/Object"}}},"deprecated":false}},"/api/ToEpl/{id}":{"get":{"tags":["ToEpl"],"operationId":"ToEpl_Get","consumes":[],"produces":["application/json","text/json","application/xml","text/xml"],"parameters":[{"name":"id","in":"path","required":true,"type":"integer","format":"int32"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"default":{"description":"OK","schema":{"type":"string"}}},"deprecated":false},"put":{"tags":["ToEpl"],"operationId":"ToEpl_Put","consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"produces":[],"parameters":[{"name":"id","in":"path","required":true,"type":"integer","format":"int32"},{"name":"value","in":"body","required":true,"schema":{"type":"string"}}],"responses":{"204":{"description":"No Content"}},"deprecated":false},"delete":{"tags":["ToEpl"],"operationId":"ToEpl_Delete","consumes":[],"produces":[],"parameters":[{"name":"id","in":"path","required":true,"type":"integer","format":"int32"}],"responses":{"204":{"description":"No Content"}},"deprecated":false}},"/api/Values":{"get":{"tags":["Values"],"operationId":"Values_Get","consumes":[],"produces":["application/json","text/json","application/xml","text/xml"],"responses":{"200":{"description":"OK","schema":{"type":"array","items":{"type":"string"}}},"default":{"description":"OK","schema":{"type":"array","items":{"type":"string"}}}},"deprecated":false},"post":{"tags":["Values"],"operationId":"Values_Post","consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"produces":[],"parameters":[{"name":"value","in":"body","required":true,"schema":{"type":"string"}}],"responses":{"204":{"description":"No Content"}},"deprecated":false}},"/api/Values/{id}":{"get":{"tags":["Values"],"operationId":"Values_GetById","consumes":[],"produces":["application/json","text/json","application/xml","text/xml"],"parameters":[{"name":"id","in":"path","required":true,"type":"integer","format":"int32"}],"responses":{"200":{"description":"OK","schema":{"type":"string"}},"default":{"description":"OK","schema":{"type":"string"}}},"deprecated":false},"put":{"tags":["Values"],"operationId":"Values_Put","consumes":["application/json","text/json","application/xml","text/xml","application/x-www-form-urlencoded"],"produces":[],"parameters":[{"name":"id","in":"path","required":true,"type":"integer","format":"int32"},{"name":"value","in":"body","required":true,"schema":{"type":"string"}}],"responses":{"204":{"description":"No Content"}},"deprecated":false},"delete":{"tags":["Values"],"operationId":"Values_Delete","consumes":[],"produces":[],"parameters":[{"name":"id","in":"path","required":true,"type":"integer","format":"int32"}],"responses":{"204":{"description":"No Content"}},"deprecated":false}}},"definitions":{"Object":{"type":"object","properties":{}}}}
I think this is because you have two routes with the same operationId (ToEpl_Get).
There are a few mitigations
Since Swashbuckle derives this from the action name in your api controller…you can change one of your action names…e.g. GetById instead of Get
Alternatively, the way to change operation id is to go to the SwaggerConfig.cs file add add a custom operation filter. The operation filter extension point will give you access to the operation and to change the id.
So sorry for the inconvenience, and we will be making our error reporting better soon.

Get a List from Office365 using REST API

I want to get a SP2013 list and I can't use CSOM. I've registered my app (a cmd test app, not a SP hosted one) on Sharepoint and have a clientId and clientSecret.
But when I submit the Authorize Url that I built:
https://mysite.sharepoint.com/_layouts/15/OAuthAuthorize.aspx?client_id=<myclientId>&scope=list.read&response_type=code&redirect_uri=https%3A%2F%2Fwww.google.com
I get a http403 on fiddler.
or
when I request it from a browser I get redirected to:
https://www.google.com/?error=invalid_scope&error_description=The%20scope%20list%2Eread%20is%20not%20valid%2E
which is my redirect_uri but with the error "invalid scope". I've tried to use the scope uri (instead of the alias) and got the same response.
Note that I'm also authenticaded when I make the request from the browser. Otherwise I get redirected to the login page.
How can I get an access token to make REST requests to Sharepoint?
Here is a longer description of what I'm trying to do:
I’ve got a sharepoint list at https://mysite.sharepoint.com/. (the location is actually: https://mysite.sharepoint.com/_layouts/15/start.aspx#/Lists/TestTasksList)
And I want to query it from an android app. So far I have and android app built using xamarin to create tasks.
I can’t use the client side object model. So the only option is using the Rest Api.
I have tried to create a simple .net cmd line app to query the rest api but I can’t find a way to authenticate. I think I need to use OAuth but even after getting the clientId and clientsecret I can’t manage to make requests. I can’t get an access token.
Most code samples that I found are for sharepoint applications to be deployed in the cloud and they seem to ignore the authentication bit (or just using default credentials).
I managed to authenticate and query the list using the CSOM in a .net cmd app. But I can’t find a way to do it using the rest api.
I know we can use the legacy web services (from SP2010) but that won’t work as a long term solution.
So the bottom line is querying a list in Office 365 from a console app using the REST api.

Resources