Problems parsing generated JSON - ruby-on-rails-3

I got a JSON object that I have generated via Rails 3 (via my API). I need to either put a named surrounding tag around it or loose the first "layer". I know it sounds very strange, but I cannot loop it in the client.
This is the parsing code:
#results = RestClient.get "http://localhost:5000/emails?token=#{get_token}", :accept => :json
#array = JSON.parse(#results);
Turn this:
[
{
"email": {
"created_at": "2011-03-02T12:23:59Z",
"updated_at": "2011-03-02T12:23:59Z",
"value_1": "intevisa#sss.com",
"value_2": null,
"id": 4,
"value_3": null,
"user_id": 1,
"value_4": null,
"desc": "intevisa",
"privacy": null
}
},
{
"email": {
"created_at": "2011-03-02T15:19:39Z",
"updated_at": "2011-03-02T15:19:39Z",
"value_1": "another#yahoo.com",
"value_2": null,
"id": 5,
"value_3": null,
"user_id": 1,
"value_4": null,
"desc": "Some text",
"privacy": null
}
},
{
"email": {
"created_at": "2011-03-02T15:20:17Z",
"updated_at": "2011-03-02T15:20:17Z",
"value_1": "my#email.com",
"value_2": null,
"id": 6,
"value_3": null,
"user_id": 1,
"value_4": null,
"desc": "Some text",
"privacy": null
}
},
{
"email": {
"created_at": "2011-03-02T15:21:03Z",
"updated_at": "2011-03-02T15:21:03Z",
"value_1": "An email#google.com",
"value_2": null,
"id": 7,
"value_3": null,
"user_id": 1,
"value_4": null,
"desc": "Hello world",
"privacy": null
}
}
]
Into this:
[
"email": {
"created_at": "2011-03-02T12:23:59Z",
"updated_at": "2011-03-02T12:23:59Z",
"value_1": "intevisa#sss.com",
"value_2": null,
"id": 4,
"value_3": null,
"user_id": 1,
"value_4": null,
"desc": "intevisa",
"privacy": null
},
"email": {
"created_at": "2011-03-02T15:19:39Z",
"updated_at": "2011-03-02T15:19:39Z",
"value_1": "another#yahoo.com",
"value_2": null,
"id": 5,
"value_3": null,
"user_id": 1,
"value_4": null,
"desc": "Some text",
"privacy": null
},
"email": {
"created_at": "2011-03-02T15:20:17Z",
"updated_at": "2011-03-02T15:20:17Z",
"value_1": "my#email.com",
"value_2": null,
"id": 6,
"value_3": null,
"user_id": 1,
"value_4": null,
"desc": "Some text",
"privacy": null
},
"email": {
"created_at": "2011-03-02T15:21:03Z",
"updated_at": "2011-03-02T15:21:03Z",
"value_1": "An email#google.com",
"value_2": null,
"id": 7,
"value_3": null,
"user_id": 1,
"value_4": null,
"desc": "Hello world",
"privacy": null
}
]
This is how I try to loop through it in the client.
<% #array['email'].each do |item| %>
<%= item['value_1'] %>
<% end %>

Try the following in config > initializers > wrap_parameters.rb
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActionController::Base.wrap_parameters format: [:json]
# Disable root element in JSON by default.
if defined?(ActiveRecord)
ActiveRecord::Base.include_root_in_json = false
end
By setting the "include_root_in_json" to false, it should get you the desired output

Related

API call to return a record based on a nested value

