library(sell)
library(Rconnect)
library(tidyverse)
get_company <- function(id, ...) {
cw_get(paste0('/company/companies/', id),
list(
fields = 'id,identifier,
name,accountNumber'
))
}
get_projects <- function(company_id = NULL,
project_id = NULL, ...) {
cw_resp <- cw_get(paste0('/project/projects/', project_id),
list(
conditions = paste0('company/id = ', company_id),
fields = 'id,name,
billProducts,company,contact,description,
downpayment,estimatedEnd,estimatedExpenseRevenue
,estimatedHours,estimatedProductRevenue,
estimatedStart,
department,manager,opportunity,status'
))
jsonlite::flatten(
as.data.frame(
cw_resp[[1]]
)
)
}
z <- get_company(12288)
get_projects(project_id = 5716)
get_projects(company_id = 12288)
p<-get_company(id = 12288) %>%
select(id) %>%
get_projects(company_id = .) %>%
get_projects(project_id = .[2,]) %>%
select(opportunity.id) %>%
translate(cw_opp = .)
quote_items <- get_items()
get_sell(paste0('/api/quotes/', p$quoteNumber, '/versions'))
get_sell(paste0('/api/quotes/', p$id))
get_sell(paste0('/api/quoteTabs/', p$id, '/quoteItems'))
quote_nums <- get_quotes(fields = 'id,name,quoteNumber', trunc = FALSE)
get_sell(paste0('/api/quoteTabs/', quote_nums[10,]$id, '/quoteItems'), verbose = TRUE
)
sell_resp <- httr::GET(
paste0(base_url(), paste0('/api/quoteTabs/', quote_nums[10,]$id, '/quoteItems')),
sell_auth(),
httr::verbose()
)
sell_resp <- httr::GET(
paste0(base_url(), paste0('/api/quoteTabs/', quote_nums[10,]$id, '/quoteItems')),
sell_auth(),
httr::verbose()
)
# -------------------------------------------------------------------------
# Quote Customers
sell_resp <- httr::GET(
paste0(base_url(), paste0('/api/quotes/', quote_nums[50,]$id, '/customers')),
sell_auth(),
httr::verbose()
)
jsonlite::fromJSON(httr::content(sell_resp, 'text'))
# Quote Items
sell_resp <- httr::GET(
paste0(base_url(), paste0('/api/quoteItems')),
sell_auth(),
httr::verbose()
)
jsonlite::fromJSON(httr::content(sell_resp, 'text')) %>%
names()
select(1:75) %>% View
# Quotes
sell_resp <- httr::GET(
paste0(base_url(), paste0('/api/quotes/')),
sell_auth(),
query = list(
pageSize = 50,
page = 50
#condtions = "createDate > [2020-01-06T19:55:47.477Z]"
),
httr::verbose()
)
jsonlite::fromJSON(httr::content(sell_resp, 'text')) %>% View
# Quotes / id
sell_resp <- httr::GET(
paste0(base_url(), paste0('/api/quotes/', 'q637146363205360797kjTpOGt')),
sell_auth(),
httr::verbose()
)
quote_id_resp <- jsonlite::fromJSON(httr::content(sell_resp, 'text'))
# Quotes Tabs
quoteTabs <- httr::GET(
paste0(base_url(), paste0('/api/quoteTabs')),
sell_auth(),
query = list(
page = 20
),
httr::verbose()
)
tab_resp$quote$id <- jsonlite::fromJSON(httr::content(quoteTabs, 'text'))
tab_resp[1,] %>%
View
# first translate
p <- get_company(id = 12288) %>%
select(id) %>%
get_projects(company_id = .) %>%
get_projects(project_id = .[2,]) %>%
select(opportunity.id) %>%
translate(cw_opp = .)
# Choose by external project - reverse lookup
# Works by passing a quote id to quote tabs and looking up products by quote id
quoteTabs <- httr::GET(
paste0(base_url(), paste0('/api/quoteTabs')),
sell_auth(),
query = list(
# look up by quote id
conditions = paste0('quote/id = ', p$id)
),
httr::verbose()
)
tab_resp <- jsonlite::fromJSON(httr::content(quoteTabs, 'text'), flatten = TRUE)
tab_resp %>%
as_tibble() %>%
select(id)
View
tab_resp %>% str()
typeof(tab_resp)
# Quotes Tabs Items
sell_resp <- httr::GET(
paste0(base_url(), paste0('/api/quoteTabs/', tab_resp[1,]$id,'/quoteItems')),
sell_auth(),
query = list(
conditions = paste0('quote/id = ', p$id)
# includeFields = 'id,idQuote,approvalMarginMinimum,approvalPriceMinimum,
#basePrice,cost,costModifier,crmReference,cwAgreement,cwClass,
#etilizeProductId,etilizeSerializedAttributes,
#extendedCost,extendedPrice,extendedPriceConverted,
#externalQuoteNumber,externalReference,grossMargin,idQuoteTabs,
#isShowPrice,isSold,isTaxable,isTotalsIncluded,itemNotes,
#itemNumber,lineType,markup,netCost,overridePrice,
#overridePriceModifier,owner,packagePrice,packageQty,parentQuoteItem,
#poNumber,priceConverted,productCategory,productClass,productType,
#quantity,quosalDescription,quoteItemPrice,quoteName,
#quoteReadableId,recurringAmount,shortDescription,sortOrder,
#source,sourceManufacturerId,sourceManufacturerName,
#sourceVendorId,sourceVendorName,startingCost,taxquote/id,quoteTab/id'
),
httr::verbose()
)
# Format
quote_item_resp <- jsonlite::fromJSON(httr::content(sell_resp, 'text'),
flatten = TRUE) %>%
as_tibble
# Selector
quote_item_resp[1,] %>%
select(id,idQuote,approvalMarginMinimum,approvalPriceMinimum, basePrice,cost,costModifier,crmReference,cwAgreement,cwClass, etilizeProductId,etilizeSerializedAttributes, extendedCost,extendedPrice,extendedPriceConverted, externalQuoteNumber,externalReference,grossMargin,idQuoteTabs, isShowPrice,isSold,isTaxable,isTotalsIncluded, itemNumber,lineType,markup,netCost,overridePrice, overridePriceModifier,owner,packagePrice,packageQty,parentQuoteItem, poNumber,priceConverted,productCategory,productClass,productType, quantity,quosalDescription,quoteItemPrice,quoteName, quoteReadableId,recurringAmount,shortDescription,sortOrder, source,sourceManufacturerId,sourceManufacturerName, sourceVendorId,sourceVendorName,startingCost,quoteTab.id) %>%
as_tibble %>%
str()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.