I'm working on an automation to update the access level of the user from Basic to stakeholder using an Azure DevOps RestAPI.
I have tried following Rest API as per documentation but getting bad request.
https://vsaex.dev.azure.com/xxxxxxxx/_apis/userentitlements/d42xxxx-xxxxxxxx-xxxxxx-xxxxxxxxxx?api-version=6.0-preview.3
Input Json:
{
"from": "",
"op": "replace",
"path": "/accessLevel",
"value": {
"accountLicenseType": "stakeholder",
"licensingSource": "account"
}
}
As far as I can see, the body of the request you send is a JSON object, but the example in the documentation specifies the body as JSON array. Not sure if it's a strict requirement, but try wrapping the body into [].
Please use the following body which should work as expected.
[
{
"from":"",
"op":"replace",
"path":"/accessLevel",
"value":{
"accountLicenseType":"stakeholder",
"licensingSource":"account"
}
}
]
See: Examples for more details.
Related
I'm developing a console app that uploads a custom policy (that part is working) and the related policy key using the Graph API following this documentation https://learn.microsoft.com/en-us/graph/api/trustframework-post-keysets?view=graph-rest-beta&tabs=http#example-2-create-a-keyset-with-a-key
Request:
URL: https://graph.microsoft.com/beta/trustFramework/keySets
Headers: Content-Type = application/json, Authorization = Bearer eyJ0e...Mca9g
Payload: {
"id":"Test3AADSecret",
"keys":
[
{
"use":"sig",
"k":"A1B2C3D4E5F6G7H8I9J10K11L12M13N14O15P16Q17R18S19T20U21V22W23X24Y25Z26",
"nbf":1644941414,
"exp":4070908800
}
]
}
The request works if I set the keys property to an empty array. However when I try to include a key in the keys property (as in the example above) I get 400 Bad Request status returned with this response payload
{
"error":
{
"code":"AADB2C",
"message":"The 'keySet' field is invalid in request. Please check the request body and parameters.",
"innerError":
{
"correlationId":"ee3aa070-a5a7-4c52-96b7-f0a9471fba63",
"date":"2022-02-15T16:27:36",
"request-id":"ad5dba0f-595a-4f94-ade2-fec2357bcb55",
"client-request-id":"ad5dba0f-595a-4f94-ade2-fec2357bcb55"
}
}
}
The only issues I can find on github relates to using the GraphServiceClient C# class (not the Graph API) to create a keyset with key and that issue has been closed (resolved) https://github.com/microsoftgraph/msgraph-beta-sdk-dotnet/issues/67
I've tried installing the latest version of Microsoft.Graph nuget package (4.18.0) but I can't follow the C# example from here https://learn.microsoft.com/en-us/graph/api/trustframework-post-keysets?view=graph-rest-beta&tabs=csharp#request because there's no TrustFrameworkKeySet class and the GraphServiceClient doesn't contain a definition for TrustFramework. I've tried searching nuget and google for other nuget packages to fill these gaps but I've found nothing.
Yes, I could just call the https://graph.microsoft.com/beta/trustFramework/keySets API with an empty keys array and then make a second call to https://graph.microsoft.com/beta/trustFramework/keySets/{id}/uploadSecret to add the key to the ketset. But when I do this I end up with two policy keys, one of which has a .bak extension to the name.
So I have many questions
Am I doing something wrong when calling the Graph API with a key in the keys array
Am I missing a nuget package for the GraphServiceClient C# class. If so, where can I find them?
How can I prevent the second policy key from appearing (.bak file) when attempting to add the key in a separate API call after creating the empty keyset
Thanks in advance if you help me achieve at least one of these approaches.
I made some experiments here. I'm using REST API through PowerShell.
One interesting behavior is the usage of keySets updating (PUT method). The object you try to update must somehow match the existing one.
Assume you have a signature with no valid before (nbf) and expiration, then the following payload works:
{
"keys": [
{
"use": "sig",
"k": "$key",
"kty": "oct"
}
]
}
However, if one adds the exp and nbf fields like so it fails:
{
"keys": [
{
"use": "sig",
"k": "$key",
"kty": "oct",
"nbf": $now,
"exp": $exp
}
]
}
If these fields exists, you must provide values. It fails with the common message
400 Bad Request {"error":{"code":"AADB2C","message":"The 'keySet' field is invalid in request. Please check the request body and parameters."
In general, the API works but is very restrictive. It's a very good idea to go to the portal and check the manifest files.
Identity Experience Framework | Policy Keys | {your policy} | {click on name}
{
"metadata": {
"updatedUtc": "8/1/2022 4:07:42 PM",
"tenantID": "your-tenant.onmicrosoft.com",
"storageKeyId": "B2C_1A_Keyname"
},
"keys": [
{
"kid": "Q1fDF-jMoHeyr7gciaaWgXe3eVkjYdx8BLZoG3J_f1E",
"use": "sig",
"key_ops": [
"sign"
],
"kty": "oct"
}
]
}
Mostly the keys array shown is a valid body for the API call (while I found that you can strip the key_ops field). If you start just create few key variations by hand and try out to deal with these.
I want to create a git repository in azure devops using rest api.
POST https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=5.1
Request body should be like this.
{
"name": "repo_name",
"teamProjectReference": {
"id": "azure_project_id"
}
}
Also, you can go through this link to know better https://learn.microsoft.com/en-us/rest/api/azure/devops/git/repositories/create?view=azure-devops-rest-5.1
You only need to pass the repository name and the project id within the body:
{
"name": "AnotherRepository",
"project": {
"id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c"
}
}
See also: Create a repository
I have created a APIs through importing open api spec(swagger).If I have added a new api into the list I want azure apis to get updated with new list basically re-importing the swagger. Is there any way we can automate it??
Best is to send JSON body with "fcontentFormat" and "value" set accordingly. See here: https://learn.microsoft.com/en-us/rest/api/apimanagement/current-ga/apis/create-or-update?tabs=HTTP#request-body. For example:
Content-Type: application/json
{
"properties": {
"format": "openapi-link",
"value": "https://contoso.com/my-api.yaml"
}
}
or
Content-Type: application/json
{
"properties": {
"format": "openapi+json",
"value": {
#OpenAPI document goes here
}
}
}
I am a newbie to azure logic app. My aim is to send some variables to logic app(via java service code, which in turn invokes the request trigger with the provided POST URL as REST API) and obtain response as JSON.
Currently i have created a request trigger and the JSON schema looks as follows:-
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {},
"id": "http://example.com/example.json",
"properties": {
"CustomerName": {
"type": "string"
},
"InvoiceFee": {
"type": "integer"
},
"InvoiceNo": {
"type": "integer"
}
},
"required": [
"CustomerName",
"InvoiceFee",
"InvoiceNo"
],
"type": "object"
}
From the request trigger, i am directing to response action and the following to be returned as JSON response.
{
"CustomerName": #{triggerBody()['CustomerName']},
"InvoiceFee": #{triggerBody()['InvoiceFee']},
"InvoiceNo": #{triggerBody()['InvoiceNo']}
}
Screenshot below:-
enter image description here
Could you please provide me some reference links of how to access logic app from java service?
I am don't know regarding how to pass the custom created object such that the parameters of the object maps to "CustomerName", "InvoiceNo", "InvoiceFee" properties.
My created java service code is as follows:-
InvoiceDTO invoiceDTOObject2 = new InvoiceDTO();
invoiceDTOObject2.setCustomerName("Sakthivel");
invoiceDTOObject2.setInvoiceNo(123);
invoiceDTOObject2.setInvoiceFee(4000);
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target("URL TO PROVID").resolveTemplate("properties", invoiceDTOObject2);
Response response = target.request().get();
String jsonResponse = response.readEntity(String.class);
System.out.println("JSON Reponse "+jsonResponse);
Looking at your code
Response response = target.request().get();
You are doing a GET-operation. Your Logic App HTTP Trigger would require you to perform a POST-operation using your InvoiceDTO-entity as body (serialized as JSON).
So should look something like this:
Response response = target.request().post( InvoiceDTO.entity(invoiceDTOObject2, MediaType.APPLICATION_JSON));
Not sure if it's 100% correct, my java is a little rusty, but that's the general idea.
I'm trying to use next API method: https://msdn.microsoft.com/office/office365/APi/mail-rest-operations#SendMessages. Sending messages without attachments works just fine, but I can not understand how to send message with attachments.
According to docs, Message structure can contain array of Attachments with items of type https://msdn.microsoft.com/office/office365/APi/complex-types-for-mail-contacts-calendar#RESTAPIResourcesFileAttachment . Problem is in the field ContentBytes -- it is impossible to dump bytes to JSON before sending request to this API method (actually dumping any BLOB to JSON is nonsense).
How should I pass Attachments using REST API at all?
Thanks.
There's an example of passing the attachment on that page: https://msdn.microsoft.com/office/office365/APi/mail-rest-operations#SendMessageOnTheFly
I know I'm 3 years late but, you can look at this example:
https://msdn.microsoft.com/office/office365/APi/mail-rest-operations#create-and-send-messages (if you don't get forwarded to the section "Create and send messages", please scroll manually).
I know it is 365 and not Microsoft Graph but request is absolutely same.
This is basically how JSON representation of the post method looks:
https://outlook.office.com/api/v2.0/me/sendmail
{
"Message":
{
"Subject": "Meet for lunch?",
"Body": {
"ContentType": "Text",
"Content": "The new cafeteria is open."
},
"ToRecipients": [
{
"EmailAddress": {
"Address": "garthf#a830edad9050849NDA1.onmicrosoft.com"
}
}
],
"Attachments": [
{
"#odata.type": "#Microsoft.OutlookServices.FileAttachment",
"Name": "menu.txt",
"ContentBytes": "bWFjIGFuZCBjaGVlc2UgdG9kYXk="
}
]
}
}