I am attempting to find the account with room 101. Room 101 is a nested value and I can't figure out how to write the query to only return the accont with room = 101. Hopefully somebody knows the answer.
This API call:
https://{{fqdn}}/admin/scaffolds/accounts/index.json?api_key={{api-key}}
Returns these results:
[
{
"id": 1,
"type": null,
"login": "xbox1",
"crypted_password": "$2a$11$0Wx3vC89gYaF/89mk66S1urZ2G.hm1LZDTYaVzyqCiMwlu8lzM11y",
"salt": null,
"state": "active",
"first_name": "xbox",
"last_name": "one",
"email": "xbox1#test.com",
"usage_plan_id": 1,
"usage_minutes": null,
"unlimited_usage_minutes": true,
"usage_expiration": null,
"no_usage_expiration": true,
"automatic_login": true,
"note": null,
"logged_in_at": "2022-04-25T11:16:33.622-07:00",
"created_at": "2022-04-25T05:22:09.259-07:00",
"updated_at": "2022-04-25T12:23:10.472-07:00",
"created_by": "tboyer",
"updated_by": "expire_sessions",
"mb_up": 56,
"mb_down": 429,
"pkts_up": 160309,
"pkts_down": 325389,
"usage_mb_up": null,
"usage_mb_down": null,
"unlimited_usage_mb_up": true,
"unlimited_usage_mb_down": true,
"company": null,
"address1": null,
"address2": null,
"city": null,
"region": null,
"zip": null,
"country": "US",
"phone": null,
"bill_at": null,
"lock_version": 11,
"charge_attempted_at": null,
"lock_devices": false,
"relative_usage_lifetime": null,
"scratch": null,
"portal_message": null,
"max_devices": 1,
"unlimited_devices": false,
"max_sessions": 1,
"unlimited_sessions": false,
"max_dedicated_ips": 1,
"account_group_id": 1,
"email2": null,
"pre_shared_key": "D71TP6QEH8YAS239",
"phone_validation_code": null,
"email_validation_code": null,
"phone_validated": false,
"email_validated": true,
"phone_validation_code_expires_at": null,
"email_validation_code_expires_at": null,
"max_party_devices": 0,
"unlimited_party_devices": false,
"nt_password": "3b1b47e42e0463276e3ded6cef349f93",
"upnp_enabled": true,
"automatic_provision": false,
"ips_are_static": true,
"guid": null,
"balance": "0.0",
"full_name": "xbox one",
"mb_down_consumed": 429,
"mb_down_left": 0,
"mb_up_consumed": 56,
"mb_up_left": 0,
"name": "xbox1",
"quota": "unlimited",
"total_utilization": null,
"unlimited_max_devices": false,
"unlimited_max_sessions": false,
"account_group": {
"id": 1,
"policy_id": 3,
"name": "Post-Auth",
"priority": 4,
"note": null,
"created_at": "2022-04-25T06:00:19.161-07:00",
"updated_at": "2022-04-25T06:01:11.936-07:00",
"created_by": "tboyer",
"updated_by": "puma: cluster worker 1: 92557",
"scratch": null,
"conference_id": null,
"disable_enhanced_psk_security": false
},
"account_groups": [
{
"id": 1,
"policy_id": 3,
"name": "Post-Auth",
"priority": 4,
"note": null,
"created_at": "2022-04-25T06:00:19.161-07:00",
"updated_at": "2022-04-25T06:01:11.936-07:00",
"created_by": "tboyer",
"updated_by": "puma: cluster worker 1: 92557",
"scratch": null,
"conference_id": null,
"disable_enhanced_psk_security": false
}
],
"devices": [],
"login_sessions": [],
"media_converters": [],
"pms_guests": [],
"pms_rooms": [],
"usage_plan": {
"id": 1,
"account_group_id": 1,
"name": "test",
"description": null,
"currency": "USD",
"recurring_method": "none",
"recurring_day": null,
"variable_recurring_day": true,
"automatic_login": true,
"note": null,
"created_at": "2022-04-25T08:04:58.091-07:00",
"updated_at": "2022-04-25T08:04:58.091-07:00",
"created_by": "tboyer",
"updated_by": "tboyer",
"time_plan_id": null,
"quota_plan_id": null,
"usage_lifetime_time": null,
"absolute_usage_lifetime": null,
"unlimited_usage_lifetime": true,
"no_usage_lifetime": false,
"recurring_retry_grace_minutes": 1440,
"recurring_fail_limit": 5,
"prorate_credit": false,
"permit_unpaid_ar": false,
"pms_server_id": null,
"lock_devices": false,
"scratch": null,
"max_sessions": 1,
"max_devices": 1,
"unlimited_devices": false,
"unlimited_sessions": false,
"usage_lifetime_time_unit": "days",
"max_dedicated_ips": 0,
"pms_guest_match_operator": "OR",
"recurring_lifetime_time": null,
"recurring_lifetime_time_unit": "months",
"unlimited_recurring_lifetime": true,
"sms_gateway_id": null,
"validation_method": "none",
"validation_grace_minutes": 0,
"max_party_devices": 0,
"unlimited_party_devices": false,
"upnp_enabled": true,
"automatic_provision": false,
"conference_id": null,
"ips_are_static": false,
"base_price": null
},
"vlan_tag_assignments": []
},
{
"id": 2,
"type": null,
"login": "xbox2",
"crypted_password": "$2a$11$y20aajlZCxkGkJ1jL4lyTOvhEv0mHb9gazi03U1iqNzRSBckBdEAS",
"salt": null,
"state": "active",
"first_name": "xbox",
"last_name": "two",
"email": "xbox2#test.com",
"usage_plan_id": 1,
"usage_minutes": null,
"unlimited_usage_minutes": true,
"usage_expiration": null,
"no_usage_expiration": true,
"automatic_login": true,
"note": null,
"logged_in_at": "2022-04-27T12:27:10.765-07:00",
"created_at": "2022-04-25T05:22:37.257-07:00",
"updated_at": "2022-04-29T07:35:44.872-07:00",
"created_by": "tboyer",
"updated_by": "tboyer",
"mb_up": 253,
"mb_down": 1826,
"pkts_up": 758129,
"pkts_down": 1516621,
"usage_mb_up": null,
"usage_mb_down": null,
"unlimited_usage_mb_up": true,
"unlimited_usage_mb_down": true,
"company": null,
"address1": null,
"address2": null,
"city": null,
"region": null,
"zip": null,
"country": "US",
"phone": null,
"bill_at": null,
"lock_version": 50,
"charge_attempted_at": null,
"lock_devices": false,
"relative_usage_lifetime": null,
"scratch": null,
"portal_message": null,
"max_devices": null,
"unlimited_devices": true,
"max_sessions": null,
"unlimited_sessions": true,
"max_dedicated_ips": 1,
"account_group_id": 1,
"email2": null,
"pre_shared_key": "Z79LCS6NJREH3MGU",
"phone_validation_code": null,
"email_validation_code": null,
"phone_validated": false,
"email_validated": true,
"phone_validation_code_expires_at": null,
"email_validation_code_expires_at": null,
"max_party_devices": 0,
"unlimited_party_devices": false,
"nt_password": "3b1b47e42e0463276e3ded6cef349f93",
"upnp_enabled": true,
"automatic_provision": false,
"ips_are_static": false,
"guid": null,
"balance": "0.0",
"full_name": "xbox two",
"mb_down_consumed": 1826,
"mb_down_left": 0,
"mb_up_consumed": 253,
"mb_up_left": 0,
"name": "xbox2",
"quota": "unlimited",
"total_utilization": null,
"unlimited_max_devices": true,
"unlimited_max_sessions": true,
"account_group": {
"id": 1,
"policy_id": 3,
"name": "Post-Auth",
"priority": 4,
"note": null,
"created_at": "2022-04-25T06:00:19.161-07:00",
"updated_at": "2022-04-25T06:01:11.936-07:00",
"created_by": "tboyer",
"updated_by": "puma: cluster worker 1: 92557",
"scratch": null,
"conference_id": null,
"disable_enhanced_psk_security": false
},
"account_groups": [
{
"id": 1,
"policy_id": 3,
"name": "Post-Auth",
"priority": 4,
"note": null,
"created_at": "2022-04-25T06:00:19.161-07:00",
"updated_at": "2022-04-25T06:01:11.936-07:00",
"created_by": "tboyer",
"updated_by": "puma: cluster worker 1: 92557",
"scratch": null,
"conference_id": null,
"disable_enhanced_psk_security": false
}
],
"devices": [
{
"id": 10,
"account_id": 2,
"name": "MBP",
"mac": "a0:ce:c8:ca:1f:e7",
"note": null,
"created_at": "2022-04-27T12:27:09.304-07:00",
"updated_at": "2022-04-27T12:27:09.463-07:00",
"created_by": "puma: cluster worker 0: 42604",
"updated_by": "puma: cluster worker 0: 42604",
"scratch": null,
"lock_version": 1,
"binat": false,
"lan_party_id": null,
"hidden_from_portal": false,
"static_ip_id": null
},
{
"id": 9,
"account_id": 2,
"name": "XboxOne",
"mac": "bc:83:85:84:78:ad",
"note": null,
"created_at": "2022-04-25T15:35:16.803-07:00",
"updated_at": "2022-04-29T07:35:44.881-07:00",
"created_by": "puma: cluster worker 1: 82720",
"updated_by": "puma: cluster worker 1: 50494",
"scratch": null,
"lock_version": 9,
"binat": false,
"lan_party_id": null,
"hidden_from_portal": false,
"static_ip_id": null
}
],
"login_sessions": [],
"media_converters": [],
"pms_guests": [],
"pms_rooms": [
{
"id": 1,
"pms_server_id": null,
"room": "101",
"created_by": "tboyer",
"updated_by": "tboyer",
"created_at": "2022-04-26T14:54:28.306-07:00",
"updated_at": "2022-04-30T05:05:18.384-07:00",
"pms_property_id": null
}
],
"usage_plan": {
"id": 1,
"account_group_id": 1,
"name": "test",
"description": null,
"currency": "USD",
"recurring_method": "none",
"recurring_day": null,
"variable_recurring_day": true,
"automatic_login": true,
"note": null,
"created_at": "2022-04-25T08:04:58.091-07:00",
"updated_at": "2022-04-25T08:04:58.091-07:00",
"created_by": "tboyer",
"updated_by": "tboyer",
"time_plan_id": null,
"quota_plan_id": null,
"usage_lifetime_time": null,
"absolute_usage_lifetime": null,
"unlimited_usage_lifetime": true,
"no_usage_lifetime": false,
"recurring_retry_grace_minutes": 1440,
"recurring_fail_limit": 5,
"prorate_credit": false,
"permit_unpaid_ar": false,
"pms_server_id": null,
"lock_devices": false,
"scratch": null,
"max_sessions": 1,
"max_devices": 1,
"unlimited_devices": false,
"unlimited_sessions": false,
"usage_lifetime_time_unit": "days",
"max_dedicated_ips": 0,
"pms_guest_match_operator": "OR",
"recurring_lifetime_time": null,
"recurring_lifetime_time_unit": "months",
"unlimited_recurring_lifetime": true,
"sms_gateway_id": null,
"validation_method": "none",
"validation_grace_minutes": 0,
"max_party_devices": 0,
"unlimited_party_devices": false,
"upnp_enabled": true,
"automatic_provision": false,
"conference_id": null,
"ips_are_static": false,
"base_price": null
},
"vlan_tag_assignments": []
}
]
How can I write an API call that will return only the record with room:101?
I think that the API endpoint you mentioned returns always all accounts. You need find out if endpoint accepts query parameters to filter accounts. If not, you need process returned JSON by yourself.

