I am using the Rally WSAPI 2.0p5 with and the JSON return
I am looking to get fields from multiple tables in a single response. Is this possible? For example I am trying to get the User Story and also get the Iteration.State in the same data response. I know it is possible to do client side and if that is the only way. Can someone provide and example how I handle the async response to build the table (array).
Simply add State to the list of attributes included in your fetch. Rally's WSAPI will populate the value for sub objects even if the main type being queried does not have that field.
launch: function() {
var userStories = Ext.create('Rally.data.WsapiDataStore', {
model: 'HierarchicalRequirement',
fetch: ['Iteration', 'State'],
autoLoad: true,
filters: [
{
property: 'Iteration.State',
value: 'Accepted'
}
],
limit: 10000,
listeners: { load: this._onDataLoaded, scope: this }
});
}
As a follow up for my original question. I recently came across the alpha release of the Batch Query WSAPI in Rally's WSAPI documentation. I would suggest the usage of the Batch Query to retrieve multiple Object Models in a single response.
As an example to get User Stories and get the Iteration Status in a single query.
{
"stories" : "/HierarchicalRequirement?fetch=Name,Iteration,State&query=(Iteration.State = Accepted)"
}
The result is something that is more usable and doesn't require multiple queries to the server. i.e.
"Results": [{
"_rallyAPIMajor": "1",
"_rallyAPIMinor": "40",
"_ref": "https://rally1.rallydev.com/slm/webservice/x/hierarchicalrequirement/xxxxxxxx.js",
"_objectVersion": "17",
"_refObjectName": "<user role> I would like <feature> for <benifit>",
"Name": "As a <user role> I would like <feature> for <benifit>",
"Iteration": {
"_rallyAPIMajor": "1",
"_rallyAPIMinor": "40",
"_ref": "https://rally1.rallydev.com/slm/webservice/x/iteration/xxxxxxxx.js",
"_objectVersion": "4",
"_refObjectName": "Sprint #",
"Name": "Sprint #",
"State": "Accepted",
"_type": "Iteration"
},
"Project": {
"_rallyAPIMajor": "1",
"_rallyAPIMinor": "40",
"_ref": "https://rally1.rallydev.com/slm/webservice/x/project/xxxxxxxx.js",
"_refObjectName": "Name",
"_type": "Project"
},
"_type": "HierarchicalRequirement"
},
....
]
For more information and a few resources:
https://rally1.rallydev.com/slm/doc/webservice/index.jsp?version=1.40
https://rally1.rallydev.com/slm/doc/webservice/batch.jsp
https://rally1.rallydev.com/slm/doc/webservice/BatchScratchPad.jsp
Related
MongoDB Atlas Cluster version: 5.0.12
MERN Stack Application
Simple Search App that returns Specific ads when keywords are typed in an input.
Front end is handled by React-Redux.
And I am using Axios to request my server for data.
Server is using Mongo's aggregate pipeline function to search for text using $search,
and then a few different operators to fetch data from another collection.
There are two collections, the main one has a foreign key that references the second one.
Here is a sample json of both the collections
ads: {
_id: 1,
companyId: 1,
primaryText: "",
description: "",
CTA: "Sign Up",
imageUrl: "",
heading: "",
}
companies: {
_id: 1,
name: "Levi's",
url: "",
}
This is the search index that I have been using to look for keywords in the collection.
{
"mappings": {
"dynamic": true,
"fields": {
"company": {
"fields": {
"name": [
{
"dynamic": true,
"type": "document"
},
{
"type": "string"
}
]
},
"type": "document"
},
"description": [
{
"dynamic": true,
"type": "document"
},
{
"type": "string"
}
],
"heading": [
{
"dynamic": true,
"type": "document"
},
{
"type": "string"
}
],
"primaryText": [
{
"dynamic": true,
"type": "document"
},
{
"type": "string"
}
]
}
}
}
Mongo doesn't let me query $search anywhere in the pipeline except as the first operation.
So the order that works is this
$seach --> $lookup --> $project --> $unwind
This works but the only problem is that when I try to search for keyword that is present in the companies collection, like name: "Levi's", it doesn't respond with the corresponding ad.
So, In short I am trying to find a way to apply $search on a collection that has the gone through a $lookup.
Thank you, and I appreciate you spending time reading this.
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 have set up json-server using a react app and I had a quick question about end points
this is some of my data:
{
"products": [
{
"name": "football",
"id": "SPO-001",
"category": "sport",
"price": "40",
"coupons": ["daw124qdw", "a1212cxn"]
},
{
"name": "cricket bat",
"id": "SPO-002",
"category": "sport",
"price": "80"
}
]
}
and it all works fine when i do something like this:
axios.get('http://localhost:3004/products').then(({ data }) => {
// do something with data
})
and I know I can do: http://localhost:3004/products/SPO-001 which returns me the id for that. but how can I just return the coupons entry for that specific id? is that a possible endpoint?
I tried axios.get('http://localhost:3004/products/SPO-001/coupons') but I just got an empty object. any ideas?
You have 2 options:
1st
axios.get('http://localhost:3004/products')
.then(res => this.setState({product: res.data.productID.coupon})) // not sure how you want to use your response, this is just an example
2nd create your endpoint for each product, something like http://localhost:3004/:productID/coupon and then "hit" that endpoint with your axios get request, e.g. axios.get('http://localhost:3004/23/coupon').then(res => res.data)
I would have to say the 2nd option would be more robust.
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"}
]
}
I've done Dan Abramov's intro series on EggHead, and am working on a real world app. The domain is complex, so I'll run with a classic "blogs" example.
Let's say, we have an "index / list" page, where all we need to show are the blog post's title and blurb. So we have an API endpoint that returns that, and we store it in our state tree under blogs.byId.
Then, when you click through on a blog post, we actually need a bunch more info - e.g. the full blog post, and also tags and categories. Let's call this "blogs with metadata".
Stretching the example, there might be another completely separate page where I want to display a list of blog posts with the most recent 3 comments. Let's call this "blogs with comments".
My question is, how should my state tree treat these separate examples where I'm storing the same "thing" but in different "formats"? My initial hunch would be to treat them as completely separate data types, so my state tree would have eg: blogs.byId, blogsWithMetadata.byId and blogsWithComments.byId.
And then, even if every single blog post is cached in the blogs.byId section, the minute we need to view a blog post, the app completely ignores that warm blogs.byId cache, and looks only at blogsWithMetadata.byId - so we'd essentially be building up 3 separate caches of blog data, each with different amounts of info, and treating it as though they are as unrelated to each other as "blogs" and a completely unrelated table like "widgets" would be.
Is this correct? Or is there a better way?
The app currently rams them all under the same node, without distinction based on "format" and it's causing a world of pain.
There are probably many ways you could choose to do this. One of it is to use normalizr to structure your data.
Your blog post could have a data structure returned by the API like this:
{
"id": "123",
"author": {
"id": "1",
"name": "Paul"
},
"title": "My awesome blog post",
"comments": [{
"id": "324",
"commenter": {
"id": "2",
"name": "Nicole"
}
}],
"tags": [{
"id": "1",
"value": "awesome"
}, {
"id": "2",
"value": "journal"
}],
"categories": [{
"id": "1",
"value": "personal"
}, {
"id": "2",
"value": "life"
}]
}
which after normalizing, will look something like this:
{
entities: {
"post": {
"123": {
id: "123",
author: "1",
title: "My awesome blog post",
comments: ["324"],
tags: ["1", "2"],
categories: ["1", "2"],
}
},
"users": {
"1": { "id": "1", "name": "Paul" },
"2": { "id": "2", "name": "Nicole" }
},
"comments": {
"324": { id: "324", "commenter": "2" }
}
"tags": {
"1": { id: "1", "value": "awesome" },
"2": { id: "2", "value": "journal" },
}
"categories": {
"1": { id: "1", "value": "personal" },
"2": { id: "2", "value": "life" },
}
}
}
Subsequently, you could have a state for each page if you needed to:
{
entities: {...},
ui: {
blogs: {
posts: [1, 2],
hasComments: false,
// Displaying the blogs with or without comments
// could simply just be a boolean flag in state.
},
}
}
using reselect, you then create the selectors to pass the posts you want as props to the page Components.