Appending the same values twice when iterating through two list - loops

My ansible playbook:
- hosts: localhost
connection: local
gather_facts: no
become: no
vars:
- delete: [
{
"department_link": "https://servicenowservices.com/api/now/table/da/3fb1",
"hostname": "host1",
"value": "3fb1"
},
{
"department_link": "https://servicenowservices.com/api/now/table/da/3fb1",
"hostname": "host2",
"value": "3fb1133"
}
]
tasks:
- name: connect to service now cmdb table
uri:
url: "{{item.department_link}}"
method: GET
body_format: form-urlencoded
user: "user"
password: "password"
timeout: 200
validate_certs: no
loop: "{{delete}}"
register: test
no_log: yes
- debug:
var: test.results
- name: combine
set_fact:
final: "{{ final | default([]) + [ item[0] | combine({'department': item[1].json.result.name | default(None)}) ] }}"
when:
- item[1].json.result.sys_id | string == item[0].value | string
with_nested:
- "{{delete}}"
- "{{test.results}}"
no_log: yes
- debug:
var: final
debug of the var: test.results -- truncated. -- please go to the end of the page for full output.
"test.results": [
"json": {
"result": {
"name": "dept1",
"sys_id": "3fb1",
}
},
"json": {
"result": {
"name": "dept1",
"sys_id": "3fb1",
}
}]
debug of the var: final
ok: [localhost] => {
"final": [
{
"department": 'dept1",
"department_link": "https://servicenowservices.com/api/now/table/da/3fb1",
"hostname": "host1",
"value": "3fb1"
},
{
"department": "dept1",
"department_link": "https://servicenowservices.com/api/now/table/da/3fb1",
"hostname": "host1",
"value": "3fb1"
}
]
}
You can see from the above, when I iterate though two lists and combine two list into one when the condition is satisfied, it for some reason put the output twice. I have tried many different ways but no luck.
So the result I want is:
for the var: final - I want the ouput to only be one dict in the list like so
"final": [
{
"department": 'dept1",
"department_link": "https://servicenowservices.com/api/now/table/da/3fb1",
"hostname": "host1",
"value": "3fb1"
}]
Please let me know how I can achieve this.
Below is the full output of test.results and I printed its type as well. Hope this will help!!
TASK [debug]
ok: [localhost] => {
"test.results": [
{
"ansible_loop_var": "item",
"cache_control": "no-cache,no-store,must-revalidate,max-age=-1",
"changed": false,
"connection": "close",
"content_type": "application/json;charset=UTF-8",
"cookies": {
"cook": "random input"
},
"cookies_string": "cookies",
"date": "Thu, 06 Oct 2022 17:03:50 GMT",
"elapsed": 0,
"expires": "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,
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"regexp": null,
"remote_src": null,
"removes": null,
"return_content": false,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": null,
"status_code": [
200
],
"timeout": 2000,
"unix_socket": null,
"unsafe_writes": false,
"url": "https://servicenowservices.com/api/now/table/da/3fb1",
"url_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"url_username": "user",
"use_proxy": true,
"user": "user",
"validate_certs": false
}
},
"item": {
"department_link": "https://servicenowservices.com/api/now/table/da/3fb1",
"hostname": "host1",
"value": "3fb1"
},
"json": {
"result": {
"business_unit": "",
"code": "",
"cost_center": "",
"dept_head": "",
"description": "",
"head_count": "",
"id": "",
"name": "FZB2",
"parent": "",
"primary_contact": "",
"sys_created_by": "$test",
"sys_created_on": "2017-01-25 05:43:39",
"sys_id": "3fb1",
"sys_mod_count": "0",
"sys_tags": "",
"sys_updated_by": "$test",
"sys_updated_on": "2017-01-25 05:43:39"
}
},
"msg": "OK (unknown bytes)",
"pragma": "no-store,no-cache",
"redirected": false,
"server": "ServiceNow",
,
"status": 200,
"strict_transport_security": "max-age=63072000; includeSubDomains",
"transfer_encoding": "chunked",
"url": "https://servicenowservices.com/api/now/table/da/3fb1",
"x_is_logged_in": "true",
"x_transaction_id": "id"
},
{
"ansible_loop_var": "item",
"cache_control": "no-cache,no-store,must-revalidate,max-age=-1",
"changed": false,
"connection": "close",
"content_type": "application/json;charset=UTF-8",
"cookies": {
"cook": "random input",
},
"cookies_string": "cookies",
"date": "Thu, 06 Oct 2022 17:03:51 GMT",
"elapsed": 0,
"expires": "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,
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"regexp": null,
"remote_src": null,
"removes": null,
"return_content": false,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": null,
"status_code": [
200
],
"timeout": 200,
"unix_socket": null,
"unsafe_writes": false,
"url": "https://servicenowservices.com/api/now/table/da/3fb1",
"url_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"url_username": "user",
"use_proxy": true,
"user": "user",
"validate_certs": false
}
},
"item": {
"department_link": "https://servicenowservices.com/api/now/table/da/3fb1",
"hostname": "host2",
"value": "3fb1"
},
"json": {
"result": {
"business_unit": "",
"code": "",
"cost_center": "",
"dept_head": "",
"description": "",
"head_count": "",
"id": "",
"name": "FZB2",
"parent": "",
"primary_contact": "",
"sys_created_by": "$test",
"sys_created_on": "2017-01-25 05:43:39",
"sys_id": "id",
"sys_mod_count": "0",
"sys_tags": "",
"sys_updated_by": "$test",
"sys_updated_on": "2017-01-25 05:43:39"
}
},
"msg": "OK (unknown bytes)",
"pragma": "no-store,no-cache",
"redirected": false,
"server": "ServiceNow",
"set_cookie": "glide_user=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly; SameSite=None; Secure, glide_user_session=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly; SameSite=None; Secure, glide_user_route=glide.idd; Max-Age=2147483647; Expires=Tue, 24-Oct-2090 20:17:58 GMT; Path=/; HttpOnly; SameSite=None; Secure, glide_session_store=3348D7BA1B561150C71B8557EC4BCB27; Max-Age=300; Expires=Thu, 06-Oct-2022 17:08:51 GMT; Path=/; HttpOnly; SameSite=None; Secure",
"status": 200,
"strict_transport_security": "max-age=63072000; includeSubDomains",
"transfer_encoding": "chunked",
"url": "https://servicenowservices.com/api/now/table/da/3fb1",
"x_is_logged_in": "true",
"x_transaction_id": "123"
}
]
}
TASK [debug]
ok: [localhost] => {
"test.results | type_debug": "list"
}