Display data from an Api in the V-CALENDAR Vuetify Vuejs

I have the following data coming from my api:
[
{
"id": 1,
"start": "2020-12-24 01:00",
"end": "2020-12-24 01:30",
"comments": null,
"createdAt": "2020-12-24T19:37:52.699Z",
"updatedAt": "2020-12-24T19:37:52.699Z",
"clientId": 1,
"employeeId": null,
"serviceId": null,
"appointmentStatusId": null,
"tenantId": 1,
"employee": null,
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 3,
"start": "2020-12-24 21:15",
"end": "2020-12-24 22:00",
"comments": null,
"createdAt": "2020-12-24T19:45:03.854Z",
"updatedAt": "2020-12-24T19:45:03.854Z",
"clientId": 1,
"employeeId": 1,
"serviceId": null,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Aline",
"lastName": "Magalhães"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 2,
"start": "2020-12-24 01:00",
"end": "2020-12-24 02:00",
"comments": null,
"createdAt": "2020-12-24T19:39:19.184Z",
"updatedAt": "2020-12-24T19:39:19.184Z",
"clientId": 1,
"employeeId": 1,
"serviceId": null,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Aline",
"lastName": "Magalhães"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 13,
"start": "2020-12-25 06:00",
"end": "2020-12-25 07:00",
"comments": "Fuck you",
"createdAt": "2020-12-25T16:24:10.893Z",
"updatedAt": "2020-12-25T16:24:10.893Z",
"clientId": 1,
"employeeId": 2,
"serviceId": 1,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Margareth",
"lastName": "Martins"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 14,
"start": "2020-12-25 01:00",
"end": "2020-12-25 06:00",
"comments": null,
"createdAt": "2020-12-25T22:08:40.878Z",
"updatedAt": "2020-12-25T22:08:40.878Z",
"clientId": 1,
"employeeId": 1,
"serviceId": 1,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Aline",
"lastName": "Magalhães"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 15,
"start": "2020-12-26 08:30",
"end": "2020-12-26 09:00",
"comments": null,
"createdAt": "2020-12-25T22:52:31.439Z",
"updatedAt": "2020-12-25T22:52:31.439Z",
"clientId": 1,
"employeeId": 1,
"serviceId": 1,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Aline",
"lastName": "Magalhães"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 10,
"start": "2020-12-23 09:00",
"end": "2020-12-23 09:30",
"comments": "é fodauuuuuuu",
"createdAt": "2020-12-25T15:12:20.790Z",
"updatedAt": "2020-12-25T15:12:20.790Z",
"clientId": 1,
"employeeId": null,
"serviceId": 1,
"appointmentStatusId": null,
"tenantId": 1,
"employee": null,
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 11,
"start": "2020-12-23 09:00",
"end": "2020-12-23 12:00",
"comments": "é fodauuuuuuu",
"createdAt": "2020-12-25T15:12:44.161Z",
"updatedAt": "2020-12-25T15:12:44.161Z",
"clientId": 1,
"employeeId": 1,
"serviceId": 1,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Aline",
"lastName": "Magalhães"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 4,
"start": "2020-12-25 01:00",
"end": "2020-12-25 05:00",
"comments": null,
"createdAt": "2020-12-25T02:32:32.574Z",
"updatedAt": "2020-12-25T02:32:32.574Z",
"clientId": 1,
"employeeId": 1,
"serviceId": null,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Aline",
"lastName": "Magalhães"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 5,
"start": "2020-12-24 01:00",
"end": "2020-12-24 03:00",
"comments": "ghhhhhh",
"createdAt": "2020-12-25T02:36:52.243Z",
"updatedAt": "2020-12-25T02:36:52.243Z",
"clientId": 1,
"employeeId": 1,
"serviceId": null,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Aline",
"lastName": "Magalhães"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 6,
"start": "2020-12-25 01:15",
"end": "2020-12-25 02:00",
"comments": null,
"createdAt": "2020-12-25T02:38:22.711Z",
"updatedAt": "2020-12-25T02:38:22.711Z",
"clientId": 1,
"employeeId": 1,
"serviceId": null,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Aline",
"lastName": "Magalhães"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 7,
"start": "2020-12-25 00:15",
"end": "2020-12-25 03:00",
"comments": "treeeeee",
"createdAt": "2020-12-25T14:54:51.766Z",
"updatedAt": "2020-12-25T14:54:51.766Z",
"clientId": 1,
"employeeId": 1,
"serviceId": null,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Aline",
"lastName": "Magalhães"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 8,
"start": "2020-12-25 04:00",
"end": "2020-12-25 06:00",
"comments": null,
"createdAt": "2020-12-25T15:02:54.737Z",
"updatedAt": "2020-12-25T15:02:54.737Z",
"clientId": 1,
"employeeId": 1,
"serviceId": null,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Aline",
"lastName": "Magalhães"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 12,
"start": "2020-12-31 19:30",
"end": "2020-12-31 21:00",
"comments": "Agora foi",
"createdAt": "2020-12-25T15:25:40.233Z",
"updatedAt": "2020-12-25T15:25:40.233Z",
"clientId": 1,
"employeeId": 1,
"serviceId": 1,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Aline",
"lastName": "Magalhães"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
}
]
I need to present only some of this data in the V-Calendar vuetify and according to its documentation it would be for example:
{
name: 'name'
start: '0000-00-00 00:00'
end: '0000-00-00 00:00'
}
To reach this structure I have the following code snippet in my .Vue:
created () {
this.initialize()
},
methods: {
initialize () {
// request Events
axios.get('http://192.168.15.11:3000/events')
.then((response) => {
this.events = response.data
for (const item of this.events) {
const name = item.client.firstName + ' ' + item.client.lastName
const start = item.start
const end = item.end
const items = { name, start, end }
this.events = this.items
console.log(items);
}
})
.catch((error) => {
console.log(error.response);
})
},
My console gives this feedback with the right format I need but in the calendar there is no event:
The V-Calendar excerpt:
<v-calendar
ref="calendar"
v-model="focus"
color="primary"
locale="pt-br"
:events="events"
:event-color="getEventColor"
:type="type"
#click:event="showEvent"
#click:more="viewDay"
#click:date="viewDay"
>
</v-calendar>
data: () => ({
events []
}),
Where can I be wrong, could someone help me?
Great work on providing a good context for your problem. V-calendar wants events to be an array, not a single object.
Maybe try something like this:
this.events = [];
axios.get('http://192.168.15.11:3000/events')
.then((response) => {
const events = response.data
for (const item of events) {
const name = item.client.firstName + ' ' + item.client.lastName
const start = item.start
const end = item.end
this.events.push({ name, start, end })
}
})

Shopify find order ID in hook

I need to connect some external service to the Shopify store. I've set up the hook on Order creation event, I can receive it but I didn't find information about what incoming data means. I mean I need to store order_id in order to be able to control it. I'm receiving test hook that contains field named order_number. Can anyone confirm that this field is exact order ID? Also I'm receiving in the hook id field but I guess that field is hook_id, not order_id
If you already created webhook for Order creation then when order will be created, you will receive JSON with order object. This object has id property
Example of this JSON:
{
"id": 820982911946154500,
"email": "jon#doe.ca",
"closed_at": null,
"created_at": "2017-11-29T05:57:26-05:00",
"updated_at": "2017-11-29T05:57:26-05:00",
"number": 234,
"note": null,
"token": "123456abcd",
"gateway": null,
"test": true,
"total_price": "793.50",
"subtotal_price": "783.50",
"total_weight": 0,
"total_tax": "0.00",
"taxes_included": false,
"currency": "USD",
"financial_status": "voided",
"confirmed": false,
"total_discounts": "5.00",
"total_line_items_price": "788.50",
"cart_token": null,
"buyer_accepts_marketing": true,
"name": "#9999",
"referring_site": null,
"landing_site": null,
"cancelled_at": "2017-11-29T05:57:26-05:00",
"cancel_reason": "customer",
"total_price_usd": null,
"checkout_token": null,
"reference": null,
"user_id": null,
"location_id": null,
"source_identifier": null,
"source_url": null,
"processed_at": null,
"device_id": null,
"phone": null,
"customer_locale": "en",
"app_id": null,
"browser_ip": null,
"landing_site_ref": null,
"order_number": 1234,
"discount_codes": [],
"note_attributes": [],
"payment_gateway_names": [
"visa",
"bogus"
],
"processing_method": "",
"checkout_id": null,
"source_name": "web",
"fulfillment_status": "pending",
"tax_lines": [],
"tags": "",
"contact_email": "jon#doe.ca",
"order_status_url": "https://checkout.shopify.com/24877298/orders/123456abcd/authenticate?key=abcdefg",
"line_items": [
{
"id": 866550311766439000,
"variant_id": null,
"title": "Test Product Discount",
"quantity": 1,
"price": "99.50",
"grams": 0,
"sku": "",
"variant_title": null,
"vendor": null,
"fulfillment_service": "manual",
"product_id": 252236300325,
"requires_shipping": true,
"taxable": true,
"gift_card": false,
"name": "Test Product Discount",
"variant_inventory_management": null,
"properties": [],
"product_exists": true,
"fulfillable_quantity": 1,
"total_discount": "0.00",
"fulfillment_status": null,
"tax_lines": []
},
{
"id": 141249953214522980,
"variant_id": null,
"title": "ABSTRACT PENDANT, MULTI-COLOURED, ROSE GOLD PLATING",
"quantity": 1,
"price": "689.00",
"grams": 100,
"sku": "030711585240",
"variant_title": null,
"vendor": null,
"fulfillment_service": "manual",
"product_id": 252560506917,
"requires_shipping": true,
"taxable": true,
"gift_card": false,
"name": "ABSTRACT PENDANT, MULTI-COLOURED, ROSE GOLD PLATING",
"variant_inventory_management": null,
"properties": [],
"product_exists": true,
"fulfillable_quantity": 1,
"total_discount": "5.00",
"fulfillment_status": null,
"tax_lines": []
}
],
"shipping_lines": [
{
"id": 271878346596884000,
"title": "Generic Shipping",
"price": "10.00",
"code": null,
"source": "shopify",
"phone": null,
"requested_fulfillment_service_id": null,
"delivery_category": null,
"carrier_identifier": null,
"discounted_price": "10.00",
"tax_lines": []
}
],
"billing_address": {
"first_name": "Bob",
"address1": "123 Billing Street",
"phone": "555-555-BILL",
"city": "Billtown",
"zip": "K2P0B0",
"province": "Kentucky",
"country": "United States",
"last_name": "Biller",
"address2": null,
"company": "My Company",
"latitude": null,
"longitude": null,
"name": "Bob Biller",
"country_code": "US",
"province_code": "KY"
},
"shipping_address": {
"first_name": "Steve",
"address1": "123 Shipping Street",
"phone": "555-555-SHIP",
"city": "Shippington",
"zip": "40003",
"province": "Kentucky",
"country": "United States",
"last_name": "Shipper",
"address2": null,
"company": "Shipping Company",
"latitude": null,
"longitude": null,
"name": "Steve Shipper",
"country_code": "US",
"province_code": "KY"
},
"fulfillments": [],
"refunds": [],
"customer": {
"id": 115310627314723950,
"email": "john#test.com",
"accepts_marketing": false,
"created_at": null,
"updated_at": null,
"first_name": "John",
"last_name": "Smith",
"orders_count": 0,
"state": "disabled",
"total_spent": "0.00",
"last_order_id": null,
"note": null,
"verified_email": true,
"multipass_identifier": null,
"tax_exempt": false,
"phone": null,
"tags": "",
"last_order_name": null,
"default_address": {
"id": 715243470612851200,
"customer_id": 115310627314723950,
"first_name": null,
"last_name": null,
"company": null,
"address1": "123 Elm St.",
"address2": null,
"city": "Ottawa",
"province": "Ontario",
"country": "Canada",
"zip": "K2H7A8",
"phone": "123-123-1234",
"name": "",
"province_code": "ON",
"country_code": "CA",
"country_name": "Canada",
"default": false
}
}
}

Add Product Variant - 404 Error

I am developing a VB.NET application to interact with our new Shopify store. I am in the process of automating product additions/updates/removal based on data in our Oracle database.
Basically the application creates a new Shopify part for a pattern, then creates product variants for each sku in that pattern. It does this by POSTing and PUTing requests using the HttpWebRequest class. This was working great through yesterday afternoon, now today for some reason it's failing on the product variant creation/update with a 404 - Not Found error code.
The product add request JSON is below. This works perfectly, it creates the part on Shopify which I can then see through the admin panel. This is POSTed to the URL "https://key:password#bath-and-window-direct.myshopify.com/admin/products.json" (where key and password are replaced with our credentials)
{
"product": {
"id": 0,
"body_html": "A classic combination of embroidery and cut work form the flowing border, creating your own seaside retreat. ",
"title": "Seabreeze Sand",
"vendor": "SKL",
"product_type": "",
"published_scope": "global",
"tags": "J71227",
"variants": null,
"options": null,
"images": [{
"id": 0,
"product_id": 0,
"position": 1,
"src": "http:\/\/i320.photobucket.com\/albums\/nn353\/fkhphoto\/J71227main.jpg",
"variant_ids": null
}],
"image": null
}
}
This is the JSON reply I'm receiving after this call, and I can also see the part added in the Shopify admin panel:
{
"product": {
"id": 7874734983,
"title": "Seabreeze Sand",
"body_html": "A classic combination of embroidery and cut work form the flowing border, creating your own seaside retreat. ",
"vendor": "SKL",
"product_type": "",
"created_at": "2016-07-14T10:43:56-04:00",
"handle": "seabreeze-sand",
"updated_at": "2016-07-14T10:43:56-04:00",
"published_at": "2016-07-14T10:43:56-04:00",
"template_suffix": null,
"published_scope": "global",
"tags": "J71227",
"variants": [{
"id": 24925005383,
"product_id": 7874734983,
"title": "Default Title",
"price": "0.00",
"sku": "",
"position": 1,
"grams": 0,
"inventory_policy": "deny",
"compare_at_price": null,
"fulfillment_service": "manual",
"inventory_management": null,
"option1": "Default Title",
"option2": null,
"option3": null,
"created_at": "2016-07-14T10:43:56-04:00",
"updated_at": "2016-07-14T10:43:56-04:00",
"taxable": true,
"barcode": null,
"image_id": null,
"inventory_quantity": 1,
"weight": 0.0,
"weight_unit": "lb",
"old_inventory_quantity": 1,
"requires_shipping": true
}],
"options": [{
"id": 9404426823,
"product_id": 7874734983,
"name": "Title",
"position": 1,
"values": ["Default Title"]
}],
"images": [{
"id": 16242879303,
"product_id": 7874734983,
"position": 1,
"created_at": "2016-07-14T10:43:56-04:00",
"updated_at": "2016-07-14T10:43:56-04:00",
"src": "https://cdn.shopify.com/s/files/1/1363/2407/products/J71227main.jpg?v=1468507436",
"variant_ids": []
}],
"image": {
"id": 16242879303,
"product_id": 7874734983,
"position": 1,
"created_at": "2016-07-14T10:43:56-04:00",
"updated_at": "2016-07-14T10:43:56-04:00",
"src": "https://cdn.shopify.com/s/files/1/1363/2407/products/J71227main.jpg?v=1468507436",
"variant_ids": []
}
}
}
Immediately after that, I'm POSTing the following JSON to add a product variant to this newly created part, to the URL "https://key:password#bath-and-window-direct.myshopify.com/admin/products/7874734983/variants.json". This is the call that returns a 404 - Not Found error through the HttpWebRequest class.
{
"variant": {
"id": 0,
"product_id": 7874734983,
"title": "Seabreeze Tier Curtain in Sand",
"price": "11.99",
"sku": "J7122700013V09",
"compare_at_price": "0.00",
"position": 0,
"grams": 0,
"option1": "57X13 ROD POCKET VAL",
"option2": null,
"option3": null,
"taxable": true,
"barcode": "036326422417",
"weight": 0,
"weight_unit": "lb",
"inventory_quantity": 550,
"old_inventory_quantity": 550,
"requires_shipping": true,
"image_id": null,
"metafields": [{
"id": 0,
"key": "point1",
"value": "57 x 13 Valance",
"value_type": "string",
"namespace": "J7122700013V09"
},
{
"id": 0,
"key": "point2",
"value": "To achieve the look in the photo, use one valance and one tier pair.",
"value_type": "string",
"namespace": "J7122700013V09"
},
{
"id": 0,
"key": "point3",
"value": "Feels like you are in your own beach cottage.",
"value_type": "string",
"namespace": "J7122700013V09"
},
{
"id": 0,
"key": "point4",
"value": "100% Polyester.",
"value_type": "string",
"namespace": "J7122700013V09"
},
{
"id": 0,
"key": "point5",
"value": " ",
"value_type": "string",
"namespace": "J7122700013V09"
}]
}
}
What am I doing wrong? The URLs, when copied into a web browser, work perfectly fine...I can see all the JSON of the current data. But when attempting to add the variant, I'm getting the 404.
Try leaving out the "id": 0 properties — both from the variant and from the metafields. Shopify will determine the IDs automatically.

Stock Quantity of ProductVariant not decreased in shopify shop when placing order via API

I am posting the following Order to the shopify api Order endpoint. The Order shows up in the shop and everything works as it should, except that the stock quantity of the variants in orders placed via the API are not decreased automatically by shopify. When I place an order within the admin console, they are decreased automatically. Shopify inventory tracking is turned on for the products. Any ideas would be greatly appreciated.
{
"order": {
"email": "someName#yahoo.com",
"financial_status": "paid",
"fulfillment_status": null,
"send_receipt": true,
"send_fulfillment_receipt": true,
"note": "Created by someName",
"line_items": [
{
"variant_id": 21718275463,
"quantity": 1,
"price": 99,
"requires_shipping": true,
"product_id": 6820646151
},
{
"variant_id": 21717700871,
"quantity": 1,
"price": 1000,
"requires_shipping": true,
"product_id": 6820646151
},
{
"variant_id": 21717690055,
"quantity": 1,
"price": 555,
"requires_shipping": true,
"product_id": 6821668807
}
],
"processing_method": "offsite",
"shipping_address": {
"first_name": "Chris",
"address1": "111 Love Road",
"phone": "9999999999",
"city": "St. Louis",
"zip": "63123",
"province": "MO",
"country": "United States",
"last_name": "Becker",
"name": "Chris Becker",
"country_code": "US",
"province_code": "MO"
},
"source_name": "someName",
"taxes_included": false,
"shipping_lines": [
{
"title": "standard",
"price": 0.00,
"code": null,
"source": "brand owner on shopify",
"carrier_identifier": null,
"tax_lines": null
}
],
"tags": "someName"
}
}
{
"variant": {
"id": 21718275463,
"product_id": 6820646151,
"title": "m / red",
"price": "99.00",
"sku": "",
"position": 2,
"grams": 0,
"inventory_policy": "deny",
"compare_at_price": "900.00",
"fulfillment_service": "manual",
"inventory_management": "shopify",
"option1": "m",
"option2": "red",
"option3": null,
"created_at": "2016-05-27T13:16:26-04:00",
"updated_at": "2016-05-28T13:28:20-04:00",
"taxable": false,
"barcode": "",
"image_id": 13217378823,
"inventory_quantity": 1,
"weight": 0,
"weight_unit": "lb",
"old_inventory_quantity": 1,
"requires_shipping": true
}
}
{
"variant": {
"id": 21717700871,
"product_id": 6820646151,
"title": "s / green",
"price": "1000.00",
"sku": "",
"position": 1,
"grams": 0,
"inventory_policy": "deny",
"compare_at_price": "1111.00",
"fulfillment_service": "manual",
"inventory_management": "shopify",
"option1": "s",
"option2": "green",
"option3": null,
"created_at": "2016-05-27T13:05:56-04:00",
"updated_at": "2016-05-28T12:17:22-04:00",
"taxable": true,
"barcode": "",
"image_id": 13160712135,
"inventory_quantity": 2,
"weight": 0,
"weight_unit": "lb",
"old_inventory_quantity": 2,
"requires_shipping": true
}
}
{
"variant": {
"id": 21717690055,
"product_id": 6821668807,
"title": "Default Title",
"price": "555.00",
"sku": "",
"position": 1,
"grams": 0,
"inventory_policy": "deny",
"compare_at_price": "666.00",
"fulfillment_service": "manual",
"inventory_management": "shopify",
"option1": "Default Title",
"option2": null,
"option3": null,
"created_at": "2016-05-27T13:05:39-04:00",
"updated_at": "2016-05-28T12:17:22-04:00",
"taxable": true,
"barcode": "",
"image_id": null,
"inventory_quantity": 2,
"weight": 0,
"weight_unit": "lb",
"old_inventory_quantity": 2,
"requires_shipping": true
}
}
You created a fake order using the API. Fake orders like that don't transact money or trigger the usual internal checks and balances without some extra effort. Maybe if you tried adding a fulfillment to the order, Shopify might ding inventory levels? Seems like something to try anyway.