0

I'm trying to use the Trade Me API (https://developer.trademe.co.nz/api-reference/selling-methods/list-an-item) to list an item for sale, but I'm getting an error message that says "Please enter a description" and "Please select the payment methods you will accept" and "Please select a shipping option."

I've double-checked that I'm including a description and that I've selected payment and shipping options, but I'm still getting this error. Here is my code:

# Install and load required packages
library(httr)
library(jsonlite)
library(tidyverse)

# Set API keys and secrets
consumer_key <- "my_key"
consumer_secret <- "my_secret"
access_token <- "my_token"
access_secret <- "my_token_secret"

# Set API endpoint URL
api_url <- "https://api.tmsandbox.co.nz/v1/Selling.json"

auth <- paste0(
  "OAuth oauth_consumer_key=", consumer_key,
  ",oauth_token=", access_token,
  ",oauth_signature_method=PLAINTEXT",
  ",oauth_signature=", consumer_secret, "%26", access_secret)

headers <- c('Authorization' = auth,
             'Content-Type' = 'application/json' # set the content type to JSON
             )  

# Set request body
body <- list(
  Category = "3849",
  Title = "Arty surprise",
  Description = list(
    Paragraph = "All true art lovers will buy this"
  ), 
  StartPrice = 7.0,
  BuyNowPrice = 9.0,
  Duration = 7.0,
  Pickup = 3,
  IsBrandNew = 'false',
  ShippingOptions = list(
    ShippingOption = list(
      Type = "Undecided" 
    )
  ),
  PaymentMethods = list(
    PaymentMethod = c("Cash", "CreditCard") 
  )
)

# Make POST request to API
response <- POST(
  url = api_url,
  body = body,
  add_headers(headers),
  encode = "json" 
)

# Retrieve the response content as a list object
response_data <- httr::content(response)

print(response_data)

Here is the error message I'm getting:

$Success
[1] FALSE

$Description
[1] "Please enter a description\r\nPlease select the payment methods you will accept.\r\nPlease select a shipping option."

Any help with this issue would be greatly appreciated!

versb
  • 91
  • 5

0 Answers0