Bandcamp API sales data retrieval feature

Looking for assistance with a call to the Bandcamp API. Every time I request /http://bandcamp.com/api/sales/1/sales_report/, I receive this message in the response:

/"error_message":"JSON parse error: 757: unexpected token at ''/

Below is an unsuccessful example call:

var artistId = <my band_id>
var memberArtistId=''; // optional - only applies to label accounts
var start_time='2018-01-01 23:59:59';
var end_time='2020-01-01 23:59:59'; // optional
var format='json'; // optional
 
 var objParams = {
  "band_id": artistId,
  "member_band_id": memberArtistId,
  "start_time": start_time, 
  "end_time": end_time,
  "format": format
}
   
var parameters = {
  headers:{Authorization:'Bearer '+access_token},
  method:"post",      
  payload:objParams,
  muteHttpExceptions:true
 };

var response = UrlFetchApp.fetch(token_url,parameters).getContentText(); 

Encountering the same issue when using the sample code at /https://bandcamp.com/developer/sales/. It looks like there might be an issue with escaping or encapsulating characters correctly within the JSON object of the request.

If someone could provide a successful example, that would be much appreciated so I can identify where the problem lies. A curl command would be great, but any format will do. Currently working with Google Apps Script (JavaScript).

Thanks in advance!

Answer №1

It appears that in your specific scenario, the request body may need to be sent as a JSON value. Would you consider making the following modification?

From:

var parameters = {
  headers:{Authorization:'Bearer '+access_token},
  method:"post",      
  payload:objParams,
  muteHttpExceptions:true
 };

To:

var parameters = {
  headers: {Authorization: 'Bearer ' + access_token},
  method: "post",
  payload: JSON.stringify(objParams),
  contentType: "application/json",
  muteHttpExceptions: true
};

Note:

  • This alteration assumes that both your access_token and objParams are accurate. Please verify their correctness before implementation.

Reference:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Converting JSON to CSV in Python 3

In my Python program, I am dealing with a JSON dict that I want to convert into a CSV file. The structure of my data and code snippet is presented below: import csv import json x = { "success": 1, "return": { "variable_id": { "var1": "val1", ...

The act of initiating a click on a radio button involves evaluating conditions prior to toggling

Apologies for the slightly ambiguous title, let me provide a clearer explanation. I have created a codepen to demonstrate an issue that I am facing. You can view it here. In my codepen, I have two toggle buttons labeled "Male" and "Female" for simplicity. ...

Modifying CSS using jQuery in a PHP While Loop

I've been racking my brain trying to solve this issue, experimenting with different approaches but so far, no luck. Question: How can I dynamically change the color of a specific div within a PHP while loop using jQuery after receiving an AJAX respon ...

producing valid JSON output with added customized tags

After running my PHP code, I noticed that it generates valid JSON output for a specific piece of code: echo json_encode($player,JSON_FORCE_OBJECT); The output looks like this: { "0": { "0": "1.g", "1": "d4", "2": "3.g", "3": "8.g", ...

Set up a WhatsApp web bot on the Heroku platform

I am currently in the process of developing a WhatsApp bot using the node library whatsapp-web.js. Once I finish writing the script, it appears something like this (I have provided an overview of the original script) - index.js const {Client, LocalAuth, M ...

Converting units to rem dynamically in CSS: a comprehensive guide

Hey there, I'm currently trying to dynamically convert units into rem in CSS and facing some issues. I have set the root font-size as 23px The current font-size is 16px The expected result should be 16 / 23 => 0.695rem Question: I am looking for ...

js TouchEvent: When performing a pinch gesture with two fingers and lifting one of them up, how can you determine which finger was lifted?

I am currently working on a challenging touching gesture and have encountered the following issue: let cachedStartTouches: TouchList; let cachedMoveTouches: TouchList; function onStart(ev: TouchEvent) { // length equals 2 when two fingers pinch start ...

Using jQuery to swap out sections of a HTML tag

Similar Question: Use of jQuery for Modifying an HTML Tag? After extensive research, I have not come across a solution that fits my specific requirements. My objective is to replace a part of an HTML tag without completely replacing the entire tag. To ...

the pause in execution before my function redirects to a different route

Currently, I am developing a page using nodeJs with express which is supposed to display a table. However, I encountered an issue with my variable "allMusique" that contains the data for my page. When trying to access it initially, there seems to be an err ...

troubleshooting Axios errors in React applications

User/Project.js: import React, { useState, useEffect } from "react"; import Axios from "axios"; const Project = () => { const [projectName, setprojectName] = useState(""); const [projectDescription, setprojectDescriptio ...

TypeScript maintains the reference and preserves the equality of two objects

Retrieve the last element of an array, make changes to the object that received the value, but inadvertently modify the original last position as well, resulting in both objects being identical. const lunchVisit = plannedVisits[plannedVisits.length ...

Transforming Uint8Array into BigInt using Javascript

I've come across 3 different ways to convert a Uint8Array to BigInt, but each method seems to produce varying results. Can someone clarify which approach is correct and recommended? Utilizing the bigint-conversion library. The function bigintConversi ...

how to name a collection variable in MongoDB shell using JavaScript

When using the mongo shell with JavaScript, is it possible to dynamically set the collection name in order to work with multiple collections? db.collection.insert() ...

Prevent clicking through slides on React by disabling the Swiper feature

Is there a way to handle the global document click event (using React hook useClickAway) so that it still fires even when clicking on a slide? For example, think of a circle in the header like an avatar dropdown - when you click on it, a menu pops up. Th ...

Load Bootstrap CSS file externally on a website dynamically

Although my knowledge of JavaScript is limited, I am the recipient of a small web application from a friend that is being utilized by multiple companies. As each company requires specific modifications in the appearance and CSS of certain webpages, it can ...

What is the best way to retrieve ul li values using AngularJS?

I am looking to extract the content of li elements within a ul element in an AngularJS controller and save them into an array. Sample HTML Code: <ul id="list" my-directive> <li>A</li> <li>B</li> <li>C ...

Having issues with npm python-shell integration within electron framework

I'm currently attempting to establish a connection between a python script and an Electron app by utilizing the npm's python-shell package. The requirement is for the script to be executed whenever a button is clicked. So, let's assume my d ...

The art of perfect alignment: Mastering the positioning of Material-UI Grid

This issue has been resolved Hey there, I'm currently working on a React App with Material-UI and I'm trying to center a Grid item that includes a Card along with two additional Grid items. Below is the relevant code snippet. Although the Cards ...

What is the best way to add a border around an image along with a button using VueJS?

I am struggling to link a button and an image in VueJS to display a border around the picture. While I can successfully display the border on the button, I am unsure how to extend it to the image as well. Vue.component('my-button', 'my-img& ...

Guide to Deserializing a JSON Object in Windows Phone 8.1

Can anyone help me with an issue I'm facing? When I deserialize a JSON object and bind it to my properties, the properties show null values. Here is my code: string s = "{\"response\":{\"status\":\"fail\",\"content& ...