You are facing this issue because test.results varialbe have duplicate json blocks.
I have removed them using map and unique functions
Please try this modified task
- name: combine
set_fact:
final: "{{ final | default([]) + [ item[0] | combine({'department': item[1].result.name | default(None)}) ] }}"
when:
- item[1].result.sys_id | string == item[0].value | string
with_nested:
- "{{delete}}"
- "{{test.results | map(attribute='json') | unique }}"
no_log: yes

Related

React Hooks update nested JSON array by index

I have this JSON object and I want to change an attribute inside it. In this case I'm trying to change VALUE inside configs[0].configs[0].value
{
"id": "PAY_TOOL_1",
"name": "PAY_TOOL_1",
"description": "PayTool1",
"state": "ENABLED",
"configs": [
{
"isDefaultConfig": null,
"id": "configId-1",
"name": "configId-1",
"defaultConfig": null,
"description": null,
"configs": [
{
"isEditable": true,
"identifier": null,
"name": "returnUrl",
"value": "http://localhost:7070/pay/payment/confirm/", <-- WANT TO CHANGE THIS
"defaultValue": null,
"description": null,
"editable": true
},
{
"isEditable": true,
"identifier": null,
"name": "cancelUrl",
"value": "http://localhost:7070/pay/payment/cancel/",
"defaultValue": null,
"description": null,
"editable": true
}
]
},
{
"isDefaultConfig": null,
"id": "configId-2",
"name": "configId-2",
"defaultConfig": null,
"description": null,
"configs": [
{
"isEditable": true,
"identifier": null,
"name": "returnUrl2",
"value": "http://localhost:7070/pay/payment/confirm/22",
"defaultValue": null,
"description": null,
"editable": true
},
{
"isEditable": true,
"identifier": null,
"name": "cancelUrl2",
"value": "http://localhost:7070/pay/payment/cancel/22",
"defaultValue": null,
"description": null,
"editable": true
}
]
}
]
}
This is the code in REACT HOOKS following this solution
SOLUTION
const [editPaymentTool, setEditPaymentTool] = useState(null);
function handleConfigurationInputs( configIndex, propertyIndex, configId, attributeName, attributeValue) {
console.log("CONFIG_INDEX: "+configIndex+" PROPERTY_INDEX: "+propertyIndex+" CONFIG ID: "+configId+ " NAME: "+attributeName+ " VALUE: "+attributeValue);
console.log(editPaymentTool);
setEditPaymentTool(prev => ({
...prev,
configs:[{
...prev.configs,
configs:[{
...prev.configs[configIndex].configs[propertyIndex],
value:attributeValue
}]
}]
}));
}
and the output produced which is pretty different from the expected above
{
"id": "PAY_TOOL_1",
"name": "PAY_TOOL_1",
"description": "PayTool1",
"state": "ENABLED",
"configs": [
{
"0": {
"isDefaultConfig": null,
"id": "configId-1",
"name": "configId-1",
"defaultConfig": null,
"description": null,
"configs": [
{
"isEditable": true,
"identifier": null,
"name": "returnUrl",
"value": "http://localhost:7070/pay/payment/confirm/", <-- EXPECTED TO BE CHANGED BUT NOT
"defaultValue": null,
"description": null,
"editable": true
},
{
"isEditable": true,
"identifier": null,
"name": "cancelUrl",
"value": "http://localhost:7070/pay/payment/cancel/",
"defaultValue": null,
"description": null,
"editable": true
}
]
},
"1": {
"isDefaultConfig": null,
"id": "configId-2",
"name": "configId-2",
"defaultConfig": null,
"description": null,
"configs": [
{
"isEditable": true,
"identifier": null,
"name": "returnUrl2",
"value": "http://localhost:7070/pay/payment/confirm/22",
"defaultValue": null,
"description": null,
"editable": true
},
{
"isEditable": true,
"identifier": null,
"name": "cancelUrl2",
"value": "http://localhost:7070/pay/payment/cancel/22",
"defaultValue": null,
"description": null,
"editable": true
}
]
},
"configs": [
{
"isEditable": true,
"identifier": null,
"name": "returnUrl",
"value": "http://localhost:7070/pay/payment/confirm/l", <-- THE CHANGED VALUE IS PUT HERE (WRONG)
"defaultValue": null,
"description": null,
"editable": true
}
]
}
]
}
Any help is appreciated
Try this:
newState = _.cloneDeep(editPaymentTool);
newState.configs[0].configs[0].value = newValue;
//more complicated nested updates
...
setEditPaymentTool(newState);

