Add event to calendar on SharePoint through REST API - rest

I'm trying to add a calendar event to a SharePoint Calendar through REST API but i can't seems to find the relevant resources to achieve this.
If i understand correctly, the calendar in SharePoint is a List of events object, as such I should be able to add the event via ListItem object?
Sorry if this sounds wrong as I'm not familiar with SharePoint structure.
Thanks

This is the example for OAuth token Authentication but REST part is anyway like this.
var dataObj = {
"Subject": "Birthday Party"
"Body": {
"ContentType": "Text",
"Content": "Birthday Party for Cathy",
},
"Start": {
"dateTime": "2016-07-03T09:00:00Z",
"timeZone": "Asia/Tokyo"
},
"End": {
"dateTime": "2016-07-04T11:00:00Z",
"timeZone": "Asia/Tokyo"
},
"Location": {
"DisplayName": "Conference Room 1"
},
"ShowAs": "Busy",
"Attendees": [
{
"EmailAddress": { "Name": "Alex Darrow", "Address": "darrow.alex#company.com" },
"Type": "Required"
}
]
};
var url = "https://graph.microsoft.com/v1.0/me/events/";
var data = JSON.stringify(dataObj);
$.ajax({
url: url,
type: "POST",
data: data,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json;odata.metadata=full;odata.streaming=true");
XMLHttpRequest.setRequestHeader('Authorization', 'Bearer ' + accessToken);
XMLHttpRequest.setRequestHeader("content-type", "application/json;odata=verbose");
},
success: function (result, textStatus, jqXHR) {
//Success
},
error: function (data) {
//
}});

Related

How to create multiple entities using a single OData POST to a Business Central Web Service?

I tried to POST an array of objects and, as expected, it isn't that easy. In my case I want to insert multiple Transfer Order Lines in the same request.
// Request Body
[
{
"documentNo": "1002",
"itemNo": "1968-S",
"quantity": 3
},
{
"documentNo": "1002",
"itemNo": "1968-S",
"quantity": 113
}
]
// Response
{
"error": {
"code": "BadRequest",
"message": "Invalid Request Body CorrelationId: a2606676-3f8f-4753-aaee-be91a621f070."
}
}
Is it possible to do what I want without sending a request for every Line entity I want to add?
You need to create a structure like this:
url: api/2.0/$batch
Body:
```lang-json
{
"requests":
[
{
"method": "POST",
"id":"R1",
"url": "companies(id)/APIEntitySetName",
"headers":
{
"content-Type": "application/json"
},
"body":
{}
},
{
another line
}
]
}
```

Error trying to use an uploaded image in Linkedin

