Creating a new SharePoint column using Graph REST API - sharepoint

I've been working on a function that puts a value in a list column if it exists. However, in the case that it doesn't exist (which I check using GET https://graph.microsoft.com/v1.0/drives/{driveID}/list/columns"), I'd like it to make a list column. How do I create a new column in SharePoint using Microsoft Graph's REST API? I've scoured the documentation but have thus far come up short.

Per the API documents, there is no such an endpoint to update a list. I believe the related functionality has not been released. You can submit the feedback on Microsoft Graph Feature Requests or turn to the old sharepoint rest api:
https://www.codesharepoint.com/rest-api/create-list-column-in-sharepoint-using-rest-api

HTTP :
POST https://graph.microsoft.com/v1.0/me/drive/items/{id}/workbook/tables/{id|name}/columns
Content-type: application/json
Content-length: 81
{
"id": 99,
"name": "name-value",
"index": 99,
"values": "values-value"
}
Response : HTTP
HTTP/1.1 201 Created
Content-type: application/json
Content-length: 81
{
"id": 99,
"name": "name-value",
"index": 99,
"values": "values-value"
}
Response :
If successful, this method returns 201 Created response code and WorkbookTableColumn object in the response body.
For more details : https://learn.microsoft.com/en-us/graph/api/table-post-columns?view=graph-rest-1.0&tabs=http

Related

Insert User through Sharepoint batch send HTTP Request Connector

I need to insert items into sharepoint by using SP connector - Send HTTP Request
I send body : "User": { "Key": "i:0#.f|membership|#{first(body('Get_by_mail')?['value'])['Email']}" },
Despite it having successfully created, the sharepoint shows the field without value. Do you have any idea what could be going on?
After reproducing from my end, I could able to make this work using the below JSON in the body while sending the HTTP request.
{
"__metadata": { "type": "SP.Data.<YOUR_LIST_NAME>ListItem" },
"Title": "ccc",
"UserId": 6
}
UserId is the key which represents the column in my Sharepoint which is named as User. Consider if Person is the column in your Sharepoint then make sure you set the key value as PersonId.
Results:
If you look at your JSON:
"User":
{
"Key": "i:0#.f|membership|#{first(body('Get_by_mail')?['value'])['Email']}"
}
you'll notice that you're sending just a key to a key/value pair target. The item inserts because a Key is provided, but it doesn't display anything because you did not provide a Value that would be displayed. Try the following JSON instead:
"User":
{
"Key": "i:0#.f|membership|#{first(body('Get_by_mail')?['value'])['Email']}",
"Value": "i:0#.f|membership|#{first(body('Get_by_mail')?['value'])['Email']}"
}

How to connect Azure APIM to Logic Apps to transform JSON structure of API response?

I've read and followed multiple posts but I can't fix my problem:
I've created a APIM(Azure API Management) service and this works, the gateway url www.azurebroker.nl/azurebroker/factuur(for example) that does a request to my own API(www.ownapi.nl/invoice). The response of this API is as following:
{
"invoiceID":1,
"formType":"invoice",
"amount":449,
"currency":"eur",
"description":"Invoice real estate",
"period":{"end":20122019,"start":20122020},
"owner"{"id":91434,"firstname":"User","lastname":"UserName","dateOfBirth":1121993,"phoneNumber":3487378434,"countryOfBirth":"Nederland","IBAN":"NL28 ABNA 743734763474324"},
"property":{"id":105,"type":"apartment","address":"ghost lane 13","ZIP":"7888 CK","State\/Province":"Groningen","country":"Nederland","construction-year":15072009,"previousOwners":9},
"previousProperties":[54,193,11,454,18]
}
Now I'm trying to transform the structure of the response above to a different structure, for example:
{
"general": {
"invoiceID": 12,
"formType": "invoice",
"amount": 449,
"currency": "eur",
"description": "Invoice real estate",
"period": {
"end": 20122019,
"start": 20122020
}
},
"owner": {
"id": 91434,
"name": "User, Username",
"dateOfBirth": 1121993,
"phoneNumber": 646068151,
"countryOfBirth": "Nederland",
"IBAN": "NL28 ABNA 743734763474324"
},
"property": {
"id": 105,
"type": "apartment",
"fullAddress": "ghost lane 13, 7888 CK Groningen Nederland",
"construction-year": 15072009,
"previousOwners": 9
},
"previousProperties": [ 54, 193, 11, 454, 18 ]
}
As you look closely, some fields are changed, for example:
Firstname + Lastname is now Name.
invoiceID, formType, amount, currency, description are now put in a object named "general".
I've tried doing the following in Logic Apps:
The request body schema input field of this action is a schema of the first JSON mentioned in this article. After this action I've tried the action "Parse JSON":
In the Schema input field of the action "Parse Json" I've filled a JSON schema of the second JSON mentioned in this article.
Hope my goal is clear to you guys and someone can help me out. I'm trying to map the json structure of the response of my request I'm making with my API Management Gateway URL.
Thanks in advance
If you want to use LA, you could use send-request policy in APIM to compose new HTTP request and make a call to LA, and then use set-body to override response body with response from LA. But if this JSON transformation is all you need, you could avoid using LA and do everything in APIM. Add this inside outbound section of your operation policy:
<set-body>#{
var body = context.Response.Body.As<JObject>();
var newBody = new JObject(new JProperty("general", body));
var owner = (JObject)body["owner"];
owner["name"] = $"{owner["firstname"]}, {owner["lastname"]}";
owner.Remove("firstname");
owner.Remove("lastname");
body.Remove("owner");
newBody.Add("owner", owner);
var property = (JObject)body["property"];
property["fullAddress"] = $"{property["address"]}, {property["ZIP"]} {property["State/Province"]} {property["country"]}";
property.Remove("address");
property.Remove("ZIP");
property.Remove("State/Province");
property.Remove("country");
body.Remove("property");
newBody.Add("property", property);
var previousProperties = (JArray)body["previousProperties"];
body.Remove("previousProperties");
newBody.Add("previousProperties", previousProperties);
return newBody.ToString();
}</set-body>
Depending on your exact transformations you may perfer to cherry-pick all properties instead, or even use liquid template to construct body, set-body policy supports that.