Array parsing and converting to new array List

How to convert below array to specific output?
Input:
[
{
"id": "9664581",
"isSelected": true,
"isExpanded": false,
"disabled": false,
"cells": [
{
"id": "9664581:att_name",
"value": "Test1 att_name",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "att_name"
}
},
{
"id": "9664581:att_email",
"value": "test1#gmail.com",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "att_email"
}
},
{
"id": "9664581:comp_name",
"value": "Test1 comp_name",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "comp_name"
}
},
{
"id": "9664581:attendee_ctry",
"value": "Test cnt",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "attendee_ctry"
}
},
{
"id": "9664581:sources",
"value": "Test DB",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "sources"
}
}
]
},
{
"id": "9528552",
"isSelected": true,
"isExpanded": false,
"disabled": false,
"cells": [
{
"id": "9528552:att_name",
"value": "Test2 att_name",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "att_name"
}
},
{
"id": "9528552:att_email",
"value": "Test2#gmail.com",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "att_email"
}
},
{
"id": "9528552:comp_name",
"value": "Dsd comp_name",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "comp_name"
}
},
{
"id": "9528552:attendee_ctry",
"value": "Test2 cnt",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "attendee_ctry"
}
},
{
"id": "9528552:sources",
"value": "Test2 DB",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "sources"
}
}
]
}
]
output should be like
output:
[
{
"id": "9664581",
"name": "Test1 att_name",
"email": test1#gmail.com
},
{
"id": "9528552",
"name": "Test2 att_name",
"email": test2#gmail.com
}
]
You need to understand your data.
It appears that the id comes right off of each object. As for the name and email, those are the values of the first and second cell. This turns into a trivial mapping.
You could also try to look-up the cells by their header:
function transformData(data) {
return data.map(item => {
return {
id : item.id,
name : item.cells.find(cell => cell.info.header.endsWith('name')).value,
email : item.cells.find(cell => cell.info.header.endsWith('email')).value
};
});
}
console.log(transformData(getData()));
function transformData(data) {
return data.map(item => {
return {
id : item.id,
name : item.cells[0].value,
email : item.cells[1].value
};
});
}
function getData() {
return [{
"id": "9664581",
"isSelected": true,
"isExpanded": false,
"disabled": false,
"cells": [{
"id": "9664581:att_name",
"value": "Test1 att_name",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "att_name"
}
}, {
"id": "9664581:att_email",
"value": "test1#gmail.com",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "att_email"
}
}, {
"id": "9664581:comp_name",
"value": "Test1 comp_name",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "comp_name"
}
}, {
"id": "9664581:attendee_ctry",
"value": "Test cnt",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "attendee_ctry"
}
}, {
"id": "9664581:sources",
"value": "Test DB",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "sources"
}
}]
}, {
"id": "9528552",
"isSelected": true,
"isExpanded": false,
"disabled": false,
"cells": [{
"id": "9528552:att_name",
"value": "Test2 att_name",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "att_name"
}
}, {
"id": "9528552:att_email",
"value": "Test2#gmail.com",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "att_email"
}
}, {
"id": "9528552:comp_name",
"value": "Dsd comp_name",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "comp_name"
}
}, {
"id": "9528552:attendee_ctry",
"value": "Test2 cnt",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "attendee_ctry"
}
}, {
"id": "9528552:sources",
"value": "Test2 DB",
"isEditable": false,
"isEditing": false,
"isValid": true,
"errors": null,
"info": {
"header": "sources"
}
}]
}];
}
.as-console-wrapper { top: 0; max-height: 100% !important; }
You could do this:
let output = input.map(v => {
let name = '';
let email = '';
v.cells.map(obj => {
if(obj.info.header === 'att_name') {
name = obj.value
}
if(obj.info.header === 'att_email') {
email = obj.value
}
return
})
return {
"id": v.id,
"name": name,
"email": email
}
})