I'm trying to use the Linkedin API to share a post with an image. I've followed all the steps in the documentation:
https://learn.microsoft.com/es-es/linkedin/consumer/integrations/self-serve/share-on-linkedin?context=linkedin/consumer/context#share-media
First, I register the upload with a POST to https://api.linkedin.com/v2/assets?action=registerUpload and this body:
{
"registerUploadRequest": {
"recipes": [
"urn:li:digitalmediaRecipe:feedshare-image"
],
"owner": "urn:li:person:{{owner_ID}}",
"serviceRelationships": [
{
"relationshipType": "OWNER",
"identifier": "urn:li:userGeneratedContent"
}
]
}
}
I get this response:
{
"value": {
"uploadMechanism": {
"com.linkedin.digitalmedia.uploading.MediaUploadHttpRequest": {
"uploadUrl": "https://api.linkedin.com/mediaUpload/C4E22AQF6AS1WhrD1lw/feedshare-uploadedImage/0?ca=vector_feedshare&cn=uploads&m=AQKLg3lSJnswAgAAAXSgLwWp6iAPzjh6E_5XQh8QuP1Aucf_j9bgW3m5vQ&app=74851466&sync=0&v=beta&ut=2h9vtCSeuP0ps1",
"headers": {
"media-type-family": "STILLIMAGE"
}
}
},
"asset": "urn:li:digitalmediaAsset:C4E22AQF6AS1WhrD1lw",
"mediaArtifact": "urn:li:digitalmediaMediaArtifact:(urn:li:digitalmediaAsset:C4E22AQF6AS1WhrD1lw,urn:li:digitalmediaMediaArtifactClass:feedshare-uploadedImage)"
}
}
Then I use the uploadURL to make another post with the image as body, and get a 201 Created response.
I've checked the upload with a GET https://api.linkedin.com/v2/assets/C4E22AQF6AS1WhrD1lw and it has been uploaded correctly:
{
"recipes": [
{
"recipe": "urn:li:digitalmediaRecipe:feedshare-image",
"status": "AVAILABLE"
}
],
"serviceRelationships": [
{
"relationshipType": "OWNER",
"identifier": "urn:li:userGeneratedContent"
}
],
"mediaTypeFamily": "STILLIMAGE",
"created": 1600415270252,
"id": "C4E22AQF6AS1WhrD1lw",
"lastModified": 1600415345915,
"status": "ALLOWED"
}
When I try to share a post referencing this image I get this error:
{"message":"com.linkedin.restli.server.RestLiServiceException [HTTP Status:401]: com.linkedin.content.common.ResponseException: Writers of type person are not authorized to modify UserGeneratedContent.","status":401}
I'm sending a POST to this URL https://api.linkedin.com/v2/ugcPosts with this body:
{
"author": "urn:li:person:{{person_id}}",
"lifecycleState": "PUBLISHED",
"specificContent": {
"com.linkedin.ugc.ShareContent": {
"shareCommentary": {
"text": "Feeling inspired after meeting so many talented individuals at this year's conference. #talentconnect"
},
"shareMediaCategory": "IMAGE",
"media": [
{
"status": "READY",
"description": {
"text": ""
},
"media": "urn:li:digitalmediaAsset:C4E22AQF6AS1WhrD1lw",
"title": {
"text": ""
}
}
]
}
},
"visibility": {
"com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
}
}
I can share an only text post without trouble, look at my person ID, even like a post, but I'm stuck with this.
Can anyone tell me what am I doing wrong?
Solved. I had an error in the person_id variable, so I was trying to create a post with the wrong id.

Sharepoint Rest API - Apply filter on expanded fields - Status 400

