I am trying to get Values from JSON in Node.JS - node.js

I am trying to get values from a json in node.
Here is the code:
https.get('https://www.reddit.com/r/cute/random.json', (resp) => {
let data = '';
resp.on('data', (chunk) => {
data += chunk;
});
const obj = JSON.parse(data);
resp.on('end', () => {
console.log(obj.url);
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
First I get the json file from Reddit, then the code should parse the data, get the url value and print.
Here is a response from reddit:
[{"kind": "Listing", "data": {"modhash": "k08cakl21qf62e475cdf685ff8f62982c15997278420b30b86", "dist": 1, "children": [{"kind": "t3", "data": {"approved_at_utc": null, "subreddit": "cute", "selftext": "", "user_reports": [], "saved": false, "mod_reason_title": null, "gilded": 0, "clicked": false, "title": "Took this picture at my local zoo", "link_flair_richtext": [], "subreddit_name_prefixed": "r/cute", "hidden": false, "pwls": 6, "link_flair_css_class": null, "downs": 0, "thumbnail_height": 140, "top_awarded_type": null, "parent_whitelist_status": "all_ads", "hide_score": false, "name": "t3_np1ulg", "quarantine": false, "link_flair_text_color": "dark", "upvote_ratio": 1.0, "author_flair_background_color": null, "subreddit_type": "public", "ups": 13, "total_awards_received": 0, "media_embed": {}, "thumbnail_width": 140, "author_flair_template_id": null, "is_original_content": false, "author_fullname": "t2_6oq8e4ri", "secure_media": null, "is_reddit_media_domain": true, "is_meta": false, "category": null, "secure_media_embed": {}, "link_flair_text": null, "can_mod_post": false, "score": 13, "approved_by": null, "is_created_from_ads_ui": false, "author_premium": false, "thumbnail": "https://b.thumbs.redditmedia.com/rcVqy9jgOCmApJ36YpAN9CCDQ2lRC0hSsAqBpt0zBxw.jpg", "edited": false, "author_flair_css_class": null, "author_flair_richtext": [], "gildings": {}, "post_hint": "image", "content_categories": null, "is_self": false, "mod_note": null, "created": 1622491454.0, "link_flair_type": "text", "wls": 6, "removed_by_category": null, "banned_by": null, "author_flair_type": "text", "domain": "i.redd.it", "allow_live_comments": false, "selftext_html": null, "likes": null, "suggested_sort": null, "banned_at_utc": null, "url_overridden_by_dest": "https://i.redd.it/h9b00p6y4g271.jpg", "view_count": null, "archived": false, "no_follow": false, "is_crosspostable": true, "pinned": false, "over_18": false, "preview": {"images": [{"source": {"url": "https://preview.redd.it/h9b00p6y4g271.jpg?auto=webp&s=9962d8aa05efc905e39b67bff7a3385576ef4267", "width": 2448, "height": 3264}, "resolutions": [{"url": "https://preview.redd.it/h9b00p6y4g271.jpg?width=108&crop=smart&auto=webp&s=a30f747ccc3a51648498dbe90ffc92f114f438e5", "width": 108, "height": 144}, {"url": "https://preview.redd.it/h9b00p6y4g271.jpg?width=216&crop=smart&auto=webp&s=4bade02391aff8db706eeb74c3354aace0195048", "width": 216, "height": 288}, {"url": "https://preview.redd.it/h9b00p6y4g271.jpg?width=320&crop=smart&auto=webp&s=76bec250dec57f8ee75c379188c2d209eaa21646", "width": 320, "height": 426}, {"url": "https://preview.redd.it/h9b00p6y4g271.jpg?width=640&crop=smart&auto=webp&s=520ab610461f06a6d64f3a183ef25e33cdee4625", "width": 640, "height": 853}, {"url": "https://preview.redd.it/h9b00p6y4g271.jpg?width=960&crop=smart&auto=webp&s=961c512920a728777b9b13185d53f9afe4f6aaea", "width": 960, "height": 1280}, {"url": "https://preview.redd.it/h9b00p6y4g271.jpg?width=1080&crop=smart&auto=webp&s=6f943fbd5d53b892dd15b28052f12c929e5887b9", "width": 1080, "height": 1440}], "variants": {}, "id": "W08V856IQ3icquk8jx2Q0UiWHZnlDFcsSY7Cdu8J-S4"}], "enabled": true}, "all_awardings": [], "awarders": [], "media_only": false, "can_gild": true, "spoiler": false, "locked": false, "author_flair_text": null, "treatment_tags": [], "visited": false, "removed_by": null, "num_reports": null, "distinguished": null, "subreddit_id": "t5_2qh5l", "mod_reason_by": null, "removal_reason": null, "link_flair_background_color": "", "id": "np1ulg", "is_robot_indexable": true, "num_duplicates": 0, "report_reasons": null, "author": "ForMotherRussia3", "discussion_type": null, "num_comments": 1, "send_replies": true, "media": null, "contest_mode": false, "author_patreon_flair": false, "author_flair_text_color": null, "permalink": "/r/cute/comments/np1ulg/took_this_picture_at_my_local_zoo/", "whitelist_status": "all_ads", "stickied": false, "url": "https://i.redd.it/h9b00p6y4g271.jpg", "subreddit_subscribers": 96358, "created_utc": 1622462654.0, "num_crossposts": 0, "mod_reports": [], "is_video": false}}], "after": null, "before": null}}, {"kind": "Listing", "data": {"modhash": "k08cakl21qf62e475cdf685ff8f62982c15997278420b30b86", "dist": null, "children": [{"kind": "t1", "data": {"total_awards_received": 0, "approved_at_utc": null, "comment_type": null, "awarders": [], "mod_reason_by": null, "banned_by": null, "ups": 1, "author_flair_type": "text", "removal_reason": null, "link_id": "t3_np1ulg", "author_flair_template_id": null, "likes": null, "replies": "", "user_reports": [], "saved": false, "id": "h02og3g", "banned_at_utc": null, "mod_reason_title": null, "gilded": 0, "archived": false, "no_follow": true, "author": "AutoModerator", "can_mod_post": false, "send_replies": false, "parent_id": "t3_np1ulg", "score": 1, "author_fullname": "t2_6l4z3", "report_reasons": null, "approved_by": null, "all_awardings": [], "subreddit_id": "t5_2qh5l", "body": "This is the perfect post for r/cute!\n\n*I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/cute) if you have any questions or concerns.*", "edited": false, "downs": 0, "author_flair_css_class": null, "is_submitter": false, "collapsed": false, "author_flair_richtext": [], "author_patreon_flair": false, "body_html": "<div class=\"md\"><p>This is the perfect post for <a href=\"/r/cute\">r/cute</a>!</p>\n\n<p><em>I am a bot, and this action was performed automatically. Please <a href=\"/message/compose/?to=/r/cute\">contact the moderators of this subreddit</a> if you have any questions or concerns.</em></p>\n</div>", "gildings": {}, "collapsed_reason": null, "associated_award": null, "stickied": false, "author_premium": true, "subreddit_type": "public", "can_gild": true, "top_awarded_type": null, "author_flair_text_color": null, "score_hidden": false, "permalink": "/r/cute/comments/np1ulg/took_this_picture_at_my_local_zoo/h02og3g/", "num_reports": null, "locked": false, "name": "t1_h02og3g", "created": 1622491455.0, "subreddit": "cute", "author_flair_text": null, "treatment_tags": [], "created_utc": 1622462655.0, "subreddit_name_prefixed": "r/cute", "controversiality": 0, "depth": 0, "author_flair_background_color": null, "collapsed_because_crowd_control": null, "mod_reports": [], "mod_note": null, "distinguished": "moderator"}}], "after": null, "before": null}}]
When I run the code (Includes are present but not shown in the code snippet I have imported https) I get this error:
SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at ClientRequest.<anonymous> (C:\Users\cameron\Desktop\cjp\bot.js:22:20)
at Object.onceWrapper (node:events:485:26)
at ClientRequest.emit (node:events:378:20)
at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:636:27)
at HTTPParser.parserOnHeadersComplete (node:_http_common:129:17)
at TLSSocket.socketOnData (node:_http_client:502:22)
at TLSSocket.emit (node:events:378:20)
at addChunk (node:internal/streams/readable:313:12)
at readableAddChunk (node:internal/streams/readable:288:9)
Thanks in advance for any help!

Updated code here:
const fetch = require("node-fetch");
const main = async () => {
const json = await fetch("https://www.reddit.com/r/cute/random.json").then(
res => res.json()
);
console.log(
json
.map(entry => entry.data.children.map(child => child.data.url))
.flat()
.filter(Boolean)
);
};
main();
I am iterating it through the data and getting the output of the listing, I guess only one URL gets populated of k3 kind. So you get this as an output here:
Run #1
[ 'https://i.redd.it/pjom447yp8271.jpg' ]
Run #2
[ 'https://i.redd.it/h9b00p6y4g271.jpg' ]
Run #3
[ 'https://v.redd.it/lcejh8z6zp271' ]
Previous Answer for your reference:
In simple way, you can use something like node-fetch:
const fetch = require("node-fetch");
const main = async () => {
const json = await fetch("https://www.reddit.com/r/cute/random.json").then(
res => res.json()
);
console.log(json);
};
main();
You'll get the contents in the console.log(). When I run it with Node JS, I get the output so.js:
$ node so
[
{
kind: 'Listing',
data: {
modhash: '',
dist: 1,
children: [Array],
after: null,
before: null
}
},
{
kind: 'Listing',
data: {
modhash: '',
dist: null,
children: [Array],
after: null,
before: null
}
}
]

Related

How to get Product and Quantity information from payment_intent.succeeded event via Webhooks in Stripe?

Here is how I'm initializing the Checkout Process in Node.js.
let email = req.body.email
let product_id = req.body.product_id
let YOUR_DOMAIN = 'http://localhost:8000'
const session = await stripe.checkout.sessions.create({
line_items: [{
price: product_id,
adjustable_quantity: {
enabled: true,
minimum: 1,
maximum: 5,
},
quantity: 1,
}],
customer_email: email,
mode: 'payment',
success_url: `${YOUR_DOMAIN}/payment-success`,
cancel_url: `${YOUR_DOMAIN}/payment-failure`,
});
Here are the events I have subscribed to in Webhooks
payment_intent.succeeded
checkout.session.completed
Object Received in Payment Intent Succeeded
{
"id": "evt_1KEqIxI5cib7rtVMoKMkak96",
"object": "event",
"api_version": "2020-03-02",
"created": 1641453754,
"data": {
"object": {
"id": "pi_1KEqIeI5cib7rtVMcz8zsXys",
"object": "payment_intent",
"amount": 59700,
"amount_capturable": 0,
"amount_received": 59700,
"application": null,
"application_fee_amount": null,
"automatic_payment_methods": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic",
"charges": {
"object": "list",
"data": [{
"id": "ch_1KEqIvI5cib7rtVMYUVn5gfQ",
"object": "charge",
"amount": 59700,
"amount_captured": 59700,
"amount_refunded": 0,
"application": null,
"application_fee": null,
"application_fee_amount": null,
"balance_transaction": "txn_1KEqIwI5cib7rtVMGfJlEahg",
"billing_details": {
"address": {
"city": "NY",
"country": "US",
"line1": "sada",
"line2": "asd",
"postal_code": "10001",
"state": "NY"
},
"email": "test#gmail.com",
"name": "John Doe",
"phone": null
},
"calculated_statement_descriptor": "VIDEOFORM",
"captured": true,
"created": 1641453753,
"currency": "usd",
"customer": "cus_KufeYc1hifvZGA",
"description": null,
"destination": null,
"dispute": null,
"disputed": false,
"failure_code": null,
"failure_message": null,
"fraud_details": {},
"invoice": null,
"livemode": false,
"metadata": {},
"on_behalf_of": null,
"order": null,
"outcome": {
"network_status": "approved_by_network",
"reason": null,
"risk_level": "normal",
"risk_score": 25,
"seller_message": "Payment complete.",
"type": "authorized"
},
"paid": true,
"payment_intent": "pi_1KEqIeI5cib7rtVMcz8zsXys",
"payment_method": "pm_1KEqIuI5cib7rtVMYPWlLV8S",
"payment_method_details": {
"card": {
"brand": "visa",
"checks": {
"address_line1_check": "pass",
"address_postal_code_check": "pass",
"cvc_check": "pass"
},
"country": "US",
"exp_month": 1,
"exp_year": 2023,
"fingerprint": "QaiTi5PATFO8ZoC3",
"funding": "credit",
"installments": null,
"last4": "4242",
"mandate": null,
"network": "visa",
"three_d_secure": null,
"wallet": null
},
"type": "card"
},
"receipt_email": null,
"receipt_number": null,
"receipt_url": "https://pay.stripe.com/receipts/acct_1GhUSuI5cib7rtVM/ch_1KEqIvI5cib7rtVMYUVn5gfQ/rcpt_KufeysPW3LD8Yu47q14iYOIIlcGth9h",
"refunded": false,
"refunds": {
"object": "list",
"data": [],
"has_more": false,
"total_count": 0,
"url": "/v1/charges/ch_1KEqIvI5cib7rtVMYUVn5gfQ/refunds"
},
"review": null,
"shipping": null,
"source": null,
"source_transfer": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
}],
"has_more": false,
"total_count": 1,
"url": "/v1/charges?payment_intent=pi_1KEqIeI5cib7rtVMcz8zsXys"
},
"client_secret": "pi_1KEqIeI5cib7rtVMcz8zsXys_secret_uZwm3uziwfaWePgTHENYXeraD",
"confirmation_method": "automatic",
"created": 1641453736,
"currency": "usd",
"customer": "cus_KufeYc1hifvZGA",
"description": null,
"invoice": null,
"last_payment_error": null,
"livemode": false,
"metadata": {},
"next_action": null,
"on_behalf_of": null,
"payment_method": "pm_1KEqIuI5cib7rtVMYPWlLV8S",
"payment_method_options": {
"card": {
"installments": null,
"mandate_options": null,
"network": null,
"request_three_d_secure": "automatic"
}
},
"payment_method_types": ["card"],
"processing": null,
"receipt_email": null,
"review": null,
"setup_future_usage": null,
"shipping": null,
"source": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
}
},
"livemode": false,
"pending_webhooks": 3,
"request": {
"id": "req_Y87umQuitz9WCc",
"idempotency_key": "a4b6af76-73d8-49b4-8393-9017e673af7e"
},
"type": "payment_intent.succeeded"
}
Object Received in Checkout Session Completed
{
"id": "evt_1KEqQOI5cib7rtVMRwAHWDvV",
"object": "event",
"api_version": "2020-03-02",
"created": 1641454214,
"data": {
"object": {
"id": "cs_test_a1AQ9EKIaxi8dXFAJzZ86xYm5meRkWb9Vu0eLowfkiKgUO4cyToooBzSTd",
"object": "checkout.session",
"after_expiration": null,
"allow_promotion_codes": null,
"amount_subtotal": 59700,
"amount_total": 59700,
"automatic_tax": {
"enabled": false,
"status": null
},
"billing_address_collection": null,
"cancel_url": "http://localhost:8000/payment-failure",
"client_reference_id": null,
"consent": null,
"consent_collection": null,
"currency": "usd",
"customer": "cus_Kuflo6N0n4HTzL",
"customer_details": {
"email": "test#gmail.com",
"phone": null,
"tax_exempt": "none",
"tax_ids": []
},
"customer_email": "test#gmail.com",
"expires_at": 1641540596,
"livemode": false,
"locale": null,
"mode": "payment",
"payment_intent": "pi_1KEqQ4I5cib7rtVMyND6NhQG",
"payment_method_options": {},
"payment_method_types": ["card"],
"payment_status": "paid",
"phone_number_collection": {
"enabled": false
},
"recovered_from": null,
"setup_intent": null,
"shipping": null,
"shipping_address_collection": null,
"shipping_options": [],
"shipping_rate": null,
"status": "complete",
"submit_type": null,
"subscription": null,
"success_url": "http://localhost:8000/payment-success",
"total_details": {
"amount_discount": 0,
"amount_shipping": 0,
"amount_tax": 0
},
"url": null
}
},
"livemode": false,
"pending_webhooks": 4,
"request": {
"id": null,
"idempotency_key": null
},
"type": "checkout.session.completed"
}
I'm unable to figure out how to get the Product ID and the Quantity. Could anyone suggest the right approach here?
You can find the Product and the quantity from the Checkout Session by using expand on the line_items property. The code should look like this.
// In "checkout.session.completed" event handler, get the ID of the Checkout Session
const id = event.data.object.id; // "cs_xxx"
// Retrieve the Checkout Session with expand
const session = await stripe.checkout.sessions.retrieve(id, {
expand: [ "line_items" ]
});
// Get the quantity
console.log(session.line_items.data[0].quantity);
// Get the product ID
console.log(session.line_items.data[0].price.product);

Ansible. Get specific value from {{ item }} loop

I'm trying to work with loops and item(s) and I can't get it to work... maybe you can help me.
So I want to print in a loop the "content" value of this output and I'm unable to do this. Do
- name: "Verify started instances"
uri:
url: "http://localhost:808{{ item[-1] }}/url"
method: GET
return_content: yes
register: status
until: "status is search('Version')"
retries: 3
delay: 60
ignore_errors: yes
with_items: "{{ instances_running.stdout_lines }}"
- debug:
msg: "{{ item }}"
with_items: "{{ status }}"
ignore_errors: yes
Output looks like that:
TASK [[AppServerAgent] verify started instances] **************************************************************************************************************************************
FAILED - RETRYING: [AppServerAgent] verify started instances (3 retries left).
FAILED - RETRYING: [AppServerAgent] verify started instances (2 retries left).
ok: [SERVER] => (item=inst0)
FAILED - RETRYING: [AppServerAgent] verify started instances (3 retries left).
FAILED - RETRYING: [AppServerAgent] verify started instances (2 retries left).
FAILED - RETRYING: [AppServerAgent] verify started instances (1 retries left).
failed: [SERVER] (item=instnull) => {"ansible_loop_var": "item", "attempts": 3, "changed": false, "item": "instnull", "msg": "invalid literal for int() with base 10: '808l'", "status": -1, "url": "http://localhost:808l/url"}
...ignoring
TASK [debug] **************************************************************************************************************************************************************************
ok: [SERVER] => {
"msg": {
"changed": false,
"failed": true,
"msg": "All items completed",
"results": [
{
"ansible_loop_var": "item",
"attempts": 3,
"changed": false,
"connection": "close",
"content": "Version: 2-SNAPSHOT\nBuild number: 1\nBuild id: 2020-11-325_09-03-20\n",
"content_length": "281",
"cookies": {},
"cookies_string": "",
"date": "",
"elapsed": 0,
"failed": false,
"invocation": {
"module_args": {
"attributes": null,
"backup": null,
"body": null,
"body_format": "raw",
"client_cert": null,
"client_key": null,
"content": null,
"creates": null,
"delimiter": null,
"dest": null,
"directory_mode": null,
"follow": false,
"follow_redirects": "safe",
"force": false,
"force_basic_auth": false,
"group": null,
"headers": {},
"http_agent": "ansible-httpget",
"method": "GET",
"mode": null,
"owner": null,
"regexp": null,
"remote_src": null,
"removes": null,
"return_content": true,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": null,
"status_code": [
200
],
"timeout": 30,
"unix_socket": null,
"unsafe_writes": null,
"url": "http://localhost:8080/url",
"url_password": null,
"url_username": null,
"use_proxy": true,
"validate_certs": true
}
},
"item": "inst0",
"msg": "OK (281 bytes)",
"redirected": false,
"status": 200,
"url": "http://localhost:8080/url"
},
{
"ansible_loop_var": "item",
"attempts": 3,
"changed": false,
"failed": true,
"invocation": {
"module_args": {
"attributes": null,
"backup": null,
"body": null,
"body_format": "raw",
"client_cert": null,
"client_key": null,
"content": null,
"creates": null,
"delimiter": null,
"dest": null,
"directory_mode": null,
"follow": false,
"follow_redirects": "safe",
"force": false,
"force_basic_auth": false,
"group": null,
"headers": {},
"http_agent": "ansible-httpget",
"method": "GET",
"mode": null,
"owner": null,
"regexp": null,
"remote_src": null,
"removes": null,
"return_content": true,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": null,
"status_code": [
200
],
"timeout": 30,
"unix_socket": null,
"unsafe_writes": null,
"url": "http://localhost:808l/url",
"url_password": null,
"url_username": null,
"use_proxy": true,
"validate_certs": true
}
},
"item": "instnull",
"msg": "invalid literal for int() with base 10: '808l'",
"status": -1,
"url": "http://localhost:808l/url"
}
]
}
}
I was trying to use something like this:
- debug:
msg: "{{ item.content.split('\n') }}"
with_items: "{{ status }}"
ignore_errors: yes
but then the output looks like that:
TASK [debug] **************************************************************************************************************************************************************************
fatal: [SERVER]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'ansible.utils.unsafe_proxy.AnsibleUnsafeBytes object' has no attribute 'content'\n\nThe error appears to be in '/deploy.yaml': line 176, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - debug:\n ^ here\n"}
How can I do this?
Or maybe there is also a way to use other command instead of until: "status is search('Version')" to find content field and print output in name block instead of debug task?
THanks!
Try "{{ status.results.content }}"

STRIPE API Returns Empty Response

I am using Sripe PHP SDK from this link
When I am trying to use any api of Stripe Payment it gets successful but the response it returns is empty
I am following API Instructions from Strip API Documentations
For example I am using following code snippet to create a payment
$stripe = new \Stripe\StripeClient(
'SECRET_KEY'
);
$stripe->paymentIntents->create([
'amount' => 1200,
'currency' => 'usd',
'payment_method_types' => ['card']
]);
// after successfull payment, you can store payment related information into your database
$this->response([ 'success' =>'1' ,'status' => 'success', 'message' => $stripe], REST_Controller::HTTP_OK);
But it is not returning any response, instead the return object is empty.
Here is the response
{"success":"1","status":"success","message":{}}
It should return an object like this in message
{
"id": "pi_1HkSRrKUkp6sNA1QWNFwUOLd",
"object": "payment_intent",
"amount": 2000,
"amount_capturable": 0,
"amount_received": 0,
"application": null,
"application_fee_amount": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic",
"charges": {
"object": "list",
"data": [],
"has_more": false,
"url": "/v1/charges?payment_intent=pi_1HkSRrKUkp6sNA1QWNFwUOLd"
},
"client_secret": "SECRET_KEY",
"confirmation_method": "automatic",
"created": 1604659539,
"currency": "usd",
"customer": null,
"description": "Created by stripe.com/docs demo",
"invoice": null,
"last_payment_error": null,
"livemode": false,
"metadata": {},
"next_action": null,
"on_behalf_of": null,
"payment_method": null,
"payment_method_options": {
"card": {
"installments": null,
"network": null,
"request_three_d_secure": "automatic"
}
},
"payment_method_types": [
"card"
],
"receipt_email": null,
"review": null,
"setup_future_usage": null,
"shipping": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "requires_payment_method",
"transfer_data": null,
"transfer_group": null
}
Where exactly are you getting that example from? It looks incomplete.
You should just save the output of the API call to some variable, then return the client_secret for example:
$intent = $stripe->paymentIntents->create([
'amount' => 1200,
'currency' => 'usd',
'payment_method_types' => ['card']
]);
$this->response([ 'success' =>'1' ,'status' => 'success', 'message' => $intent->client_secret], REST_Controller::HTTP_OK);

How do one should set a custom agent pool in DevOps release definition?

I create release definitions using DevOps REST APIs. Due to lack of documentation I used to capture HTTP requests and examine JSON payload.
I'm able to set a release using Azure agent pools. It follows only the relevant node:
"deploymentInput": {
"parallelExecution": {
"parallelExecutionType": 0
},
"agentSpecification": {
"identifier": "windows-2019"
},
"skipArtifactsDownload": false,
"artifactsDownloadInput": {},
"queueId": 749,
"demands": [],
"enableAccessToken": false,
"timeoutInMinutes": 0,
"jobCancelTimeoutInMinutes": 1,
"condition": "succeeded()",
"overrideInputs": {},
"dependencies": []
}
I want to set a custom defined agent pool, but if I try to capture the request I still can't undertand how to set it. This is the full JSON of an empty release with custom agent set:
{
"id": 0,
"name": "New release pipeline",
"source": 2,
"comment": "",
"createdOn": "2020-10-31T10:02:19.034Z",
"createdBy": null,
"modifiedBy": null,
"modifiedOn": "2020-10-31T10:02:19.034Z",
"environments": [
{
"id": -1,
"name": "Stage 1",
"rank": 1,
"variables": {},
"variableGroups": [],
"preDeployApprovals": {
"approvals": [
{
"rank": 1,
"isAutomated": true,
"isNotificationOn": false,
"id": 0
}
],
"approvalOptions": {
"executionOrder": 1
}
},
"deployStep": {
"tasks": [],
"id": 0
},
"postDeployApprovals": {
"approvals": [
{
"rank": 1,
"isAutomated": true,
"isNotificationOn": false,
"id": 0
}
],
"approvalOptions": {
"executionOrder": 2
}
},
"deployPhases": [
{
"deploymentInput": {
"parallelExecution": {
"parallelExecutionType": 0
},
"agentSpecification": null,
"skipArtifactsDownload": false,
"artifactsDownloadInput": {},
"queueId": 1039,
"demands": [],
"enableAccessToken": false,
"timeoutInMinutes": 0,
"jobCancelTimeoutInMinutes": 1,
"condition": "succeeded()",
"overrideInputs": {},
"dependencies": []
},
"rank": 1,
"phaseType": 1,
"name": "Agent job",
"refName": null,
"workflowTasks": [],
"phaseInputs": {
"phaseinput_artifactdownloadinput": {
"artifactsDownloadInput": {},
"skipArtifactsDownload": false
}
}
}
],
"runOptions": {},
"environmentOptions": {
"emailNotificationType": "OnlyOnFailure",
"emailRecipients": "release.environment.owner;release.creator",
"skipArtifactsDownload": false,
"timeoutInMinutes": 0,
"enableAccessToken": false,
"publishDeploymentStatus": true,
"badgeEnabled": false,
"autoLinkWorkItems": false,
"pullRequestDeploymentEnabled": false
},
"demands": [],
"conditions": [
{
"conditionType": 1,
"name": "ReleaseStarted",
"value": ""
}
],
"executionPolicy": {
"concurrencyCount": 1,
"queueDepthCount": 0
},
"schedules": [],
"properties": {
"LinkBoardsWorkItems": false,
"BoardsEnvironmentType": "unmapped"
},
"preDeploymentGates": {
"id": 0,
"gatesOptions": null,
"gates": []
},
"postDeploymentGates": {
"id": 0,
"gatesOptions": null,
"gates": []
},
"environmentTriggers": [],
"owner": {
"displayName": "Giacomo Stelluti Scala",
"id": "3617734a-1751-66f2-8343-c71c1398b5e6",
"isAadIdentity": true,
"isContainer": false,
"uniqueName": "giacomo.stelluti#dev4side.com",
"url": "https://dev.azure.com/dev4side/"
},
"retentionPolicy": {
"daysToKeep": 30,
"releasesToKeep": 3,
"retainBuild": true
},
"processParameters": {}
}
],
"artifacts": [],
"variables": {},
"variableGroups": [],
"triggers": [],
"lastRelease": null,
"tags": [],
"path": "\\test-poc",
"properties": {
"DefinitionCreationSource": "ReleaseNew",
"IntegrateJiraWorkItems": "false",
"IntegrateBoardsWorkItems": false
},
"releaseNameFormat": "Release-$(rev:r)",
"description": ""
}
Where do this is agent is set? Anyone knows how to do it properly?
Any help really appreciated.
Giacomo S. S.
I've found the solution in this question.
"deploymentInput": {
"parallelExecution": {
"parallelExecutionType": 0
},
"agentSpecification": null,
"skipArtifactsDownload": false,
"artifactsDownloadInput": {},
"queueId": 1039,
"demands": [],
"enableAccessToken": false,
"timeoutInMinutes": 0,
"jobCancelTimeoutInMinutes": 1,
"condition": "succeeded()",
"overrideInputs": {},
"dependencies": []
}
agentSpecification must be null and queueId must be set.

fabric on nodeJS, No images rendering at all

The issue is on Ubuntu 14.04:
NodeJS: 0.10.32
Canvas: 1.3.6
Fabric: 1.6.0-rc.1
Example JSON:
{
"objects": [{
"id": 0,
"name": "1452525510_death_star.svg",
"type": "image",
"originX": "left",
"originY": "top",
"left": 78,
"top": 21,
"width": 512,
"height": 512,
"fill": "rgb(0,0,0)",
"stroke": null,
"strokeWidth": 1,
"strokeDashArray": null,
"strokeLineCap": "butt",
"strokeLineJoin": "miter",
"strokeMiterLimit": 10,
"scaleX": 0.46,
"scaleY": 0.46,
"angle": 0,
"flipX": false,
"flipY": false,
"opacity": 1,
"shadow": null,
"visible": true,
"clipTo": null,
"backgroundColor": "",
"fillRule": "nonzero",
"globalCompositeOperation": "source-over",
"transformMatrix": null,
"_controlsVisibility": {
"tl": false,
"tr": true,
"br": true,
"bl": false,
"ml": true,
"mt": false,
"mr": false,
"mb": true,
"mtr": true
},
"src": "http://somedomain.com/media/patterns/users/1fb158157a882d6a4c983ddc401101d1.svg",
"filters": [{
"type": "Tint",
"color": "#c485c4",
"opacity": 1
}],
"crossOrigin": "",
"alignX": "none",
"alignY": "none",
"meetOrSlice": "meet"
}, {
"id": 1,
"name": "Baby inside",
"type": "image",
"originX": "left",
"originY": "top",
"left": 102,
"top": 290,
"width": 470,
"height": 427,
"fill": "rgb(0,0,0)",
"stroke": null,
"strokeWidth": 1,
"strokeDashArray": null,
"strokeLineCap": "butt",
"strokeLineJoin": "miter",
"strokeMiterLimit": 10,
"scaleX": 0.5,
"scaleY": 0.5,
"angle": 0,
"flipX": false,
"flipY": false,
"opacity": 1,
"shadow": null,
"visible": true,
"clipTo": null,
"backgroundColor": "",
"fillRule": "nonzero",
"globalCompositeOperation": "source-over",
"transformMatrix": null,
"_controlsVisibility": {
"tl": false,
"tr": true,
"br": true,
"bl": false,
"ml": true,
"mt": false,
"mr": false,
"mb": true,
"mtr": true
},
"src": "http://somedomain.com/media/patterns/12.png",
"filters": [{
"type": "Tint",
"color": "#FFFFFF",
"opacity": 1
}],
"crossOrigin": "",
"alignX": "none",
"alignY": "none",
"meetOrSlice": "meet"
}],
"background": "#b0b0b0",
"backgroundImage": {
"id": 0,
"name": "",
"type": "image",
"originX": "left",
"originY": "top",
"left": 0,
"top": 0,
"width": 470,
"height": 574,
"fill": "rgb(0,0,0)",
"stroke": null,
"strokeWidth": 1,
"strokeDashArray": null,
"strokeLineCap": "butt",
"strokeLineJoin": "miter",
"strokeMiterLimit": 10,
"scaleX": 1,
"scaleY": 1,
"angle": 0,
"flipX": false,
"flipY": false,
"opacity": 1,
"shadow": null,
"visible": true,
"clipTo": null,
"backgroundColor": "",
"fillRule": "nonzero",
"globalCompositeOperation": "source-over",
"transformMatrix": null,
"_controlsVisibility": null,
"src": "http://somedomain.com/media/products/121_37_2.jpg",
"filters": [],
"crossOrigin": "",
"alignX": "none",
"alignY": "none",
"meetOrSlice": "meet"
}
Note that this JSON exported with toJSON() has some custom fields: [name, id].
This is from my Node script:
function savetoFile() {
var jsonData = JSONfromAbove;
var out = fs.createWriteStream(filepath);
canvas = fabric.createCanvasForNode(470, 574);
canvas.loadFromJSON(jsonData, function () {
CanvasZoom(parseInt(zoom), function(){
console.log('after zooom');
console.log(canvas.getObjects());
var stream = canvas.createPNGStream();
stream.on('data', function (chunk) {
out.write(chunk);
});
stream.on('end', function () {
out.end();
});
});
});
}
function CanvasZoom(z, callback) {
width = canvas.width;
height = canvas.height;
canvas.setWidth(width*z);
canvas.setHeight(height*z);
canvas.setZoom(z);
canvas.renderAll.bind(canvas);
callback();
}
Facts:
No matter what types of objects I add ('image', 'path',
'path-group') they are not rendering at all, except text and
maybe (I did not tested it) PATHS not from URL's.
In JSON above
there is background img - it doesn't rendering too.
There is no errors at all, however:
The same identical script on OSX works fine BUT:
When I'm trying to add "large" SVG file it gives me:
"image given has not completed loading"
Works fine with HUGE numbers of normal PNG's.
The time to "render" final PNG is proportional to number of objects and their image sizes which might tell that they are loading some kind of well.
I have installed all dependent libs.
Tried to add one object like that ending with the same problem:
fabric.Image.fromURL('http://somedomain.com/media/patterns/12.png', function(oImg, e) {...});
I bet for node-canvas someway failing with URL's.
I spend almost 2 days trying to fix this devilish problem ];>
he issue is that on www.somedomain.com was httpasswd, so it just can't download files but did not throw any errors.
When switched 1.6.0-rc1 to 1.5.X an error occur: "Segmentation Fault".

Resources