How to create a context variable in the entire multiplied-replies node in Watson Assistant?

To add a context variable in a node with a single reply, I just add the var once in that response and that's fair enough.
But in multiple replies node, I must configure each response and add the context variable in each one with either context or JSON editor.
Can I add that only once?
If not what is the idea behind that?
Why does not even a node general variable option exist besides reply-specific ones?
The multiple response node is a way to easily have different responses nested together. Before this feature you had to create a node for every single response you wanted to do.
This appears to be a side-effect of this, but is easy to resolve.
Create your main node and set your context variable. Then create a child node and have the parent "Skip User Input". The child node should have your multiple responses.
Example workspace:
{
"name": "Example single context for multiresponse node",
"intents": [],
"entities": [],
"language": "en",
"metadata": {
"api_version": {
"major_version": "v1",
"minor_version": "2017-05-26"
}
},
"description": "",
"dialog_nodes": [
{
"type": "response_condition",
"title": null,
"output": {
"generic": [
{
"values": [
{
"text": "two $example"
}
],
"response_type": "text"
}
]
},
"parent": "node_1_1532968597524",
"context": null,
"metadata": {},
"next_step": null,
"conditions": "input.text == \"2\"",
"description": null,
"dialog_node": "node_3_1532968635994",
"previous_sibling": "node_2_1532968631610"
},
{
"type": "response_condition",
"title": null,
"output": {
"generic": [
{
"values": [
{
"text": "one $example"
}
],
"response_type": "text",
"selection_policy": "sequential"
}
]
},
"parent": "node_1_1532968597524",
"context": null,
"metadata": {},
"next_step": null,
"conditions": "input.text == \"1\"",
"description": null,
"dialog_node": "node_2_1532968631610",
"previous_sibling": null
},
{
"type": "standard",
"title": "Enter 1 or 2 to trigger.",
"output": {},
"parent": "node_4_1532968810899",
"context": null,
"metadata": {
"_customization": {
"mcr": true
}
},
"next_step": null,
"conditions": "anything_else",
"description": null,
"dialog_node": "node_1_1532968597524",
"digress_out": "allow_all",
"previous_sibling": null
},
{
"type": "standard",
"title": "$example set to value of \"example\"",
"output": {
"generic": [
{
"values": [],
"response_type": "text",
"selection_policy": "sequential"
}
]
},
"parent": null,
"context": {
"example": "example"
},
"metadata": {},
"next_step": {
"behavior": "skip_user_input"
},
"conditions": "anything_else",
"description": null,
"dialog_node": "node_4_1532968810899",
"previous_sibling": "Welcome"
},
{
"type": "standard",
"title": "Anything else",
"output": {
"generic": [
{
"values": [
{
"text": "I didn't understand. You can try rephrasing."
},
{
"text": "Can you reword your statement? I'm not understanding."
},
{
"text": "I didn't get your meaning."
}
],
"response_type": "text",
"selection_policy": "sequential"
}
]
},
"parent": null,
"context": null,
"metadata": {},
"next_step": null,
"conditions": "anything_else",
"description": null,
"dialog_node": "Anything else",
"previous_sibling": "node_4_1532968810899"
},
{
"type": "standard",
"title": "Welcome",
"output": {
"generic": [
{
"values": [
{
"text": "Hello. How can I help you?"
}
],
"response_type": "text",
"selection_policy": "sequential"
}
]
},
"parent": null,
"context": null,
"metadata": {},
"next_step": null,
"conditions": "welcome",
"description": null,
"dialog_node": "Welcome",
"previous_sibling": null
}
],
"workspace_id": "9e5b9851-5f0e-4e5f-9523-d2ac7045bf1d",
"counterexamples": [],
"system_settings": {
"tooling": {
"store_generic_responses": true
},
"disambiguation": {
"prompt": "Did you mean:",
"none_of_the_above_prompt": "None of the above"
},
"human_agent_assist": {
"prompt": "Did you mean:"
}
},
"learning_opt_out": false
}

