Passing optional parameters to Strapi query without creating model definition? - geolocation

I want to pass an additional parameter geoDistance to my Strapi endpoint. This parameter should be used by the controller to run a calculation first and afterwards query those records which contain certain longitude / lattitude values.
Example: lets assume that my collection type realestate contains the fields cityName, longitude and latitude, so my request / path would look something like this:
GET /realestate?cityName=Berlin&geoDistance=5
If I do this, I get an error (if the field doesn't appear on my model definition):
{
"statusCode": 400,
"error": "Bad Request",
"message": "Your filters contain a field 'geodistance' that doesn't appear on your model definition nor it's relations"
}
But I don't want it to be on my model definition, because it should only be used temporarily before running the actual (bounding box) query, e.g. something like this:
if (ctx.query.geodistance) {
const geodistance = ctx.query.geodistance
const { longitude, latitude } = getCityDegrees(ctx.query.cityName)
// use geodistance in combination with lon, lat, etc...
}
So the question is if there is a way to pass params without a model definition? Because the param itself should not appear inside the database.

I have solved the problem by passing the value not via a url query, but instead via a dynamic route parameter. Therefore I have a defined a new routes object like this:
{
"method": "GET",
"path": "/realestate/distance/:distance",
"handler": "Realestate.find",
"config": {
"policies": []
}
And then used it like this const distance = ctx.params.distance ...
If there is another solution to this, I am happy to hear about it.

Related

How to return friendly field names for zapier trigger (zapier developers)

I am working on a Zapier integration for an online form builder. Each unique form for our users has lots of long, auto-generated field names.
We have a trigger called “New form entries”, which polls our server for form entries, and comes back like this:
[
{
"id": "6209aee326baa600224d822c",
"email_907058157108782": "test#test.com",
"phone_589083232390193": "12345",
},
{
"id": "61fd629f19408200225e1893",
"email_907058157108782": "test#test2.com",
"phone_589083232390193": "54321",
},
]
However, this results in end users seeing these really long, gross field names in the Zapier interface:
My question: how do I get Zapier to display friendly labels to the user, whilst using the unique field IDs behind the scenes?
I’m thinking of returning something like the following (each object represents a form entry, , but I need to know how to actually use “friendlyFieldName” and “value” in Zapier!-
[
{
// the id for the entry
"id": "62179ec5ab9daa0022df7d1d",
// the id for the first field entry
"text_576692390099896": {
// a friendly name and value for zapier
"friendlyFieldName": "What is your favourite colour?",
"value": "Blue"
}
}
]
Thank you :)
You can define output fields labels in outputFields. Here are the reference document that you can follow: Output Fields

Create a documentSet using graph API - configuration

I implemented with Graph API several calls to create a document set.
I followed the answer posted here concerning the possibility of creating a DocumentSet in SharePoint here : Is it possible to create a project documentset using graph API?
For this i followed those steps :
1. Getting the library driveId :
`GET https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${listId}?$expand=drive`
2. Creating the folder:
POST https://graph.microsoft.com/v1.0/drives/${driveId}/root/children
I have to pass an object:
{
"name": ${nameOfTheFolder},
"folder": {},
}
3. Getting the Sharepoint itemId:
4. Updating the document library:
`PATCH https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${listId}/items/${sharepointIds.listItemId}`
and passing a body:
{
"contentType": {
"id": "content-type-id-of-the-document-set"
},
"fields": {
//whatever fields you want to set
}
}
I have questions concerning the folder creation and the updating:
What is expected in the folder object ?
{
"name": ${nameOfTheFolder},
"folder": {},
}
Concerning the path step:
{
"contentType": {
"id": "content-type-id-of-the-document-set"
},
"fields": {
//whatever fields you want to set
}
}
I have several questions :
Let's consider i have a document type called invoices. Which id is expected for document type id ?
finally how do i pass the fields ? let's say i want to pass 3 fields : invoiceId, claimId, clientId.
Graph API is great but some more information would be helpful. thanks !
I have questions concerning the folder creation and the updating: What is expected in the folder object ?
The folder object (sent as {}) is there to tell graph API that you are creating a folder and not a file. It is a property of the drive item
Let's consider i have a document type called invoices. Which id is expected for document type id ?
This is the id contentType subfield of the list item you are patching
ally how do i pass the fields ? let's say i want to pass 3 fields : invoiceId, claimId, clientId.
You just pass them with repective values like below. See Update listItem
{
"invoiceId": "value",
"claimId": "value"
...
}
One point I didn't express correctly was to know what id is expected here :
{
"contentType": {
"id": "content-type-id-of-the-document-set"
},
"fields": {
//whatever fields you want to set
}
}
I retrieved the different content types of my site by calling this kind of URL and check if the content type exists.
https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${listId}/contentTypes
From the result i retrieve in a Value object the id.
The id looks like this :
0x0120D5200082903AB771604546844DB2AC483D905B00E58445A7D..........
In modern SharePoint, you can also get the Content Type ID from the UI by browsing to SharePoint Site > Site Settings > Site content types > <ContentTypeName> > Content Type ID.
Content Type ID
Not sure if this is easier than via graph, but it's another option at least.

Can't Update Sharepoint Managed Meta Data Field from Microsoft Graph Explorer

I'm trying to update the fields associated with a list item via Graph Explorer, https://developer.microsoft.com/en-us/graph/graph-explorer (or a REST API call). For one of the fields, its value can be one item from a term set (managed meta data). I can see each of the elements in the term set and get each termguid when I visit https://XXX.sharepoint.com/Lists/TaxonomyHiddenList/AllItems.aspx.
I'm trying to do a PATCH request with a URL of something like https://graph.microsoft.com/beta/sites/XXX.sharepoint.com,FOO,BAR/drive/root/children/Test%20Document.txt/listItem/fields (or https://graph.microsoft.com/v1.0/sites/XXX.sharepoint.com,FOO,BAR/drive/list/items/1/fields) to identify the fields associated with a specific item
To update the CakeType field, I've set the request body to the following:
{
"CakeType": {
"Label": "Apple",
"TermGuid": "3a3ad73f-94ca-4d1e-a25c-XXXX",
"WssId": -1
}
}
When I then press the Run Query button, I get an InvalidClientQueryException with a message of "A value without a type name was found and no expected type is available. When the model is specified, each value in the payload must have a type which can be either specified in the payload, explicitly by the caller or implicitly inferred from the parent value."
So, I've been trying to figure out what datatype to specify and how to... In various examples online, I've seen adding a field named __metadata and others adding #odata.type, like CakeType#odata.type for the case here. I've tried adding these lines within the CakeType JSON and outside it, for the whole structure. Neither worked...
{
"CakeType": {
"__metadata" : {"type" : "SP.Taxonomy.TaxonomyFieldValue" },
"Label": "Apple",
"TermGuid": "3a3ad73f-94ca-4d1e-a25c-XXXX",
"WssId": -1
}
}
or
{
"__metadata" : {"type" : "SP.Taxonomy.TaxonomyFieldValue" },
"CakeType": {
"Label": "Apple",
"TermGuid": "3a3ad73f-94ca-4d1e-a25c-XXXX",
"WssId": -1
}
}
I've also tried using the field name in the type which I thought I saw somewhere...
"__metadata" : {"type" : "SP.Data.CakeType" },
and tried
"CakeType#odata.type" : "SP.Taxonomy.TaxonomyFieldValue" ,
"CakeType#odata.type" : "SP.Data.CakeType",
"#odata.type" : "SP.Taxonomy.TaxonomyFieldValue" ,
The only things that gave a different error message was when I put "CakeType#odata.type" : "SP.Taxonomy.TaxonomyFieldValue" , immediately after the opening { or without the CakeType part within the CakeType...
{
"CakeType#odata.type" : "SP.Taxonomy.TaxonomyFieldValue" ,
"CakeType": {
"Label": "Apple",
"TermGuid": "3a3ad73f-94ca-4d1e-a25c-XXXX",
"WssId": -1
}
}
and
{
"CakeType": {
"#odata.type" : "SP.Taxonomy.TaxonomyFieldValue" ,
"Label": "Apple",
"TermGuid": "3a3ad73f-94ca-4d1e-a25c-XXXXX",
"WssId": -1
}
}
Each gave an error of "A type named 'SP.Taxonomy.TaxonomyFieldValue' could not be resolved by the model. When a model is available, each type name must resolve to a valid type."
This makes me think that I have the right field name but the wrong type...
So... what should I be naming the type so I can update the managed meta data field? or... what must the JSON be if the above structure is so far off... or how can I update the field strictly using the Graph API.
Thanks.
I thought looking at schema extensions might help (GET https://graph.microsoft.com/v1.0/schemaExtensions) but it didn't...
Ultimately, I'm trying to update the managed meta data field from Java with the classes in com.microsoft.graph.... so if I can figure out the right stuff with Graph Explorer, I can then move over to Java. I've seen some examples of such in other languages but can't figure out the right way to do same in Java.
Here is how I was finally able to do this.
First you need the id of the hidden field which is the displayName corresponding to your field CakeType which should be CakeType_0.
I used this REST call to get find the id:
https://graph.microsoft.com/v1.0/sites/{sitid}/lists/{listid}/items?expand=hidden
This will return all your fields and you want the one with the _0 suffix:
..."displayName": "Cake_0",...
"name": "d39a5181f12f41a483acb1a4e47477b1"...
It is this name id you need to use to update the field.
So then the PATCH call on your item is like this:
https://graph.microsoft.com/v1.0/sites/{sitid}/lists/{listid}/items/{itemid}
Then the payload syntax is like this:
{"{FieldID}":"{TermNumber};#{Term}|{TermGuid}"}
So it would look like this (assuming Apple is the 4th tag although I think -1 might work there too):
{"d39a5181f12f41a483acb1a4e47477b1":"4;#Apple|3a3ad73f-94ca-4d1e-a25c-XXXX"}
For more than one tag separate them with ;# all within the same quoted string
I was having the same issue, and found this: https://microsoftgraph.uservoice.com/forums/920506-microsoft-graph-feature-requests/suggestions/33421180-support-for-setting-sharepoint-managed-metadata-t
The feature request:
Support for setting SharePoint Managed Metadata (taxonomy) column values and other complex column types on items via the Graph API
The response:
Thank you for your feedback! This work is on the backlog and currently isn’t scheduled. The feature will be updated here once dev work has started. -EY

RestKit - Map to a simple instance variable

I am quite new to RestKit. I know that the Object Mapping of Restkit is very powerful. However, in some case, I just want to map to a simple variable. For example, take a look at the following response:
{
"response": 400,
"result": {
"error_message": "Invalid session token"
}
}
I just want to know the value of "response" or "error_message". It's quite wasteful to create 2 classes "response", and "result", since these classes have only few fields.
Any recommendation is welcome.
You can create a single class with response and message properties, then use mappings:
#"response" : #"response",
#"result.error_message" : #"message"
Or you can just map into a dictionary for error responses and then use the keypath to access the message.

Unable to create course via api

I am trying to create a course in a semester through the api in valence d2l. I keep getting a 404 not found error, both in my program and in the "getting started" application. The call I am making is to /d2l/api/lp/1.0/courses/ using post. I pass the following JSON object along with it:
{
"Name": "COMM291 - Test A",
"Code": "C-COMM291",
"Path": "/enforced/C-COMM291/",
"CourseTemplateId": 20992,
"SemesterId": 20993,
"StartDate": "2013-08-22T19:41:14.0983532Z",
"EndDate": "2013-08-27T19:41:14.0993532Z",
"LocaleId": 4105,
"ForceLocale": false,
"ShowAddressBook": false
}
I have also tried passing null for the fields that say they accept null values, but no luck. The course template and the semester ID are correct - I have tripled checked that they exist, I am enrolled in them and I am using the correct ID numbers.
Try reducing the precision in your start and end dates to three decimals after the final point (e.g., "2013-08-22T19:41:14.0983532Z" becomes "2013-08-22T19:41:14.098Z").
If your org is configured to automatically enforce, and generate, paths for course offerings, then you should not provide one in your CreateCourseOffering block at all. The following structure works on our test instance: notice the empty string for path (shouldn't be null, but an empty string, I believe):
{ "Name": "Extensibility 104",
"Code": "EXT-104",
"Path": "",
"CourseTemplateId": 8082,
"SemesterId": 6984,
"StartDate": "2013-09-01T19:41:14.098Z",
"EndDate": "2013-12-27T19:41:14.098Z",
"LocaleId": 1,
"ForceLocale": false,
"ShowAddressBook": false }
The other thing to note is that if your CreateCourse form doesn't have a form element to provide a Semester ID, then your API call should pass null for that property.
I found that part of my problem was with the call if I change it to /d2l/api/lp/1.3/courses/ instead of 1.0 it works, (1.0 will work but it seems that you can only pass null for the semester).
The dates were also picky and did prefer milliseconds to only 3 decimal places.
Then passing null for LocaleId also helped.

Resources