I have a JSON object that I'm working with. It's the result of an HTTP GET request.
The expected results are the following:
{
"name": {
"type": "string"
},
"authors": {
"collection": "users",
"via": "IDPid"
},
"id": {
"type": "integer",
"autoIncrement": true,
"primaryKey": true,
"unique": true
}
}
The actual results are the following (The authors attribute is omitted):
{
"name": {
"type": "string"
},
"id": {
"type": "integer",
"autoIncrement": true,
"primaryKey": true,
"unique": true
}
}
Why did it take out the authors attribute?
However, when I debug this in Chrome, though the authors attributes is still omitted, I am able to execute console.log(response.authors) and it reads it fine.
Also, when I go to the Network tab on Chrome dev tools to see the response of the HTTP request, it shows the missing attribute in the response body just fine.
I found out the problem. It was because console.log doesn't run right away. It runs after some time. I had other code that modified the object, but console.log ran after that code for some reason, even though I wrote it before.
Related
I'm trying to configure an Azure Table Storage output binding for an Azure Function (in JavaScript) using an identity-based connection instead of a connection string. I believe I've setup the Function as per the docs but I'm getting this error:
System.Private.CoreLib: Exception while executing function: Functions.AzureTvDataFetcher. Microsoft.Azure.WebJobs.Extensions.Storage: Storage account connection string 'AzureWebJobsAzuretvTableStorageConnection' does not exist. Make sure that it is a defined App Setting.
The error mentions that it should be a defined app setting, which it is. This is my local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "node",
"AzuretvTableStorageConnection__tableServiceUri": "https://<account-name>.table.core.windows.net"
}
}
And these are the triggers/bindings defined in function.json:
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "table",
"tableName": "azuretv",
"name": "azuretvTableBinding",
"direction": "out",
"connection": "AzuretvTableStorageConnection"
}
]
}
The docs mention that it requires the extension bundle version 2.x, which is installed, see my host.json:
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[2.*, 3.0.0)"
},
So I'm not sure what I'm doing wrong. If I use a connection string instead it works fine. I've also deployed the Function app, created a managed identity for it and assigned the Storage Table Data Contributor role to the storage account but I still get the same error. Any ideas?
I'm trying to do a POST to the Strapi API and can't seem to figure out how to attach a 'has and belongs to many' (many to many) relationship.
I've already tried the following body's:
events: ["ID", "ID"]
name: "name"
&
events: [ID, ID]
name: "name"
Which regarding the docs should be right, I think.
There's no error, I get a '200 OK' response. It adds the record but without the relations.
Event.settings.json:
{
"connection": "default",
"collectionName": "events",
"info": {
"name": "event",
"description": ""
},
"options": {
"increments": true,
"timestamps": [
"created_at",
"updated_at"
],
"comment": ""
},
"attributes": {
"name": {
"type": "string"
},
"artists": {
"collection": "artist",
"via": "events",
"dominant": true
}
}
}
Artist.settings.json:
{
"connection": "default",
"collectionName": "artists",
"info": {
"name": "artist",
"description": ""
},
"options": {
"increments": true,
"timestamps": [
"created_at",
"updated_at"
],
"comment": ""
},
"attributes": {
"name": {
"required": true,
"type": "string"
},
"events": {
"collection": "event",
"via": "artists"
}
}
}
I'm using the standard SQLite database, strapi version 3.0.0-beta.13 and tried the request through Postman, HTML & curl.
I would love to know how to attach the relation on POST
Update 23-07:
Did a fresh install of Strapi and now everything is working.
I think it's because your set you ID as a String instead of an Integer
{
events: [1, 2],
name: "My name"
}
And here 1 and 2 are the IDs of events you want to add.
Late reply. Hoping this might help someone!
Right now I am using Strapi v4.3.2 and was facing the same issue. I overcame this by overriding the default core controller for create as explained in official docs. Relations are now visible!
async create(ctx) {
const { data } = ctx.request.body;
const response = await strapi.entityService.create(
"api::collection.collection",
{
data: data,
}
);
return {response}
}
This is (still? again?) a bug in Strapi, see: https://github.com/strapi/strapi/issues/12238
As a workaround you need to add the find-permission to the user / role who is performing the request for the related content type (you want to check first if this is a security issue for your scenario or not - alternatively you might want to try Paratron's approach which is described in the comments).
I am trying to create a SharePoint ListItem using Microsoft Graph.
The methods I use to POST/PATCH ListItems are working unless I apply these methods to a list that contain objects (like Groups, Users or even Images).
In my examples, I'll be posting, patching or getting from /beta/sites/root/lists/1231231231234/items/4/fields.
SharePoint ListItem
{
"#odata.context":
"https://graph.microsoft.com/beta/$metadata#sites('root')/lists('1234123412341234')/items('4')/fields/$entity",
"#odata.etag": "\"123412341234,18\"",
"Title": "Test Title",
"description": "Some random description",
"assignedGroups": [
{
"LookupId": 7818,
"LookupValue": "7818",
"Email": "DemoGroep#12341234.onmicrosoft.com"
},
{
"LookupId": 7822,
"LookupValue": "7822",
"Email": "TestDemo#12341234.onmicrosoft.com"
}
],
"startDate": "2018-05-15T07:00:00Z",
"endDate": "2018-08-18T07:00:00Z",
"alwaysAvailable": false,
"id": "4",
"ContentType": "Item",
"Modified": "2018-05-17T13:27:21Z",
"Created": "2018-04-03T09:34:49Z",
"AuthorLookupId": "7688",
"EditorLookupId": "5222",
"_UIVersionString": "1.0",
"Attachments": false,
"Edit": "",
"LinkTitleNoMenu": "Test123123",
"LinkTitle": "Test123123",
"ItemChildCount": "0",
"FolderChildCount": "0",
"_ComplianceFlags": "",
"_ComplianceTag": "",
"_ComplianceTagWrittenTime": "",
"_ComplianceTagUserId": "",
"AppEditorLookupId": "25"
}
Working example (Note: This works because I update a simple field like 'Title' which is of type String)
{
Title: "SomeNewTitle"
}
Not working Example (returns 400 'The request is malformed or incorrect.')
{
assignedGroups: [{"Email": "Test1003#12341234o.onmicrosoft.com"}]
}
I tried multiple kinds of objects here but it never works.. even empty arrays (to clear group memberships) is returning 400 status.
I have a feeling that this is a limitation/bug in the Graph API
This is unfortunately a known issue with Microsoft Graph's SharePoint API. There is a UserVoice request to fix this, it could absolutely use more votes.
Try the PATCH body like this:
//PATCH
{
assignedGroups: {"Email": "Test1003#StichtingNuovo.onmicrosoft.com"}
}
Because in the listItem it is returning an array of assignedGroups but you are only updating one. If you needed to update multiple I believe the call would be:
//PATCH
{
assignedGroups: [{"Email": "Test1003#StichtingNuovo.onmicrosoft.com"},
{"Email": "AnotherEmail#microsoft.com"}
]
}
So, I've started playing with the Asterisk Restful Interface (ARI).
I have created a separate express app to do this.
I have a correctly configured instance of Asterisk 13 running. I know this because When I go to https://192.168.46.122:8088/ari/sounds in my browser, I am prompted for a username and password, which when entered, returns a valid JSON object back with the expected data...
[
{
"id": "conf-now-unmuted",
"text": "The conference is now unmuted.",
"formats": [
{
"language": "en",
"format": "gsm"
}
]
},
{
"id": "vm-nomore",
"text": "No more messages.",
"formats": [
{
"language": "en",
"format": "gsm"
}
]
},
{
"id": "vm-review",
"text": "press 1 to accept this recording press 2 to listen to it press 3 to rerecord your message",
"formats": [
{
"language": "en",
"format": "gsm"
}
]
},
{
"id": "demo-echodone",
"text": "The echo test has been completed.",
"formats": [
{
"language": "en",
"format": "gsm"
}
]
},
{
"id": "confbridge-rest-talk-vol-out",
"text": "...to reset your speaking volume to the default level.",
"formats": [
{
"language": "en",
"format": "gsm"
}
]
}, ...... etc etc
In my app.js file I have included the following code...
...
var logger = require('morgan');
var client = require('ari-client');
var url = 'https://192.168.46.122:8088/ari/sounds';
var username = 'correct_username';
var password = 'correct_password';
client.connect(url, username, password, function (err, ari) {
console.log('HELLLLLLOOOOO!!');
});
...
The issue, is that the anon callback is never fired. I never see 'HELLLLLLOOOOO!!'
Can anyone shed any light on why/under what circumstances this could happen? Are there any known bugs with the module that could be causing this?
Please let me know if you need further information about config, environment etc.
Thanks guys
UPDATE
Following comments below... I have tried the following:
client.connect(url, username, password)
.then(function(ari) {
console.log('HELLLLLLOOOOO!!');
})
.catch(function(err){
console.log('ERR: ' + err);
});
AND
client.connect(url, username, password, function (err, ari) {
if(err) console.log(err);
console.log('HELLLLLLOOOOO!!');
});
No error and no 'HELLLLLOOOOOO!!' at any point :-(
UPDATE 2
Have just visited /ari/api-docs/resources.json and got the following response... so it looks like it is present.
{
"_copyright": "Copyright (C) 2012 - 2013, Digium, Inc.",
"_author": "David M. Lee, II <dlee#digium.com>",
"_svn_revision": "$Revision: 430337 $",
"apiVersion": "1.7.0",
"swaggerVersion": "1.1",
"basePath": "http://192.168.46.122:8088/ari",
"apis": [
{
"path": "/api-docs/asterisk.{format}",
"description": "Asterisk resources"
},
{
"path": "/api-docs/endpoints.{format}",
"description": "Endpoint resources"
},
{
"path": "/api-docs/channels.{format}",
"description": "Channel resources"
},
{
"path": "/api-docs/bridges.{format}",
"description": "Bridge resources"
},
{
"path": "/api-docs/recordings.{format}",
"description": "Recording resources"
},
{
"path": "/api-docs/sounds.{format}",
"description": "Sound resources"
},
{
"path": "/api-docs/playbacks.{format}",
"description": "Playback control resources"
},
{
"path": "/api-docs/deviceStates.{format}",
"description": "Device state resources"
},
{
"path": "/api-docs/mailboxes.{format}",
"description": "Mailboxes resources"
},
{
"path": "/api-docs/events.{format}",
"description": "WebSocket resource"
},
{
"path": "/api-docs/applications.{format}",
"description": "Stasis application resources"
}
]
}
I'm now thinking it may be an SSL issue?!
Your connection is failing (for reasons outlined below), and because of an issue / upcoming-feature in node-ari-client, the failed connection is not logged.
The node-ari-client module uses Swagger, which expects to load a JSON schema describing an API. In the node-ari-client implementation, Swagger expects to find this JSON schema at %s//%s/ari/api-docs/resources.json.
So, the first thing to check is whether or not this exists / is accessible in your application:
https://192.168.46.122:8088/ari/api-docs/resources.json
There could be several reasons why this would not be available, but most likely the problem is authentication. You mention that when visiting your URL you are "prompted for a username and password". If your JSON schema (or any other files that need to be accessed without credentials) are behind authentication, you are going to need to rethink your application structure.
Currently, if there is a connection failure before Swagger has loaded the JSON schema, node-ari-client will fail silently. There is a Pull Request waiting which addresses this issue and would log the error, but in the meantime you should address the underlying issues which are preventing the connection.
If you can successfully access resources.json, there may be other issues with accessing resources. The URL you describe is accessing your service over https, but your resources.json file is telling Swagger to access it over regular http. To handle this, you could try:
Changing the basePath in your Swagger schema to use https:
"basePath": "https://192.168.46.122:8088/ari",
Adding a protocols field to your Swagger schema:
"protocols":["http", "https"]
Removing https
This is probably a good option in order to discover if https is the cause of the connection issue. Simply keep the Swagger schema exactly as is and try accessing / connecting to your services over http. Does this make a difference?
I have a Strongloop Loopback Node.js project with some models and relations.
The problem at hand
My problem relates how to query only those Media instances that have a relation to a certain Tag id, using the Angular SDK - while not querying Tags.media (which return Tag instances), but instead making a query somehow that returns plain Media instances.
Please read below for specific information..
Spec
Basically, I have a Model Media which has many 'tags' (model Tag). Think of a image file (Media) having various EXIF tags (Tag). Here is the relation spec (this all works as expected):
Media (media.json):
{
"name": "media",
"base": "PersistedModel",
"properties": {
"id": {
"type": "string",
"id": true
}
},
"relations": {
"tags": {
"type": "hasAndBelongsToMany",
"model": "tag"
}
}
Tag (tag.json):
{
"name": "tag",
"base": "PersistedModel",
"idInjection": true,
"properties": {
"name": {
"type": "string",
"required": true
}
},
"relations": {
"medias": {
"type": "hasAndBelongsToMany",
"model": "media"
}
},
"acls": [],
"methods": []
}
Solutions
Now, I know I could do a query like this (using Angular SDK in my example, but the syntax is the same):
injector.get('Tag').find({
'filter': {
'include': 'medias',
'where': {'id': <mytagid>}
}
});
My problem with this approach is, that I receive 1 (one) Tag instance with attached Media instances. This disrupts why whole workflow as I deal only with Media instances.. i just want to filter by Tag id, not bother about Tag at all.
Bottom line
If I see the API explorer (/explorer/), the return value of GET /api/tags/<myTagID>/medias is exactly what I need - an array of Media objects - but how to query them exactly like this using the Angular SDK (lb_services)?
I had a similar problem. One recommendation is to open the lb-services.js and try to find: /tags/:id/medias or something similar. Then you will find a comment like this: // INTERNAL. Use Tags.medias() instead. Or something similar. So that is the method that you should call. Do not call the "prototype$__get....." methods.
Then just call what it says there I suppose: Tag.medias({id:})
Other suggestions:
As you said in your description Media has many Tags. So why not use just
{
"name": "media",
"base": "PersistedModel",
"properties": {
"id": {
"type": "string",
"id": true
}
},
"relations": {
"tags": {
"type": "hasMany", <---------- hasMany
"model": "tag",
"foreignKey": "tagId" <---FK name
}
}
and
for the tags just belongsTo as type.
{
"name": "tag",
"base": "PersistedModel",
"idInjection": true,
"properties": {
"name": {
"type": "string",
"required": true
}
},
"relations": {
"medias": {
"type": "belongsTo",
"model": "media",
"foreignKey": "mediaId" <---FK name
}
},
"acls": [],
"methods": []
}
But really I don't think this is the problem because you said when you request GET /api/tags/<myTagID>/medias it returns what you want.
Then, in AngularJS you can use:
Media.tags({id:<mediaId>})
for media/:id/tags
and for the other side try:
Tag.medias({id:<tagId>})
Tag.find({
filter:{
where:{mediaId: <mediaId>} <----mediaId comes from FK name
}
})
In this case both are persistent models there is no problems, I had permission problems when doing a similar thing with data that extends User type. But that is another story...
Hope this is helpful, I changed some stuff from a similar app that I am doing and hope not making so many errors when adapting to your code...