ruby json get values from array

I have a this json that has a arrays in it.
How can i get :
- full_text,
- picture link : media_url_https from media and from extended_entities
- url from entities in urls
- lang
[{
"created_at": "Thu Oct 12 14:42:03 +0000 2017",
"id": 9184869314823331890,
"id_str": "9184869314823331890",
"full_text": "trying some stuff! \nhttps://somewebsite.com/emjc1MLAbD\n\uf6430\nWhat bird is this? What is its name? It has beautiful feathers. Love the mix of green, white. https://somewebsite.com/q3IqrfVcUz",
"truncated": false,
"display_text_range": [0, 139],
"entities": {
"hashtags": [],
"symbols": [],
"user_mentions": [],
"urls": [{
"url": "https://somewebsite.com/emjc1MLAbD",
"expanded_url": "https://www.pexels.com/royalty-free-images/",
"display_url": "pexels.com/royalty-free-i\u2026",
"indices": [20, 43]
}],
"media": [{
"id": 918486209067827200,
"id_str": "918486209067827200",
"indices": [140, 163],
"media_url": "http://pbs.twimg.com/media/DL8eVz6VQAA4VHn.jpg",
"media_url_https": "https://pbs.twimg.com/media/DL8eVz6VQAA4VHn.jpg",
"url": "https://somewebsite.com/q3IqrfVcUz",
"display_url": "pic.twitter.com/q3IqrfVcUz",
"expanded_url": "https://twitter.com/DevAdama/status/918486931482333189/photo/1",
"type": "photo",
"sizes": {
"small": {
"w": 680,
"h": 482,
"resize": "fit"
},
"medium": {
"w": 1200,
"h": 850,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 1939,
"h": 1374,
"resize": "fit"
}
}
}]
},
"extended_entities": {
"media": [{
"id": 918486209067827200,
"id_str": "918486209067827200",
"indices": [140, 163],
"media_url": "http://pbs.twimg.com/media/DL8eVz6VQAA4VHn.jpg",
"media_url_https": "https://pbs.twimg.com/media/DL8eVz6VQAA4VHn.jpg",
"url": "https://somewebsite.com/q3IqrfVcUz",
"display_url": "pic.twitter.com/q3IqrfVcUz",
"expanded_url": "https://twitter.com/DevAdama/status/918486931482333189/photo/1",
"type": "photo",
"sizes": {
"small": {
"w": 680,
"h": 482,
"resize": "fit"
},
"medium": {
"w": 1200,
"h": 850,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 1939,
"h": 1374,
"resize": "fit"
}
}
}]
},
"metadata": {
"iso_language_code": "en",
"result_type": "recent"
},
"source": "Twitter Web Client",
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 915243599930982401,
"id_str": "915243599930982401",
"name": "devAdama",
"screen_name": "DevAdama",
"location": "",
"description": "",
"url": null,
"entities": {
"description": {
"urls": []
}
},
"protected": false,
"followers_count": 0,
"friends_count": 0,
"listed_count": 0,
"created_at": "Tue Oct 03 15:54:13 +0000 2017",
"favourites_count": 0,
"utc_offset": null,
"time_zone": null,
"geo_enabled": false,
"verified": false,
"statuses_count": 2,
"lang": "en",
"contributors_enabled": false,
"is_translator": false,
"is_translation_enabled": false,
"profile_background_color": "000000",
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_tile": false,
"profile_image_url": "http://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png",
"profile_image_url_https": "https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png",
"profile_link_color": "981CEB",
"profile_sidebar_border_color": "000000",
"profile_sidebar_fill_color": "000000",
"profile_text_color": "000000",
"profile_use_background_image": false,
"has_extended_profile": false,
"default_profile": false,
"default_profile_image": true,
"following": false,
"follow_request_sent": false,
"notifications": false,
"translator_type": "none"
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"retweet_count": 0,
"favorite_count": 0,
"favorited": false,
"retweeted": false,
"possibly_sensitive": false,
"lang": "en"
}, {
"created_at": "Wed Oct 04 17:33:29 +0000 2017",
"id": 915630969218064385,
"id_str": "915630969218064385",
"full_text": "hola!",
"truncated": false,
"display_text_range": [0, 5],
"entities": {
"hashtags": [],
"symbols": [],
"user_mentions": [],
"urls": []
},
"metadata": {
"iso_language_code": "es",
"result_type": "recent"
},
"source": "Twitter Web Client",
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 915243599930982401,
"id_str": "915243599930982401",
"name": "devAdama",
"screen_name": "DevAdama",
"location": "",
"description": "",
"url": null,
"entities": {
"description": {
"urls": []
}
},
"protected": false,
"followers_count": 0,
"friends_count": 0,
"listed_count": 0,
"created_at": "Tue Oct 03 15:54:13 +0000 2017",
"favourites_count": 0,
"utc_offset": null,
"time_zone": null,
"geo_enabled": false,
"verified": false,
"statuses_count": 2,
"lang": "en",
"contributors_enabled": false,
"is_translator": false,
"is_translation_enabled": false,
"profile_background_color": "000000",
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_tile": false,
"profile_image_url": "http://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png",
"profile_image_url_https": "https://website.com/sticky/default_profile_images/default_profile_normal.png",
"profile_link_color": "981CEB",
"profile_sidebar_border_color": "000000",
"profile_sidebar_fill_color": "000000",
"profile_text_color": "000000",
"profile_use_background_image": false,
"has_extended_profile": false,
"default_profile": false,
"default_profile_image": true,
"following": false,
"follow_request_sent": false,
"notifications": false,
"translator_type": "none"
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"retweet_count": 0,
"favorite_count": 0,
"favorited": false,
"retweeted": false,
"lang": "es"
}]
Maybe not tidy but still you can try do the following:
require 'json'
test = JSON.parse(json)
test.each {|k|
p "============================"
full_text = k['full_text'] unless k['full_text'].nil?
urls = k['entities']['urls'] unless k['entities']['urls'].nil?
urls.each {|u|
entities_url = u['url'] unless u['url'].nil?
p "Url: #{entities_url}" }
lang = k['lang'] unless k['lang']
media = k['entities']['media']
extended_media = k['extended_entities']['media'] unless k['extended_entities'].nil?
p "Full text: #{full_text}" unless full_text.nil?
media.each {|u|
p "Media url: #{u['media_url_https']}" unless u['media_url_https'].nil?
} unless media.nil?
extended_media.each {|u|
p "Extended url: #{u['media_url_https']}" unless u['media_url_https'].nil?
} unless extended_media.nil?
p "Lang: #{lang}" unless lang.nil?
p "============================="
}

