Reformatting JSON Files in R - r

I have a JSON file formatted as follows:
[
{
"StreetAddress": "",
"City": "",
"State": "",
"Zip": "V6A 2P3",
"County": "",
"Country": "",
"SPLC": "",
"CountryPostalFilter": "",
"AbbreviationFormat": "",
"CountryAbbreviation": ""
},
{
"StreetAddress": "",
"City": "",
"State": "",
"Zip": "V6A 2P3",
"County": "",
"Country": "",
"SPLC": "",
"CountryPostalFilter": "",
"AbbreviationFormat": "",
"CountryAbbreviation": ""
}
]
Is there R script I can use to reformat the file as follows:
{
"Locations": [
{
"Address": {
"StreetAddress": "1000 Herrontown Rd",
"City": "Princeton",
"State": "NJ",
"Zip": "",
"County": "",
"Country": null,
"SPLC": "",
"CountryPostalFilter": 0,
"AbbreviationFormat": 0,
"CountryAbbreviation": "US"
}
},
{
"Address": {
"StreetAddress": "457 N Harrison St",
"City": "",
"State": "",
"Zip": "08540",
"County": "",
"Country": null,
"SPLC": "",
"CountryPostalFilter": 0,
"AbbreviationFormat": 0
}
}
]
}

df <- jsonlite::fromJSON('[
{
"StreetAddress": "",
"City": "",
"State": "",
"Zip": "V6A 2P3",
"County": "",
"Country": "",
"SPLC": "",
"CountryPostalFilter": "",
"AbbreviationFormat": "",
"CountryAbbreviation": ""
},
{
"StreetAddress": "",
"City": "",
"State": "",
"Zip": "V6A 2P3",
"County": "",
"Country": "",
"SPLC": "",
"CountryPostalFilter": "",
"AbbreviationFormat": "",
"CountryAbbreviation": ""
}
]')
In comparison with #Brian's answer, I don't set simplifyDataFrame = F so the JSON form will be converted to a data.frame object in R. Then use tibble() to put this data frame into a 2x1 data frame with column name Address(This is a little tricky because base data.frame() cannot do that).
res <- list(Locations = tibble::tibble(Address = df))
jsonlite::toJSON(res, pretty = T)
Edit: This method works even when I set simplifyDataFrame = F, because tibble() also allow named lists as columns.
Output
{
"Locations": [
{
"Address": {
"StreetAddress": "",
"City": "",
"State": "",
"Zip": "V6A 2P3",
"County": "",
"Country": "",
"SPLC": "",
"CountryPostalFilter": "",
"AbbreviationFormat": "",
"CountryAbbreviation": ""
}
},
{
"Address": {
"StreetAddress": "",
"City": "",
"State": "",
"Zip": "V6A 2P3",
"County": "",
"Country": "",
"SPLC": "",
"CountryPostalFilter": "",
"AbbreviationFormat": "",
"CountryAbbreviation": ""
}
}
]
}

df<-jsonlite::fromJSON('[
{
"StreetAddress": "",
"City": "",
"State": "",
"Zip": "V6A 2P3",
"County": "",
"Country": "",
"SPLC": "",
"CountryPostalFilter": "",
"AbbreviationFormat": "",
"CountryAbbreviation": ""
},
{
"StreetAddress": "",
"City": "",
"State": "",
"Zip": "V6A 2P3",
"County": "",
"Country": "",
"SPLC": "",
"CountryPostalFilter": "",
"AbbreviationFormat": "",
"CountryAbbreviation": ""
}
]', simplifyDataFrame = F)
purrr::map(df, ~list(Address = .x)) %>%
list(Locations = .) %>%
jsonlite::toJSON(pretty = T, auto_unbox = T)
I think this reproduces your desired output exactly.

Related

How do I scrape this table across all pages [no links for the page buttons]