I am using Sharepoint rest API to get specific files in a group of folders. For this, I am applying filter on the expanded field. The problem is when I apply filter, it says the "Field or property does not exist"
I've tried to get the data without applying filter and it's coming correctly. Also, I am able to apply filter on the fields which are not under the expand parameter.
Below code is working in postman:
https://sp.foo.net/sites/spdsdfrn/_api/web/GetFolderByServerRelativeUrl('Shared Documents/abc/2019')/Folders?$expand=Files&$select=Files/Name&$filter=Files/Name eq 'abc.xlsx'
Below is the relevant part of the output:
{
"d": {
"results": [
{
"__metadata": {
"id": "https://sp.foo.net/sites/spdsdfrn/_api/web/GetFolderByServerRelativeUrl('Shared Documents/abc/2019/folder1')",
"uri": "https://sp.foo.net/sites/spdsdfrn/_api/web/GetFolderByServerRelativeUrl('Shared Documents/abc/2019/folder1')",
"type": "SP.Folder"
},
"Files": {
"results": [
{
"__metadata": {
"id": "https://sp.foo.net/sites/spdsdfrn/_api/web/GetFolderByServerRelativeUrl('Shared Documents/abc/2019/folder1/abc.xlsx')",
"uri": "https://sp.foo.net/sites/spdsdfrn/_api/web/GetFolderByServerRelativeUrl('Shared Documents/abc/2019/folder1/abc.xlsx')",
"type": "SP.File"
},
"Name": "abc.xlsx"
},
{
"__metadata": {
"id": "https://sp.foo.net/sites/spdsdfrn/_api/web/GetFolderByServerRelativeUrl('Shared Documents/abc/2019/folder1/def.xlsx')",
"uri": "https://sp.foo.net/sites/spdsdfrn/_api/web/GetFolderByServerRelativeUrl('Shared Documents/abc/2019/folder1/def.xlsx')",
"type": "SP.File"
},
"Name": "def.xlsx"
}
]
}
},
.........
.........
..........
Below code is not working in postman:
https://sp.foo.net/sites/spdsdfrn/_api/web/GetFolderByServerRelativeUrl('Shared Documents/abc/2019')/Folders?$expand=Files&$select=Files/Name&$filter=Files/Name eq 'abc.xlsx'
Below is the error output I am getting with status code 400 (bad request):
{
"error": {
"code": "-1, Microsoft.SharePoint.Client.InvalidClientQueryException",
"message": {
"lang": "en-US",
"value": "Field or property \"Name\" does not exist."
}
}
}
I've seen many solutions on the internet and they suggest that it should work in this way. Also, I've seen to check the internal names as they might differ but it's same "Name" in this case.
Is it some bug or I am missing something?
This looks like a typo:
"Field or property \"Names\" does not exist."
As your URL references "Name" not "Names".
Your second URL does not have the file type (.xlsx)
&$filter=Files/Name eq 'abc'
Otherwise...
Your URL includes "/folder". This returns a list of folders. Are you looking for a file in a particular folder, or all files by that name in any folder?
This will return a file in a particular folder:
https://sp.foo.net/sites/spdsdfrn/_api/web/GetFolderByServerRelativeUrl('Shared Documents/abc/2019')/files?$select=Name&$filter=Name eq 'abc.xlsx'
Technically speaking... It's a "server relative", not "site relative" URL. But starting with the library name seems to work.
https://sp.foo.net/sites/spdsdfrn/_api/web/GetFolderByServerRelativeUrl('Shared Documents/abc/2019')/Folders
probably should be:
https://sp.foo.net/sites/spdsdfrn/_api/web/GetFolderByServerRelativeUrl('/sites/spdsdfrn/Shared Documents/abc/2019')/Folders
You can use GetItems method in combination with setting FolderServerRelativeUrl property and Scope.
Example code:
<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var fileName="abc.xlsx";
var libraryTitle="Documents";
var folderRelativeUrl="Shared Documents/abc/2019";
var viewXml = "<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='File'>"+fileName+"</Value></Eq></Where></Query></View>";
var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('"+libraryTitle+"')/getitems?$select=*,FileDirRef,FileRef";
var query = {
'query' : {
'__metadata': { 'type': 'SP.CamlQuery' },
'ViewXml' : viewXml,
'FolderServerRelativeUrl': folderRelativeUrl
}
};
$.ajax({
url: url,
method: "POST",
data: JSON.stringify(query),
headers: {
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"Accept": "application/json; odata=verbose",
"content-type": "application/json; odata=verbose"
},
success: function (data) {
alert(JSON.stringify(data.d.results));
},
error: function (err) {
alert(JSON.stringify(err));
}
});
});
</script>
Or we can use the REST API below.
/_api/web/lists/getbytitle('Documents')/items?$select=File&$expand=File&$filter=FileLeafRef eq 'abc.xlsx'

Simple REST API Call from logic app - Azure

First of all I want you to know that I am new to Azure.
Recently, I am trying to work on Azure Logic App.
My motive is to make a simple REST API Call from the HTTP API (from Microsoft) and mail the response JSON via Office 365 connector.
Here is my code:
{
..
.
.
"triggers": {
"http": {
"recurrence": {
"frequency": "Day",
"interval": 1
},
"type": "Http",
"inputs": {
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"uri": "http://xxx/wcf/myrestservice.svc/is_online"
}
}
},
"actions": {
"office365connector": {
"type": "ApiApp",
"inputs": {
"apiVersion": "2015-01-14",
"host": {
"id": "/subscriptions/xxx/resourcegroups/resourcegroup1/providers/Microsoft.AppService/apiapps/office365connector",
"gateway": "https://xxx.azurewebsites.net"
},
"operation": "SendMail",
"parameters": {
"message": {
"To": "xxx#example.com",
"Subject": "My Service Status",
"Importance": "High",
"Body": "Hi #{triggers().outputs.body.Is_OnlineResult}"
}
},
"authentication": {
"type": "Raw",
"scheme": "Zumo",
"parameter": "#parameters('/subscriptions/xxx/resourcegroups/resourcegroup1/providers/Microsoft.AppService/apiapps/office365connector/token')"
}
},
"conditions": []
}
},
"outputs": {}
}
I am wondering, how could I get the response of the HTTP call?
Then I want to send the same in the mail body.
Please correct me if I am going in wrong direction. Any response from you will be very helpful to me.
Manish!
Have you tried using "Content"?
#triggers().outputs.body.Content

Record saves, promise rejects with custom REST adapter

I'm writing an ember-data adapter for the DreamFactory services platform and am running into an issue I think is related to my adapter.
When updating an existing record the promise resulting from model.save() is ALWAYS rejected with an error of
Assertion Failed: An adapter cannot assign a new id to a record that already has an id. <App.Event311:1> had id: 1 and you tried to update it with null. This likely happened because your server returned data in response to a find or update that had a different id than the one you sent
Thing is - the request to the REST API and the response back from the REST API have the same ID!
Request (PUT)
{
"record": {
"id": "1",
"title": "Sample Event",
"date": "7/20/2013",
"type": "success",
"desc": "My first sample event."
}
}
Response
{
"record": [
{
"id": 1,
"title": "Sample Event",
"date": "7/20/2013",
"type": "success",
"desc": "My first sample event."
}
]
}
The really weird thing is the record still updates properly both in the store AND in the database!
I have a working JSBin at http://emberjs.jsbin.com/mosek/1/edit that illustrates the problem. My custom adapter is on GitHub at https://github.com/ultimatemonty/ember-data-dreamfactory-adapter. The JSBin as well as my app are using Ember 1.7.0 and ED 1.0.0-beta.9
EDIT
The JSBin is attached to my personal hosted instance of DreamFactory - I haven't done anything with it outside of allowing access from JSBin but please be gentle :)
* EDIT #2 *
The updateRecord code is accessible on GitHub at https://github.com/ultimatemonty/ember-data-dreamfactory-adapter/blob/master/lib/ember-data-dreamfactory-adapter.js#L106 but here is the full method for reference:
updateRecord: function(store, type, record) {
var data = {};
var serializer = store.serializerFor(type.typeKey);
serializer.serializeIntoHash(data, type, record);
var adapter = this;
return new Ember.RSVP.Promise(function(resolve, reject) {
// hack to make DSP send back the full object
adapter.ajax(adapter.buildURL(type.typeKey) + '?fields=*', "PUT", { data: data }).then(function(json){
// if the request is a success we'll return the same data we passed in
resolve(json);
}, function(reason){
reject(reason.responseJSON);
});
});
}
The adapter/serializer you're using is expecting you to return a response without the type in it:
{
"id": 1,
"title": "Sample Event",
"date": "7/20/2013",
"type": "success",
"desc": "My first sample event."
}
Example: http://emberjs.jsbin.com/tigiza/1/edit
You can see it here in the extractSingle, where it tries to wrap the payload in in another object with the type specified
EmberDreamFactoryAdapter.Serializer = DS.RESTSerializer.extend({
extractArray: function(store, primaryType, payload) {
var namespacedPayload = {};
namespacedPayload[Ember.String.pluralize(primaryType.typeKey)] = payload.record;
return this._super(store, primaryType, namespacedPayload);
},
extractSingle: function (store, primaryType, payload, recordId) {
var namespacedPayload = {};
namespacedPayload[primaryType.typeKey] = payload;
return this._super(store, primaryType, namespacedPayload, recordId);
},
Your response looks like this:
{
"record": [
{
"id": 1,
"title": "Sample Event",
"date": "7/20/2013",
"type": "success",
"desc": "My first sample event."
}
]
}
Then the serializer kicks in, and it looks like this:
{
event:{
"record": [
{
"id": 1,
"title": "Sample Event",
"date": "7/20/2013",
"type": "success",
"desc": "My first sample event."
}
]
}
}
When really, the serializer should have it looking like this:
{
event:{
"id": 1,
"title": "Sample Event",
"date": "7/20/2013",
"type": "success",
"desc": "My first sample event."
}
}
You can see from the second example, the serializer wraps it in the type, then Ember Data says, hey, give me the id, so it looks at event.id which is undefined, because it lives under event.record[0].id