DocuSign Request error "Envelope definition missing."

I am trying to make 'createAndSendEnvelope' request using DocuSign REST api/v2. My JSON is valid.
I came across the same question and I tried the solution given in there i.e. I made sure all new lines use '\r\n'.
What am I missing here? Here is my request, I get error code, "message": "The Envelope is not Complete. A Complete Envelope Requires Documents, Recipients, Tabs, and a Subject Line. Envelope definition missing."
POST https://demo.docusign.net/restapi/v2/accounts/xxxxx/envelopes HTTP/1.1
X-DocuSign-Authentication: {"Username":"xxxxxx","Password":"xxxxx","IntegratorKey":"xxxxxx"}
Content-Type: multipart/form-data; boundary=AAA
Accept: application/json
Host: demo.docusign.net
Content-Length: 90500
Expect: 100-continue
--AAA
Content-Type: application/json
Content-Disposition: form-data
{
"status": "sent",
"recipients": {
"signers": [{
"tabs": {
"signHeretabs": [{
"yPosition": "15",
"xPosition": "249",
"width": "100",
"tablabel": null,
"required": "TRUE",
"recipientId": "1",
"pagenumber": "1",
"fontSize": "Size12",
"font": "Calibri",
"documentid": "1",
"anchorYoffset": null,
"anchorXOffset": null,
"anchorUnits": "pixels",
"anchorString": "Sign Here",
"anchorIgnoreIfNotPresent": "true"
}],
"initialsTabs": [{
"yPosition": "45",
"xPosition": "249",
"width": "100",
"tablabel": null,
"required": "TRUE",
"receipientId": "1",
"pagenumber": "1",
"fontSize": "Size12",
"font": "Calibri",
"documentId": "1",
"anchorYoffset": null,
"anchorXOffset": null,
"anchorUnits": "pixels",
"anchorString": "Initials Here",
"anchorIgnoreIfNotPresent": "true"
}],
"dateSignedTabs": [{
"yPosition": "65",
"xPosition": "249",
"width": "100",
"tablabel": null,
"required": "TRUE",
"receipientid": "1",
"pagenumber": "1",
"fontSize": "Size12",
"font": "Calibri",
"documentid": "1",
"anchorYoffset": "-5",
"anchorXOffset": null,
"anchorUnits": "pixels",
"anchorString": "Date Signed",
"anchorIgnoreIfNotPresent": "true"
}]
},
"routingorder": "1",
"rolename": "roleNameHere",
"recipientid": "1",
"name": "XXXXXXXXXX",
"email": "xxxxx#gcpa.com"
}]
},
"emailsubject": "TestDocuSign Call",
"emailBlurb": "Test Email Blurb",
"documents": [{
"name": "Name1",
"fileExtension": ".pdf",
"documentId": "1",
"documentBase64": null
}]
}
--AAA
Content-Type: application/octet-stream
Content-Disposition: file; filename="Name1.pdf"; documentid="1"
Content-Transfer-Encoding: base64
VGhpcyBpcyBh
You can specify your base64 encoded document bytes in the documentBase64 property
POST https://demo.docusign.net/restapi/v2/accounts/xxxxx/envelopes HTTP/1.1
X-DocuSign-Authentication: {"Username":"xxxxxx","Password":"xxxxx","IntegratorKey":"xxxxxx"}
Content-Type: application/json
{
"status": "sent",
"recipients": {
"signers": [{
"tabs": {
<Removed tabs for brevity>
},
"routingorder": "1",
"rolename": "roleNameHere",
"recipientid": "1",
"name": "XXXXXXXXXX",
"email": "xxxxx#gcpa.com"
}]
},
"emailsubject": "TestDocuSign Call",
"emailBlurb": "Test Email Blurb",
"documents": [{
"name": "Name1",
"fileExtension": ".pdf",
"documentId": "1",
"documentBase64": "VGhpcyBpcyBh"
}]
}

Resources