Related
Just started playing around withPostman a week ago to make life easier.
Situation :
I have a get request which returns x amount of key (Jira userstories)
What do i want to achieve :
I want to create subtask for each of the keys i get back from the GET request with Postman
The POST part on how to create the subtask is already done. My issue is specifically looping through the GET request list to create it for every story.
Any help would be much appreciated
My postman GET request :
{
"expand": "schema,names",
"startAt": 0,
"maxResults": 50,
"total": 8,
"issues": [
{
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
"id": "59332",
"self": "xxx",
**"key": "GRIP-502"**
},
{
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
"id": "58465",
"self": "xx",
"key": "GRIP-429"
},
{
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
"id": "56409",
"self": "xxxx",
**"key": "GRIP-338"**
},
{
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
"id": "55191",
"self": "xxx",
"key": "GRIP-246"
},
{
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
"id": "55180",
"self": "xx",
**"key": "GRIP-244"**
},
{
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
"id": "52783",
"self": "xx",
"key": "GRIP-104"
},
{
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
"id": "51641",
"self": "xxx",
"key": "GRIP-69"
},
{
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
"id": "51473",
"self": "xx",
"key": "GRIP-48"
}
]
}
in the first request where you get the information store the issues into a variable:
pm.environment.set("issues",pm.response.json().issues)
In the pre-request section of the POSt request you want to send use :
let array = pm.environment.get("issues")
let issue = array.pop()
pm.environment.set("issues",array)
pm.environment.set("id",issue.id) // or key what ever you want
array.length!==0?postman.setNextRequest(pm.info.requestName):null
You could write a javascript function to iterate and process each issue in your response. For example:
function createSubTask(issueId) {
console.log(`POST Subtask: ${issueId}`);
}
for (let subtask of response.issues) {
createSubTask(subtask.id)
}
You can find more help here
[
{
"id": "2448ec2e-b849-4835-9c6a-02ea7b28f298",
"name": "test sequence for Abort",
"description": "This a test sequence",
"type": "Product",
"createDate": "2018-08-09T21:01:47.3120000Z",
"lastUpdateDate": "2018-08-09T21:01:47.3120000Z",
"lastUpdateUser": "José Carlos",
"variables": [
{
"id": "afa2f2e1-e3be-4dff-a7ad-817b7d25be64",
"name": "Result1",
"type": "string"
},
{
"id": "a0914b11-43ff-475a-ac44-65da1fd68aea",
"name": "Result2",
"type": "string"
},
{
"id": "5a3277d3-386d-4a12-b373-af38d91a727d",
"name": "Result3",
"type": "string"
},
{
"id": "61fc107a-8929-4a33-8f26-2a0228344adc",
"name": "Result4",
"type": "string"
},
{
"id": "598a1843-12f0-42ea-819d-944c1e1d6060",
"name": "Result5",
"type": "string"
},
{
"id": "c6182b5f-df2f-4d6d-91b0-77e8679f052f",
"name": "Result6",
"type": "string"
},
{
"id": "a368b7db-3d0c-4385-9f56-ad9793072b97",
"name": "Result7",
"type": "string"
},
{
"id": "ae5db407-ce44-485c-a1a2-e0ae33353279",
"name": "Result8",
"type": "string"
},
{
"id": "760bb1f1-70f6-49e9-a9b4-9e8d7e26b14a",
"name": "Result9",
"type": "string"
}
],
"instructions": null
},
{
"id": "888108a7-2101-4aeb-b1ec-6ad779b8c09d",
"name": "test sequence for initial",
"description": "This a test sequence",
"type": "0",
"createDate": "2018-08-09T21:02:24.8290000Z",
"lastUpdateDate": "2018-08-09T21:02:24.8290000Z",
"lastUpdateUser": "José Carlos",
"variables": [
{
"id": "afa2f2e1-e3be-4dff-a7ad-817b7d25be64",
"name": "Result1",
"type": "string"
},
{
"id": "a0914b11-43ff-475a-ac44-65da1fd68aea",
"name": "Result2",
"type": "string"
},
{
"id": "5a3277d3-386d-4a12-b373-af38d91a727d",
"name": "Result3",
"type": "string"
},
{
"id": "61fc107a-8929-4a33-8f26-2a0228344adc",
"name": "Result4",
"type": "string"
},
{
"id": "598a1843-12f0-42ea-819d-944c1e1d6060",
"name": "Result5",
"type": "string"
},
{
"id": "c6182b5f-df2f-4d6d-91b0-77e8679f052f",
"name": "Result6",
"type": "string"
},
{
"id": "a368b7db-3d0c-4385-9f56-ad9793072b97",
"name": "Result7",
"type": "string"
},
{
"id": "ae5db407-ce44-485c-a1a2-e0ae33353279",
"name": "Result8",
"type": "string"
},
{
"id": "760bb1f1-70f6-49e9-a9b4-9e8d7e26b14a",
"name": "Result9",
"type": "string"
}
],
"instructions": null
}
]
I'm trying to get the value of:
"id": "598a1843-12f0-42ea-819d-944c1e1d6060",
"name": "Result5",
"type": "string"
I managed a way to get the values.
Now, i have 9 env variables for id, name and type and i want to pass the values to them without creating a set event for each.
the env variables are:
varID1 to varID9,
varName1 to varName9,
varType1 to varType9.
I'm trying the bellow code but the name created by"varID ='varId'+k", e.g varID1 isn´t used on the set.
i can´t see why this doesn´t work.
for ( var j = 0; j < test ; j ++ ) {
var k = j + 1;
var varID ='varId'+k;
var varName ='varName'+k;
var varType ='varType'+k;
pm.environment.set(varID, jsonData[key].variables[j].id);
pm.environment.set(varName, jsonData[key].variables[j].name);
pm.environment.set(varType, jsonData[key].variables[j].type);
console.log(varID + " " + jsonData[key].variables[j].id );
console.log(varName + " " + jsonData[key].variables[j].name);
console.log(varType + " " + jsonData[key].variables[j].type);
}
Do you have a suggestion?
Would this help you achieve the same thing? It could be cleaner but I think it would be the same.
let idCount = 1
let nameCount = 1
let typeCount = 1
_.each(_.first(pm.response.json()).variables, (arrItem) => {
pm.environment.set(`varID${idCount ++}`, arrItem.id);
pm.environment.set(`varName${nameCount ++}`, arrItem.name);
pm.environment.set(`varType${typeCount ++}`, arrItem.type);
})
It would store the variables like this:
I try to use a {json:api}-JSON with ember.js (1.13.3) and ember-data (1.13.4) by using the DS.JSONAPIAdapter.
The JSON:
{
"data": [
{
"type": "altersgruppe",
"id": "1",
"attributes": {
"name": "ALTER_21_24",
"tarifbeitraege": [
{
"type": "tarifbeitrag",
"id": "1",
"attributes": {
"name": "REISE",
"beitrag": "12.70",
"proergaenzung": "7,00",
"gesamtbeitrag": "25.99"
}
},
{
"type": "tarifbeitrag",
"id": "2",
"attributes": {
"name": "KRANKEN",
"beitrag": "25,70",
"proergaenzung": "7,00",
"gesamtbeitrag": "25.99"
}
}
]
}
},
{
"type": "altersgruppe",
"id": "2",
"attributes": {
"name": "ALTER_25_30",
"tarifbeitraege": [
{
"type": "tarifbeitrag",
"id": "3",
"attributes": {
"name": "REISE",
"beitrag": "29,70",
"proergaenzung": "7,00",
"gesamtbeitrag": "25.99"
}
},
{
"type": "tarifbeitrag",
"id": "4",
"attributes": {
"name": "KRANKEN",
"beitrag": "28,70",
"proergaenzung": "7,00",
"gesamtbeitrag": "30.99"
}
}
]
}
}
]
}
The models:
App.Altersgruppe = DS.Model.extend({
name: DS.attr('string'),
tarifbeitraege: DS.hasMany('tarifbeitrag', {async: true})
});
App.Tarifbeitrag = DS.Model.extend({
altersgruppe: DS.belongsTo('altersgruppe'),
name: DS.attr('string'),
beitrag: DS.attr('string'),
proergaenzung: DS.attr('string'),
gesamtbeitrag: DS.attr('string')
});
When I used the ember-inspector to see the data only the model "altersgruppe" has records. The model "tarifbeitrag" has no records.
So why?
The adapter:
App.AltersgruppeAdapter = DS.JSONAPIAdapter.extend({
namespace: REST_ADAPTER_NAMESPACE,
shouldBackgroundReloadRecord: function(store, snapshot){
return false;
}
});
It seems to me that the "hasMany"-Relationship does not work. How to fix that. Any ideas (JSON wrong? Model wrong). Thank you.
Because of Mike1o1's tip to read the {json:api}-Spec again and I made the
decision to changed the structure of the JSON to this:
{
"data": [
{
"type": "altersgruppe",
"id": "1",
"attributes": {
"name": "ALTER_21_24"
},
"relationships": {
"tarifbeitraege": {
"data": [
{
"type": "tarifbeitrag",
"id": "1"
},
{
"type": "tarifbeitrag",
"id": "2"
}
]
}
}
},
{
"type": "altersgruppe",
"id": "2",
"attributes": {
"name": "ALTER_25_30"
},
"relationships": {
"tarifbeitraege": {
"data": [
{
"type": "tarifbeitrag",
"id": "3"
},
{
"type": "tarifbeitrag",
"id": "4"
}
]
}
}
}
],
"included": [
{
"type": "tarifbeitrag",
"id": "1",
"attributes": {
"name": "REISE",
"beitrag": "25,70",
"proergaenzung": "7,00",
"gesamtbeitrag": "25.99"
}
},
{
"type": "tarifbeitrag",
"id": "2",
"attributes": {
"name": "KRANKEN",
"beitrag": "25,70",
"proergaenzung": "7,00",
"gesamtbeitrag": "25.99"
}
},
{
"type": "tarifbeitrag",
"id": "3",
"attributes": {
"name": "REISE",
"beitrag": "29,70",
"proergaenzung": "7,00",
"gesamtbeitrag": "25.99"
}
},
{
"type": "tarifbeitrag",
"id": "4",
"attributes": {
"name": "KRANKEN",
"beitrag": "28,70",
"proergaenzung": "7,00",
"gesamtbeitrag": "30.99"
}
}
]
}
This works with the DS.JSONAPIAdapter. Now in the ember-inspector I can see that the model "tarifbeitrag" has also records.
At first glance this doesn't look like a valid json-api response. tarifbeitraege should be a linked relationship, not embedded in the actual attributes of the data type. I don't believe json-api supports embedded attributes like that. Take a look at compound documents part of the spec for an example of what your json output should be.
My fixture data contains multiple array.Out of this multiple array cart_items contains some product data.
I am trying to calculate total no of products available in cart data (based on length of cart_items items) but i am not able to calculate no of items are present in cart_items.
In router i have selected application fixture as model for current route,as follow :
Astcart.IndexRoute = Ember.Route.extend({
model: function() {
return Astcart.Application.find();
}
});
Computed property code :
Astcart.IndexController = Ember.ArrayController.extend({
tot_cart_prd: function() {
return this.get("model.cart_items").get('length');
}.property("#each.isLoaded")
});
And my fixture data is :
Astcart.Application.adapter = Ember.FixtureAdapter.create();
Astcart.Application.FIXTURES = [
{
"logo_url": "img/logo.jpg",
"logged_in": {
"logged": true,
"username": "sachin",
"account_id": "4214"
},
"category_list": [
{
"id": "1",
"name": "Mobiles & Accessories"
},
{
"id": "2",
"name": "Computers & Software"
},
{
"id": "3",
"name": "Fashion"
},
{
"id": "4",
"name": "Electronics"
},
{
"id": "5",
"name": "Watches & Jewelry"
},
{
"id": "6",
"name": "Health & Beauty"
},
{
"id": "7",
"name": "Games"
},
{
"id": "8",
"name": "Books & Entertainment"
},
{
"id": "9",
"name": "Gaming"
},
{
"id": "10",
"name": "Shoes & Bags"
}
],
"cart_items": [
{
"id": "1",
"name": "Samsung Galaxy Tab 2",
"qty": "1",
"price": "1245.12",
"subtotal": "7842.23"
},
{
"id": "2",
"name": "Samsung Galaxy Tab 2",
"qty": "1",
"price": "1245.12",
"subtotal": "7842.23"
},
{
"id": "3",
"name": "Samsung Galaxy Tab 2",
"qty": "1",
"price": "1245.12",
"subtotal": "7842.23"
}
]
}
];
I have posted my code here(JSFiddle).
Can any one tell me why this.get("model.cart_items") is returning null?
Because your IndexController receive an array of Astcart.Application, from the route. You need to iterate in each application and get the length of each category list .
Your computed property need to be the following:
Astcart.IndexController = Ember.ArrayController.extend({
tot_cart_prd: function() {
var result = this.get('model').map(function(application) {
return application.get('category_list.length');
});
return result;
}.property('model.#each.category_list.length')
});
Here's an updated fiddle http://jsfiddle.net/marciojunior/PZZym/
I just looked at this and your core issue has something to do with the relationship setup between Application and Cart_items. The reason that this.get("model.cart_items").get('length') is failing is that this.get("model.cart_items") returns null. If you can get your relationship working you should be on the right track. I don't know anything about EmberModel, so I can't be of much help there.
Can anyone help me, When I request using link
https://graph.facebook.com/search?&limit=2&until=now&q=hi&type=post&access_token=AAAAAAITEghMBAIScEzst3h5VpV8pKZA7di2ZC3czxr5
Note: I am not giving valid token for security reason.
I always get the result for 27 Nov 2012, while I tried to search for latest post. Am I missing something? Please help.
Thanks in Advance.
RESULT I get:
{
"data": [
{
"id": "730221920_10151138508071921",
"from": {
"name": "Pinky Saowichit",
"id": "730221920"
},
"message": "\u0e2d\u0e32\u0e17\u0e34\u0e15\u0e22\u0e4c\u0e19\u0e35\u0e49\u0e2d\u0e32\u0e08\u0e44\u0e21\u0e48\u0e44\u0e14\u0e49\u0e2d\u0e2d\u0e31\u0e19\u0e1a\u0e48\u0e2d\u0e22\u0e46 \u0e19\u0e30\u0e04\u0e30 \u0e41\u0e1f\u0e19\u0e04\u0e25\u0e31\u0e1a \u0e43\u0e2b\u0e49\u0e23\u0e39\u0e49\u0e27\u0e48\u0e48\u0e32\u0e04\u0e34\u0e14\u0e16\u0e36\u0e07\u0e19\u0e30\u0e04\u0e30 \u0e41\u0e15\u0e48\u0e15\u0e2d\u0e19\u0e19\u0e35\u0e49\u0e40\u0e23\u0e32\u0e01\u0e33\u0e25\u0e31\u0e07\u0e04\u0e34\u0e14\u0e16\u0e36\u0e07\u0e04\u0e38\u0e13 \u0e04\u0e32\u0e19\u0e18\u0e35\u0e41\u0e25\u0e30\u0e40\u0e17\u0e40\u0e23\u0e0b\u0e48\u0e32\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e21\u0e32\u0e01\u0e46 \u0e2b\u0e38 \u0e2b\u0e38",
"privacy": {
"value": ""
},
"type": "status",
"status_type": "mobile_status_update",
"created_time": "2012-11-27T03:12:32+0000",
"updated_time": "2012-11-27T07:44:54+0000",
"likes": {
"data": [
{
"name": "Weniefredo Laud",
"id": "100004751890183"
},
{
"name": "\u0e1e\u0e23\u0e15 \u0e1c\u0e25\u0e14\u0e35",
"id": "100001056963372"
},
{
"name": "\u0e08\u0e23\u0e34\u0e0d\u0e32 \u0e25\u0e2d\u0e27",
"id": "100000046347271"
},
{
"name": "Noolek Tikamborn",
"id": "100003048464258"
}
],
"count": 6
}
},
{
"id": "100003971930240_283727615063091",
"from": {
"name": "Mariana Salcedo",
"id": "100003971930240"
},
"story": "Mariana Salcedo shared a link.",
"picture": "http://external.ak.fbcdn.net/safe_image.php?d=AQASxQms6c0xFkdO&w=90&h=90&url=http\u00253A\u00252F\u00252Fask.fm\u00252Fimages\u00252F50x50.gif",
"link": "http://ask.fm/marianasalcedo/answer/15735435637",
"name": "CRUSH hi",
"caption": "jajajajaja que enfadosa erees!",
"icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yN/x/aS8ecmYRys0.gif",
"privacy": {
"value": ""
},
"type": "link",
"status_type": "shared_story",
"application": {
"name": "Ask.fm",
"id": "129215213762342"
},
"created_time": "2012-11-27T03:11:38+0000",
"updated_time": "2012-11-27T03:11:38+0000"
}
],
"paging": {
"previous": "https://graph.facebook.com/search?q=hi&limit=2&type=post&access_token=AAAAAAITEghMBAIScEzst3h5VpV8pKZA7di2ZC3czxr5ANnvKPPc1wqYJJZAANd9PI0NKLX5Xk5ReRX3T01iim8BoJp6r16itU8vPxRP&since=1353985952&__previous=1",
"next": "https://graph.facebook.com/search?q=hi&limit=2&type=post&access_token=AAAAAAITEghMBAIScEzst3h5VpV8pKZA7di2ZC3czxr5ANnvKPPc1wqYJJZAANd9PI0NKLX5Xk5ReRX3T01iim8Bo&until=1353985897"
}
}