Programmatically obtaining Azure Active Directory tenant name from ID

How can I get an AAD tenant name (not necessarily mine), from a GUID? This would be via the REST API ideally, but the Azure CLI/Powershell works too.
I found an answer here, but it requires going to the Azure Portal.
There are also plenty of links here and elsewhere on obtaining the tenant ID from the name, but I'm going in the opposite direction.
You can get the tenant name (and some other details) for the signed-in user by calling the /organization endpoint in MS Graph API: https://learn.microsoft.com/en-us/graph/api/organization-get?view=graph-rest-1.0.
Request: GET https://graph.microsoft.com/v1.0/organization
Response:
HTTP/1.1 200 OK
Content-type: application/json
Content-length: 411
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#organization",
"value": [
{
"assignedPlans": [
{
"assignedDateTime": "datetime-value",
"capabilityStatus": "capabilityStatus-value",
"service": "service-value",
"servicePlanId": "servicePlanId-value"
}
],
"businessPhones": [
"businessPhones-value"
],
"city": "city-value",
"country": "country-value",
"countryLetterCode": "countryLetterCode-value",
"displayName": "displayName-value"
}
]
}

How to Update swagger(Open API spec) through rest API in Azure API Management? Is there any Rest API support re-import using rest api?

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
}
}
}

Getting Http 500 error when calling QnA api with strictfilter

I am getting Http 500 error whenever i am calling the QnAMaker Api with Metadata(strictFilter) body. Am I not following any instruction before calling Apis?
QnA maker api is working perfectly if I am not adding strictFilter in the Api request body.
api request details:
URL: https://qnamaker endpoint/qnamaker/knowledgebases/KBID/generateAnswer
Method: POST
content-type: application/json
Authorization: EndpointKey Key
Body:
{
"question": "hi",
"top": 3,
"strictFilters": [
{
"name": "category",
"value": "pears"
}
]
}
I have even read the Microsoft documentation
Still no luck for me here.
QnaMaker Response Error with StrictFilter screenshot

Resources