I'm not able to think of way to scrape the table on this website (click on the All Moves Tab): https://www.investmentnews.com/aotm
There are multiple pages but the page buttons do not have links (see image). How could I scrape data from this table?
None of the pages have links because all the page buttons do is replace all of the information on the page with information it receives from a an ajax call to an API endpoint. You can find the endpoint in the network tab in devtools when you click on one of the buttons it will generate a request that you can see in the feed and get the url from.
Use the API endpoint:
For example:
import scrapy
class AotmSpider(scrapy.Spider):
name = 'aotm'
def start_requests(self):
for i in range(1,500):
url = f'https://aotm.in.bonhill.pbc.io/api/getAllAdvisorsListings/{i}'
yield scrapy.Request(url)
def parse(self, response):
yield {"data":response.json()}
Output for a single page:
"data": [
{ "TotalAdvisors": 117860 },
{
"input_one": "1",
"date_entered": "2022-09-23",
"adviser_name": "ANDRES CORDOBA",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "TD Ameritrade, Inc.",
"firm_joining": "Fidelity Personal and Workplace Advisors",
"firm_city": "",
"firm_state": "",
"firm_full_name": "Fidelity/NFS/National Financial",
"firm_full_url": "",
"firm_contact_person": "",
"firm_date_two": "2022-09-23",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-23",
"adviser_name": "CARLOS IVAN SALVATIERRA-DURAN",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "Merrill Lynch, Pierce, Fenner & Smith Incorporated",
"firm_joining": "Morgan Stanley",
"firm_city": "",
"firm_state": "",
"firm_full_name": "Morgan Stanley",
"firm_full_url": "http://www.morganstanley.com",
"firm_contact_person": "",
"firm_date_two": "2022-09-23",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-23",
"adviser_name": "CATHERINE LEEMING ANDERSEN",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "J.P. Morgan Securities LLC",
"firm_joining": "Wells Fargo Clearing Services, LLC",
"firm_city": "Wilton",
"firm_state": "CT",
"firm_full_name": "Wells Fargo",
"firm_full_url": "http://www.wellsfargoadvisors.com",
"firm_contact_person": "",
"firm_date_two": "2022-09-23",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-23",
"adviser_name": "David Nardiello",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "MFA Wealth Advisors, LLC",
"firm_joining": "Northwestern Mutual Investment Services, LLC",
"firm_city": "Pittsburgh",
"firm_state": "PA",
"firm_full_name": "",
"firm_full_url": "http://www.nmfn.com",
"firm_contact_person": "",
"firm_date_two": "2022-09-23",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-23",
"adviser_name": "Elizabeth Anne OConnor",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "Wells Fargo Clearing Services, LLC",
"firm_joining": "The Huntington Investment Company",
"firm_city": "",
"firm_state": "",
"firm_full_name": "Fidelity/NFS/National Financial",
"firm_full_url": "https://www.huntington.com",
"firm_contact_person": "",
"firm_date_two": "2022-09-23",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-23",
"adviser_name": "FELICIA A JACOBS",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "Merrill Lynch, Pierce, Fenner & Smith Incorporated",
"firm_joining": "LPL Financial LLC",
"firm_city": "",
"firm_state": "",
"firm_full_name": "LPL Financial LLC",
"firm_full_url": "https://www.lpl.com",
"firm_contact_person": "",
"firm_date_two": "2022-09-23",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-23",
"adviser_name": "JAMES GERARD STANTON",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "PFS Investments Inc.",
"firm_joining": "J.P. Morgan Securities LLC",
"firm_city": "",
"firm_state": "",
"firm_full_name": "JP Morgan",
"firm_full_url": "http://www.jpmorgansecurities.com",
"firm_contact_person": "",
"firm_date_two": "2022-09-23",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-23",
"adviser_name": "Jared Michael Cox",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "U.S. Bancorp Investments, Inc.",
"firm_joining": "First Horizon Advisors, Inc.",
"firm_city": "",
"firm_state": "",
"firm_full_name": "Fidelity/NFS/National Financial",
"firm_full_url": "http://www.firsthorizon.com",
"firm_contact_person": "",
"firm_date_two": "2022-09-23",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-23",
"adviser_name": "Joshua W Dowden",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "Edward Jones",
"firm_joining": "LPL Financial LLC",
"firm_city": "",
"firm_state": "",
"firm_full_name": "LPL Financial LLC",
"firm_full_url": "https://www.lpl.com",
"firm_contact_person": "",
"firm_date_two": "2022-09-23",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-23",
"adviser_name": "KOREY JOHN DOUCETTE",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "PFS Investments Inc.",
"firm_joining": "Terra Wealth",
"firm_city": "",
"firm_state": "",
"firm_full_name": "Fidelity/NFS/National Financial",
"firm_full_url": "",
"firm_contact_person": "",
"firm_date_two": "2022-09-23",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-23",
"adviser_name": "LISA ANNE MALICK",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "Cambridge Investment Research Advisors, Inc.",
"firm_joining": "Petra Financial Advisors Inc",
"firm_city": "",
"firm_state": "",
"firm_full_name": "Charles Schwab & Co., Inc.",
"firm_full_url": "",
"firm_contact_person": "",
"firm_date_two": "2022-09-23",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-23",
"adviser_name": "MARCUS CORBIN HENDERSON",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "Raymond James Financial Services, Inc.",
"firm_joining": "Marquis Wealth Management Group",
"firm_city": "",
"firm_state": "",
"firm_full_name": "Charles Schwab & Co., Inc.",
"firm_full_url": "",
"firm_contact_person": "",
"firm_date_two": "2022-09-23",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-23",
"adviser_name": "MARIA ELIZABETH LACASA",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "Amerant Investments, Inc.",
"firm_joining": "IFB Wealth Management LLC",
"firm_city": "",
"firm_state": "",
"firm_full_name": "Federal Home Loan Bank of Atlanta",
"firm_full_url": "",
"firm_contact_person": "",
"firm_date_two": "2022-09-23",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-23",
"adviser_name": "NAIM KAWADRI",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "Merrill Lynch, Pierce, Fenner & Smith Incorporated",
"firm_joining": "Fidelity Personal and Workplace Advisors",
"firm_city": "",
"firm_state": "",
"firm_full_name": "Fidelity/NFS/National Financial",
"firm_full_url": "",
"firm_contact_person": "",
"firm_date_two": "2022-09-23",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-23",
"adviser_name": "Paul M. Lamm",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "Edward Jones",
"firm_joining": "Ameriprise Financial Services, LLC",
"firm_city": "",
"firm_state": "",
"firm_full_name": "American Enterprise Investment Services Inc.",
"firm_full_url": "http://www.ameriprise.com",
"firm_contact_person": "",
"firm_date_two": "2022-09-23",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-23",
"adviser_name": "PETER CHASE MASON",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "Aloha Wealth Partners",
"firm_joining": "Foundations Investment Advisors LLC",
"firm_city": "Huntington Beach",
"firm_state": "CA",
"firm_full_name": "Fidelity/NFS/National Financial",
"firm_full_url": "",
"firm_contact_person": "",
"firm_date_two": "2022-09-23",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-23",
"adviser_name": "RICHARD SETH BIRNBAUM",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "Merrill Lynch, Pierce, Fenner & Smith Incorporated",
"firm_joining": "Wells Fargo Clearing Services, LLC",
"firm_city": "Tenafly",
"firm_state": "NJ",
"firm_full_name": "Wells Fargo",
"firm_full_url": "http://www.wellsfargoadvisors.com",
"firm_contact_person": "",
"firm_date_two": "2022-09-23",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-23",
"adviser_name": "William Merchad",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "Maven Wealth Management",
"firm_joining": "LPL Financial LLC",
"firm_city": "",
"firm_state": "",
"firm_full_name": "LPL Financial LLC",
"firm_full_url": "https://www.lpl.com",
"firm_contact_person": "",
"firm_date_two": "2022-09-23",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-22",
"adviser_name": "Adam James Kunkel",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "Edward Jones",
"firm_joining": "Commonwealth Financial Network",
"firm_city": "",
"firm_state": "",
"firm_full_name": "Fidelity/NFS/National Financial",
"firm_full_url": "http://www.commonwealth.com",
"firm_contact_person": "",
"firm_date_two": "2022-09-22",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-22",
"adviser_name": "Charles Richard Vietzen",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "First Command Brokerage Services, Inc.",
"firm_joining": "Stride Investments, LLC",
"firm_city": "",
"firm_state": "",
"firm_full_name": "TD Ameritrade",
"firm_full_url": "",
"firm_contact_person": "",
"firm_date_two": "2022-09-22",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-22",
"adviser_name": "Christine Guo",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "HSBC Securities (USA) Inc.",
"firm_joining": "Merrill Lynch, Pierce, Fenner & Smith Incorporated",
"firm_city": "",
"firm_state": "",
"firm_full_name": "Merrill Lynch/Bank of America",
"firm_full_url": "http://www.ml.com",
"firm_contact_person": "",
"firm_date_two": "2022-09-22",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-22",
"adviser_name": "Christopher A Peterson",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "Edward Jones",
"firm_joining": "Commonwealth Financial Network",
"firm_city": "",
"firm_state": "",
"firm_full_name": "Fidelity/NFS/National Financial",
"firm_full_url": "http://www.commonwealth.com",
"firm_contact_person": "",
"firm_date_two": "2022-09-22",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-22",
"adviser_name": "Colin Francis Igawa",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "J.P. Morgan Securities LLC",
"firm_joining": "Merrill Lynch, Pierce, Fenner & Smith Incorporated",
"firm_city": "",
"firm_state": "",
"firm_full_name": "Merrill Lynch/Bank of America",
"firm_full_url": "http://www.ml.com",
"firm_contact_person": "",
"firm_date_two": "2022-09-22",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-22",
"adviser_name": "DARLYN ALEXA ORELLANA",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "Wells Fargo Clearing Services, LLC",
"firm_joining": "City National Securities, Inc.",
"firm_city": "",
"firm_state": "",
"firm_full_name": "City National Bank",
"firm_full_url": "http://www.cnb.com",
"firm_contact_person": "",
"firm_date_two": "2022-09-22",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
},
{
"input_one": "1",
"date_entered": "2022-09-22",
"adviser_name": "ERIC DOUGLAS KAUFMAN",
"subgroup_name": "",
"firm_url": "",
"firm_phone": "",
"firm_email": "",
"aum_amount": null,
"rate": null,
"firm_leaving": "Lockton Investment Advisors, LLC",
"firm_joining": "Alliant Retirement Consulting",
"firm_city": "",
"firm_state": "",
"firm_full_name": "",
"firm_full_url": "",
"firm_contact_person": "",
"firm_date_two": "2022-09-22",
"data_source": "Discovery Data",
"data_source_url": "https://www.discoverydata.com/",
"sub_adviser_name": "",
"sub_contact_phone": "",
"sub_contact_email": "",
"sub_contact_url": "",
"sub_contact_datasource": "Discovery Data"
}
]
},
update
If you want to scrape all of the pages the you could calculate the total number of pages from the "TotalAdvisors" field in the data dictionary
api_url = 'https://aotm.in.bonhill.pbc.io/api/getAllAdvisorsListings/'
def start_requests(self)
yield scrapy.Request(url=api_url + "1")
def parse(self, response):
data = response.json()
date_iter = iter(data)
total_pages = next(data_iter)["TotalAdvisors"] // (len(data)-1)
for i in range(2, total_pages):
yield scrapy.Request(url=api_url + str(i), callback=parse_page)
yield {"data": data}
def parse_page(self, response):
yield {"data": response.json())

