library(httr) library(openssl) URL url <-…
- User
library(httr) library(openssl)
URL
url <- "https://586038.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=3612&deploy=1"
JSON body
body <- list( query = "Select LastName from CONTACT where FirstName='Livio'" )
Authentication credentials
consumer_key <- "200b3bacd548c08046abbdcb50b5374445f8081176e0fe1ca28a2d80918686d1" consumer_secret <- "91a127b1123f622bd951c9a52f6c3609449fbb05101fd2f5df1a13ca105c2932" token_key <- "58a0591cde917e0782c4f6d38a20dab26a1c544b65440d98bb15989c637c5a73" token_secret <- "4b58a072c9462a5288c2a0e866b31ddc0c3714f94b5e2e323ce5297ac3139a63"
Generating OAuth signature
method <- "POST" timestamp <- as.character(as.integer(Sys.time())) nonce <- charToRaw(paste0(sample(letters, 32, replace = TRUE), collapse = "")) signature_base <- paste0(method, "&", URLencode(url), "&", URLencode(paste("deploy=1", paste0("oauth_consumer_key=", consumer_key, "&", "oauth_nonce=", rawToChar(nonce), "&", "oauth_signature_method=HMAC-SHA256&", "oauth_timestamp=", timestamp, "&", "oauth_token=", token_key, "&", "oauth_version=1.0", sep = "")), "&", URLencode(paste("query=", body$query, sep = "")))
signature_key <- URLencode(paste(consumer_secret, "&", token_secret, sep = ""), reserved = TRUE) signature <- charToRaw(sha256_hmac(signature_base, signature_key))
signature <- paste(rawToChar(signature), collapse = "") oauth_header <- paste("OAuth ", paste(paste0('oauth_consumer_key="', consumer_key, '"'), paste0('oauth_nonce="', rawToChar(nonce), '"'), paste0('oauth_signature="', signature, '"'), paste0('oauth_signature_method="HMAC-SHA256"'), paste0('oauth_timestamp="', timestamp, '"'), paste0('oauth_token="', token_key, '"'), paste0('oauth_version="1.0"'), sep = ", "), sep = "")
Sending POST request with JSON body and OAuth authentication header
response <- POST(url, body = body, encode = "json", add_headers(Authorization = oauth_header))
Print response
print(content(response))
- Assistant
- User
Error in HMAC(signature_base_raw, key = signature_key, algo = "sha256"): could not find function "HMAC" Traceback:
- Assistant