transpose and rename dataframes in a for() loop in r

I have a list of files with the following pattern: sampleid_samplename_counts.csv representing count matrix with cellname in rows and genes in columns.
I'm trying to generate count matrix from these files to load in the Seurat package that need cellnames in columns and gene in rows.
I succeed in obtaining the matrix with the following where x is a vectors of all the .csv filenames (I needed to create a new name for the object as I couldn't reassign "i" within the loop):
for (i in x) {
assign(paste0(i, ".counts"), t(read.table(i, sep = ",")))
}
But the obtained matrix does not have colnames (it's replaced with V1, V2, V3...)
Row 1 of each matrix contain the cellnames.
The following is creating the correct colnames:
colnames(file.counts) <- file.counts[1,]
file.counts <- file.counts[-1,]
But this does not work in a for() loop. How can I implement this in the initial or in another loop?
EDIT:
Here is what the original .csv file looks like after a simple read.table:
structure(list(V1 = c(NA, 121270371765165, 121270372580596, 121270373898541,
121270374395228, 121270374676403, 121270375926581, 121270376000796,
121270376290589, 121270378289958, 121270378621156, 121347513957787,
121347516024694, 121347517659934, 121347518125797, 121347519671644,
121347519760734, 121347519921075, 121347520489203, 121896195804531
), V2 = c("DPM1", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", ""), V3 = c("SCYL3", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""
), V4 = c("FGR", "", "", "", "", "", "", "", "", "1.0", "", "",
"", "", "", "", "", "", "", ""), V5 = c("CFH", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", ""),
V6 = c("FUCA2", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", ""), V7 = c("GCLC", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
""), V8 = c("NFYA", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", ""), V9 = c("NIPAL3", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", ""), V10 = c("LAS1L", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "")), row.names = c(NA,
20L), class = "data.frame")
And this is what looks like after the transpose t()
structure(c(NA, "DPM1", "SCYL3", "FGR", "CFH", "FUCA2", "GCLC",
"NFYA", "NIPAL3", "LAS1L", "ENPP4", "ANKIB1", "KRIT1", "RAD52",
"BAD", "LAP3", "CD99", "MAD1L1", "LASP1", "SNX11", "1.212704e+14",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "1.212704e+14", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "1.0", "", "", "", "1.212704e+14", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "1.212704e+14", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "1.212704e+14", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "1.0",
"", "1.212704e+14", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "1.212704e+14", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "1.212704e+14",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "1.212704e+14", "", "", "1.0", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", ""), .Dim = c(20L, 10L
), .Dimnames = list(c("V1", "V2", "V3", "V4", "V5", "V6", "V7",
"V8", "V9", "V10", "V11", "V12", "V13", "V14", "V15", "V16",
"V17", "V18", "V19", "V20"), NULL))
Perhaps this is helping...
library( data.table )
#build list of csv.gz files (I only kept two files in the dir)
files.to.read <- list.files( "./temp/GSE114725_RAW/", pattern = "\\.csv.gz$", full.names = TRUE )
#build a list of read data
L <- lapply( files.to.read, data.table::fread )
#transpose each list element
L.transposed <- lapply( L, data.table::transpose, keep.names = "gene", make.names = "V1" )
#set list names based on filenames
names(L.transposed) <- basename( files.to.read )
#write list elements to individual data.tables
for(i in 1:length(L.transposed)) assign(names(L.transposed)[i], L.transposed[[i]])

Wordpress filter "wp_get_nav_menu_items" filter shows only last child

I'm trying to add latest posts to my footer menu, so I used wp_get_nav_menu_items filter.
I'm going to skip the filter itself, just in the end of the function I get an array(2) of posts. I've added all the additional data to them (like menu_parent_id etc.). The problem is final menu contains only the last post. Even if I set $items[0] = $items[1]; so that both items are identical. It does not depend on a particular menu or post amount - always the last item only. I'll leave the code in quickly-reproducible format: just a filter and JSON-encoded items:
add_filter('wp_get_nav_menu_items', function ($items, $menu, $args) {
return json_decode('[{
"ID": 2576,
"post_author": "3",
"post_date": "2020-05-11 23:46:15",
"post_date_gmt": "2020-05-11 23:46:15",
"post_content": "",
"post_title": "Testr",
"post_excerpt": "",
"post_status": "publish",
"comment_status": "open",
"ping_status": "open",
"post_password": "",
"post_name": "testr",
"to_ping": "",
"pinged": "",
"post_modified": "2020-05-11 23:46:15",
"post_modified_gmt": "2020-05-11 23:46:15",
"post_content_filtered": "",
"post_parent": 0,
"guid": "http:\/\/mysite.local\/?p=2576",
"menu_order": 0,
"post_type": "post",
"post_mime_type": "",
"comment_count": "0",
"filter": "raw",
"db_id": 2576,
"object_id": "",
"menu_item_parent": "0",
"url": "http:\/\/mysite.local\/?p=2576",
"title": "Testr",
"target": "",
"classes": [],
"type": "",
"object": "",
"attr_title": "",
"description": "",
"xfn": "",
"status": ""
}, {
"ID": 3439,
"post_author": "3",
"post_date": "2020-05-11 23:28:49",
"post_date_gmt": "2020-05-11 23:28:49",
"post_content": "",
"post_title": "Test",
"post_excerpt": "",
"post_status": "publish",
"comment_status": "open",
"ping_status": "open",
"post_password": "",
"post_name": "test-2",
"to_ping": "",
"pinged": "",
"post_modified": "2020-05-11 23:28:49",
"post_modified_gmt": "2020-05-11 23:28:49",
"post_content_filtered": "",
"post_parent": 0,
"guid": "http:\/\/mysite.local\/?p=3439",
"menu_order": 0,
"post_type": "post",
"post_mime_type": "",
"comment_count": "0",
"filter": "raw",
"db_id": 3439,
"object_id": "",
"menu_item_parent": "0",
"url": "http:\/\/mysite.local\/?p=3439",
"title": "Test",
"target": "",
"classes": [],
"type": "",
"object": "",
"attr_title": "",
"description": "",
"xfn": "",
"status": ""
}]');
});
Did anyone have this issue before, please help, it drives me nuts :)
I figured out what was the problem. Each menu item must contain a menu_order property, or else wordpress sorting function will overwrite the same value over and over again showing only the last post.

Nuxt / Vue navigation menu issue with WP API V2

Im building a website with Nuxt and headless wordpress. All data is coming from wordpress api (wp-json).
I'm having an issue with navigation menu, with parent/child menu items.
On parent element click, every menu item that has children is triggered at once.
I need it to trigger only the one I click on.
Here's what happens #click right now
Heres what I have so far:
HTML:
<nav>
<div class="">
<!-- Triggers burger menu -->
<ul :class="isOpen ? 'block' : 'hidden'" class="sm:flex">
<!-- Loop through the parent navigation -->
<!-- Add click event to trigger dropdown menu -->
<li class="sm:mx-8 text-white cursor-pointer py-4 sm:py-0"
v-for="item in linksArray"
:key="item.ID"
#click="isOpen = !isOpen"
>
<!-- Insert the data from wp-json -->
<div class="">
<!-- Parent navigation elements -->
<div class="flex items-center">
<div class=""> {{item.title}} </div>
</div>
<!-- Child navigation here -->
<div>
<!-- Trigger show or hide child elements on click from above -->
<ul
v-show="isOpen"
class="sm:absolute bg-gray-800 rounded mt-4"
>
<!-- Loop through the child elements -->
<li class="text-white rounded hover:bg-gray-700 cursor-pointer py-2 px-2"
v-for="childItem in item.child_items"
:key="childItem.ID"
>
<!-- Insert the data for children from wp-json -->
<nuxt-link :to="childItem.url">
<div class="flex items-center">
<span class="title">
{{ childItem.title }}
</span>
</div>
</nuxt-link>
</li>
</ul>
</div>
</div>
</li>
</ul>
</div>
</nav>
Script:
<script>
export default {
name: "Navbar",
props: {
linksArray: {
type: Array
},
},
data() {
return {
isOpen: false,
};
},
watch: {
// Use to close the menu on route change
'$route'() {
this.isOpen = false;
},
}
};
</script>
wp-json menu response
{
"term_id": 2,
"name": "Main",
"slug": "main",
"term_group": 0,
"term_taxonomy_id": 2,
"taxonomy": "nav_menu",
"description": "",
"parent": 0,
"count": 14,
"filter": "raw",
"items": [
{
"ID": 319,
"post_author": "1",
"post_date": "2020-01-11 21:42:33",
"post_date_gmt": "2020-01-11 21:42:33",
"post_content": "",
"post_title": "Games",
"post_excerpt": "",
"post_status": "publish",
"comment_status": "closed",
"ping_status": "closed",
"post_password": "",
"post_name": "games",
"to_ping": "",
"pinged": "",
"post_modified": "2020-01-15 21:10:20",
"post_modified_gmt": "2020-01-15 21:10:20",
"post_content_filtered": "",
"post_parent": 0,
"guid": "http://localhost/?p=319",
"menu_order": 1,
"post_type": "nav_menu_item",
"post_mime_type": "",
"comment_count": "0",
"filter": "raw",
"db_id": 319,
"menu_item_parent": "0",
"object_id": "319",
"object": "custom",
"type": "custom",
"type_label": "Custom Link",
"title": "Games",
"url": "#",
"target": "",
"attr_title": "",
"description": "",
"classes": [],
"xfn": "",
"logo": {},
"child_items": [
{
"ID": 321,
"post_author": "1",
"post_date": "2020-01-11 21:42:33",
"post_date_gmt": "2020-01-11 21:42:33",
"post_content": "",
"post_title": "Dota 2",
"post_excerpt": "",
"post_status": "publish",
"comment_status": "closed",
"ping_status": "closed",
"post_password": "",
"post_name": "dota-2",
"to_ping": "",
"pinged": "",
"post_modified": "2020-01-15 21:10:20",
"post_modified_gmt": "2020-01-15 21:10:20",
"post_content_filtered": "",
"post_parent": 0,
"guid": "http://localhost/?p=321",
"menu_order": 2,
"post_type": "nav_menu_item",
"post_mime_type": "",
"comment_count": "0",
"filter": "raw",
"db_id": 321,
"menu_item_parent": "319",
"object_id": "301",
"object": "games",
"type": "post_type",
"type_label": "Game",
"url": "http://localhost/games/dota-2/",
"title": "Dota 2",
"target": "",
"attr_title": "",
"description": "",
"classes": [
""
],
"xfn": "",
"logo": {},
"slug": "dota-2"
},
{
"ID": 322,
"post_author": "1",
"post_date": "2020-01-11 21:42:33",
"post_date_gmt": "2020-01-11 21:42:33",
"post_content": "",
"post_title": "Overwatch",
"post_excerpt": "",
"post_status": "publish",
"comment_status": "closed",
"ping_status": "closed",
"post_password": "",
"post_name": "overwatch",
"to_ping": "",
"pinged": "",
"post_modified": "2020-01-15 21:10:20",
"post_modified_gmt": "2020-01-15 21:10:20",
"post_content_filtered": "",
"post_parent": 0,
"guid": "http://localhost/?p=322",
"menu_order": 3,
"post_type": "nav_menu_item",
"post_mime_type": "",
"comment_count": "0",
"filter": "raw",
"db_id": 322,
"menu_item_parent": "319",
"object_id": "264",
"object": "games",
"type": "post_type",
"type_label": "Game",
"url": "http://localhost/games/overwatch/",
"title": "Overwatch",
"target": "",
"attr_title": "",
"description": "",
"classes": [
""
],
"xfn": "",
"logo": {},
"slug": "overwatch"
},
{},
{},
{}
]
},
{
"ID": 320,
"post_author": "1",
"post_date": "2020-01-11 21:42:33",
"post_date_gmt": "2020-01-11 21:42:33",
"post_content": "",
"post_title": "Gambling",
"post_excerpt": "",
"post_status": "publish",
"comment_status": "closed",
"ping_status": "closed",
"post_password": "",
"post_name": "gambling",
"to_ping": "",
"pinged": "",
"post_modified": "2020-01-15 21:10:20",
"post_modified_gmt": "2020-01-15 21:10:20",
"post_content_filtered": "",
"post_parent": 0,
"guid": "http://localhost/?p=320",
"menu_order": 7,
"post_type": "nav_menu_item",
"post_mime_type": "",
"comment_count": "0",
"filter": "raw",
"db_id": 320,
"menu_item_parent": "0",
"object_id": "320",
"object": "custom",
"type": "custom",
"type_label": "Custom Link",
"title": "Gambling",
"url": "#",
"target": "",
"attr_title": "",
"description": "",
"classes": [
""
],
"xfn": "",
"logo": {},
"child_items": [
{
"ID": 336,
"post_author": "1",
"post_date": "2020-01-12 00:46:53",
"post_date_gmt": "2020-01-12 00:46:53",
"post_content": "",
"post_title": "CSGO Gambling",
"post_excerpt": "",
"post_status": "publish",
"comment_status": "closed",
"ping_status": "closed",
"post_password": "",
"post_name": "csgo-gambling",
"to_ping": "",
"pinged": "",
"post_modified": "2020-01-15 21:10:20",
"post_modified_gmt": "2020-01-15 21:10:20",
"post_content_filtered": "",
"post_parent": 0,
"guid": "http://localhost/?p=336",
"menu_order": 8,
"post_type": "nav_menu_item",
"post_mime_type": "",
"comment_count": "0",
"filter": "raw",
"db_id": 336,
"menu_item_parent": "320",
"object_id": "336",
"object": "custom",
"type": "custom",
"type_label": "Custom Link",
"title": "CSGO Gambling",
"url": "/csgo/gambling",
"target": "",
"attr_title": "",
"description": "",
"classes": [
""
],
"xfn": "",
"logo": {}
}
]
},
{},
{},
{}
]
}
I'm new to development, and been stuck on this for over a week now.
Don't know where to look for answers. Found nothing on here or google.
Could you please point me at what I'm doing wrong or at the solution please.
Thanks!
In your code, all children are using the same variable to say if they should be shown or not. As a result, if this variable is true then all children will be show, and if it's false then all will be hidden.
You need track which menu items you want to show. Here is an example of how you could achieve this:
new Vue({
el: "#app",
data: {
menu: [{
title: "Main one",
children: ['child 1', 'child 2', 'child 3']
},
{
title: "Main two",
children: ['child 4', 'child 5', 'child 6']
},
{
title: "Main three",
children: ['child 7']
},
{
title: "Main four",
children: ['child 8', 'child 9']
}
],
openMenu: null
},
methods: {
showChildren(i) {
if (this.openMenu === i) this.openMenu = null
else this.openMenu = i
}
}
})
li {
margin: 8px;
padding: 8px;
background: pink;
cursor: pointer;
}
<div id="app">
<h2>menu:</h2>
<ul>
<li v-for="(nav, i) in menu" #click="showChildren(i)">
{{nav.title}}
<ul v-show="openMenu === i" v-for="child in nav.children">
<li>{{ child }}</li>
</ul>
</li>
</ul>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
Basically, this works by only showing the children if openMenu is the same as the parent items index within the array.
When you click the parent, it sends its index to a function function which checks if it's already open (openMenu is equal to the parents index), and if so changes openMenu to null to hide the children. Else it sets openMenu to the parent index, making v-show="openMenu === i" valid for that parent.

WooCommerce Order API always creates empty orders

Im playing around with Woo Commerce API (v3.4.4). I can get a product with:
curl -X GET \
'http://localhost/wp-json/wc/v2/products/7?oauth_consumer_key=ck_8cbe42fb09c04954a63994c22145270f27871dec&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1535381325&oauth_nonce=iApWJblA1A5&oauth_version=1.0&oauth_signature=9T1T43FvOpBzVBU+RQS90zMB/XM=' \
-H 'Cache-Control: no-cache' \
-H 'Postman-Token: bdb7f5c9-5719-4bcf-b4fc-38aed3bd5d08'
I get the response:
{
"id": 7,
"name": "Test product",
"slug": "test-product",
"permalink": "http://localhost/product/test-product/",
"date_created": "2018-08-22T15:25:26",
"date_created_gmt": "2018-08-22T15:25:26",
"date_modified": "2018-08-22T15:25:26",
"date_modified_gmt": "2018-08-22T15:25:26",
"type": "simple",
"status": "publish",
"featured": false,
"catalog_visibility": "visible",
"description": "<p>this is a test product</p>\n",
"short_description": "<p>the short desc</p>\n",
"sku": "",
"price": "9",
"regular_price": "10",
"sale_price": "9",
"date_on_sale_from": null,
"date_on_sale_from_gmt": null,
"date_on_sale_to": null,
"date_on_sale_to_gmt": null,
"price_html": "<del><span class=\"woocommerce-Price-amount amount\"><span class=\"woocommerce-Price-currencySymbol\">€</span>10.00</span></del> <ins><span class=\"woocommerce-Price-amount amount\"><span class=\"woocommerce-Price-currencySymbol\">€</span>9.00</span></ins>",
"on_sale": true,
"purchasable": true,
"total_sales": 3,
"virtual": false,
"downloadable": false,
"downloads": [],
"download_limit": -1,
"download_expiry": -1,
"external_url": "",
"button_text": "",
"tax_status": "taxable",
"tax_class": "",
"manage_stock": false,
"stock_quantity": null,
"in_stock": true,
"backorders": "no",
"backorders_allowed": false,
"backordered": false,
"sold_individually": false,
"weight": "",
"dimensions": {
"length": "",
"width": "",
"height": ""
},
"shipping_required": true,
"shipping_taxable": true,
"shipping_class": "",
"shipping_class_id": 0,
"reviews_allowed": true,
"average_rating": "0.00",
"rating_count": 0,
"related_ids": [
36,
41
],
"upsell_ids": [],
"cross_sell_ids": [],
"parent_id": 0,
"purchase_note": "",
"categories": [
{
"id": 15,
"name": "Uncategorized",
"slug": "uncategorized"
}
],
"tags": [],
"images": [
{
"id": 8,
"date_created": "2018-08-22T15:24:00",
"date_created_gmt": "2018-08-22T15:24:00",
"date_modified": "2018-08-22T15:24:00",
"date_modified_gmt": "2018-08-22T15:24:00",
"src": "http://localhost/wp-content/uploads/2018/08/sock.jpeg",
"name": "sock",
"alt": "",
"position": 0
}
],
"attributes": [
{
"id": 0,
"name": "size",
"position": 0,
"visible": true,
"variation": false,
"options": [
"small",
"medium",
"large"
]
}
],
"default_attributes": [],
"variations": [],
"grouped_products": [],
"menu_order": 0,
"meta_data": [],
"_links": {
"self": [
{
"href": "http://localhost/wp-json/wc/v2/products/7"
}
],
"collection": [
{
"href": "http://localhost/wp-json/wc/v2/products"
}
]
}
}
This works running the request using CURL on the command line, and running the request in Postman.
But now I try to create an order:
curl -X POST \
'http://localhost/wp-json/wc/v2/orders?oauth_consumer_key=ck_8cbe42fb09c04954a63994c22145270f27871dec&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1535382336&oauth_nonce=P8RWaD9DnZ9&oauth_version=1.0&oauth_signature=GFxtI7+gqbah5fu68gSdqL4V3fs=' \
-H 'Cache-Control: no-cache' \
-H 'Postman-Token: f17bec6a-c76b-4a6c-8797-1df9dac73f36' \
-d '{
"payment_method": "bacs",
"payment_method_title": "Direct Bank Transfer",
"set_paid": true,
"billing": {
"first_name": "John",
"last_name": "Doe",
"address_1": "969 Market",
"address_2": "",
"city": "San Francisco",
"state": "CA",
"postcode": "94103",
"country": "US",
"email": "john.doe#example.com",
"phone": "(555) 555-5555"
},
"shipping": {
"first_name": "John",
"last_name": "Doe",
"address_1": "969 Market",
"address_2": "",
"city": "San Francisco",
"state": "CA",
"postcode": "94103",
"country": "US"
},
"line_items": [
{
"product_id": 7,
"quantity": 1
}
],
"shipping_lines": [
{
"method_id": "flat_rate",
"method_title": "Flat Rate",
"total": 7
}
]
}'
When I run the above request with Postman, it creates an empty order and I get the response:
{
"id": 59,
"parent_id": 0,
"number": "59",
"order_key": "wc_order_5b8413f8ed585",
"created_via": "rest-api",
"version": "3.4.4",
"status": "pending",
"currency": "EUR",
"date_created": "2018-08-27T15:08:40",
"date_created_gmt": "2018-08-27T15:08:40",
"date_modified": "2018-08-27T15:08:41",
"date_modified_gmt": "2018-08-27T15:08:41",
"discount_total": "0.00",
"discount_tax": "0.00",
"shipping_total": "0.00",
"shipping_tax": "0.00",
"cart_tax": "0.00",
"total": "0.00",
"total_tax": "0.00",
"prices_include_tax": false,
"customer_id": 0,
"customer_ip_address": "",
"customer_user_agent": "",
"customer_note": "",
"billing": {
"first_name": "",
"last_name": "",
"company": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"postcode": "",
"country": "",
"email": "",
"phone": ""
},
"shipping": {
"first_name": "",
"last_name": "",
"company": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"postcode": "",
"country": ""
},
"payment_method": "",
"payment_method_title": "",
"transaction_id": "",
"date_paid": null,
"date_paid_gmt": null,
"date_completed": null,
"date_completed_gmt": null,
"cart_hash": "",
"meta_data": [],
"line_items": [],
"tax_lines": [],
"shipping_lines": [],
"fee_lines": [],
"coupon_lines": [],
"refunds": [],
"_links": {
"self": [
{
"href": "http://localhost/wp-json/wc/v2/orders/59"
}
],
"collection": [
{
"href": "http://localhost/wp-json/wc/v2/orders"
}
]
}
}
Bizarrely, when i run the EXACT same request with CURL on the command line, I get the response:
{"code":"woocommerce_rest_authentication_error","message":"Invalid signature - provided signature does not match.","data":{"status":401}}
If I run the request in Postman, but for "product_id" I use "this is a completely fake id" it still creates an empty order and responds with:
{
"id": 60,
"parent_id": 0,
"number": "60",
"order_key": "wc_order_5b84148e002da",
"created_via": "rest-api",
"version": "3.4.4",
"status": "pending",
"currency": "EUR",
"date_created": "2018-08-27T15:11:10",
"date_created_gmt": "2018-08-27T15:11:10",
"date_modified": "2018-08-27T15:11:10",
"date_modified_gmt": "2018-08-27T15:11:10",
"discount_total": "0.00",
"discount_tax": "0.00",
"shipping_total": "0.00",
"shipping_tax": "0.00",
"cart_tax": "0.00",
"total": "0.00",
"total_tax": "0.00",
"prices_include_tax": false,
"customer_id": 0,
"customer_ip_address": "",
"customer_user_agent": "",
"customer_note": "",
"billing": {
"first_name": "",
"last_name": "",
"company": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"postcode": "",
"country": "",
"email": "",
"phone": ""
},
"shipping": {
"first_name": "",
"last_name": "",
"company": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"postcode": "",
"country": ""
},
"payment_method": "",
"payment_method_title": "",
"transaction_id": "",
"date_paid": null,
"date_paid_gmt": null,
"date_completed": null,
"date_completed_gmt": null,
"cart_hash": "",
"meta_data": [],
"line_items": [],
"tax_lines": [],
"shipping_lines": [],
"fee_lines": [],
"coupon_lines": [],
"refunds": [],
"_links": {
"self": [
{
"href": "http://localhost/wp-json/wc/v2/orders/60"
}
],
"collection": [
{
"href": "http://localhost/wp-json/wc/v2/orders"
}
]
}
}
So I have a number of problems:
1/ No matter what product_id I use, the order that's created is always empty
2/ Even if I provide a fake product_id, an order is still created by Woo Commerce. Surely this is incorrect?
3/ Running the create order requests on the command line is giving different responses to Postman
I was missing:
-H 'Content-Type: application/json' \
from the request. I had this entered in Postman, but had not ticked the check box:

Resources