# Last.FM

## Get receipt data from last.fm

<mark style="color:blue;">`GET`</mark> `https://api.stefdp.com/receiptData/last.fm`

#### Query Parameters

| Name                                   | Type   | Description                                                                                 |
| -------------------------------------- | ------ | ------------------------------------------------------------------------------------------- |
| user<mark style="color:red;">\*</mark> | String | Last.FM username                                                                            |
| trackCount                             | Number | Amount of tracks to display                                                                 |
| period                                 | String | The period to fetch. Supports `overall`, `7day`, `1month`, `3month`, `6month` and `12month` |
| cardHolder                             | String | The name to display on top and as card holder                                               |
| order                                  | Number | The number to display as order number                                                       |
| authCode                               | Number | The number to display ad auth code                                                          |
| thanks                                 | String | The text to display as footer                                                               |

{% tabs %}
{% tab title="200: OK The receipt data" %}
{% tabs %}
{% tab title="Body" %}
{% hint style="info" %}
if the track duration is `0` or an empty string (`""`), means that [last.fm](https://last.fm) doesn't have the duration of the track
{% endhint %}

```json
{
  "tracksData": [
    {
      "name": "running",
      "artist": {
        "url": "https://www.last.fm/music/Camylio",
        "name": "Camylio"
      },
      "url": "https://www.last.fm/music/Camylio/_/running",
      "duration": "",
      "durationSeconds": 0,
      "totalDuration": "",
      "totalDurationSeconds": 0,
      "playCount": 726
    },
    {
      "name": "Trust Me Mate",
      "artist": {
        "url": "https://www.last.fm/music/Dean+Lewis",
        "name": "Dean Lewis"
      },
      "url": "https://www.last.fm/music/Dean+Lewis/_/Trust+Me+Mate",
      "duration": "02:58",
      "durationSeconds": 178,
      "totalDuration": "01:08:14:16",
      "totalDurationSeconds": 116056,
      "playCount": 652
    },
    {
      "name": "strangers",
      "artist": {
        "url": "https://www.last.fm/music/Camylio",
        "name": "Camylio"
      },
      "url": "https://www.last.fm/music/Camylio/_/strangers",
      "duration": "02:52",
      "durationSeconds": 172,
      "totalDuration": "02:37:40",
      "totalDurationSeconds": 9460,
      "playCount": 55
    },
    {
      "name": "unwanted",
      "artist": {
        "url": "https://www.last.fm/music/Camylio",
        "name": "Camylio"
      },
      "url": "https://www.last.fm/music/Camylio/_/unwanted",
      "duration": "02:38",
      "durationSeconds": 158,
      "totalDuration": "02:22:12",
      "totalDurationSeconds": 8532,
      "playCount": 54
    },
    {
      "name": "i'm sorry",
      "artist": {
        "url": "https://www.last.fm/music/Camylio",
        "name": "Camylio"
      },
      "url": "https://www.last.fm/music/Camylio/_/i%27m+sorry",
      "duration": "03:13",
      "durationSeconds": 193,
      "totalDuration": "02:47:16",
      "totalDurationSeconds": 10036,
      "playCount": 52
    },
    {
      "name": "amnesia",
      "artist": {
        "url": "https://www.last.fm/music/Camylio",
        "name": "Camylio"
      },
      "url": "https://www.last.fm/music/Camylio/_/amnesia",
      "duration": "02:52",
      "durationSeconds": 172,
      "totalDuration": "01:20:16",
      "totalDurationSeconds": 4816,
      "playCount": 28
    },
    {
      "name": "hurting me, hurting you",
      "artist": {
        "url": "https://www.last.fm/music/Camylio",
        "name": "Camylio"
      },
      "url": "https://www.last.fm/music/Camylio/_/hurting+me,+hurting+you",
      "duration": "",
      "durationSeconds": 0,
      "totalDuration": "",
      "totalDurationSeconds": 0,
      "playCount": 27
    },
    {
      "name": "Monsters",
      "artist": {
        "url": "https://www.last.fm/music/Camylio",
        "name": "Camylio"
      },
      "url": "https://www.last.fm/music/Camylio/_/Monsters",
      "duration": "02:53",
      "durationSeconds": 173,
      "totalDuration": "01:17:51",
      "totalDurationSeconds": 4671,
      "playCount": 27
    },
    {
      "name": "better love",
      "artist": {
        "url": "https://www.last.fm/music/Camylio",
        "name": "Camylio"
      },
      "url": "https://www.last.fm/music/Camylio/_/better+love",
      "duration": "",
      "durationSeconds": 0,
      "totalDuration": "",
      "totalDurationSeconds": 0,
      "playCount": 26
    },
    {
      "name": "I Tried",
      "artist": {
        "url": "https://www.last.fm/music/Camylio",
        "name": "Camylio"
      },
      "url": "https://www.last.fm/music/Camylio/_/I+Tried",
      "duration": "02:40",
      "durationSeconds": 160,
      "totalDuration": "01:09:20",
      "totalDurationSeconds": 4160,
      "playCount": 26
    },
    {
      "name": "see you soon",
      "artist": {
        "url": "https://www.last.fm/music/Camylio",
        "name": "Camylio"
      },
      "url": "https://www.last.fm/music/Camylio/_/see+you+soon",
      "duration": "",
      "durationSeconds": 0,
      "totalDuration": "",
      "totalDurationSeconds": 0,
      "playCount": 25
    },
    {
      "name": "leaving home",
      "artist": {
        "url": "https://www.last.fm/music/Camylio",
        "name": "Camylio"
      },
      "url": "https://www.last.fm/music/Camylio/_/leaving+home",
      "duration": "02:53",
      "durationSeconds": 173,
      "totalDuration": "01:09:12",
      "totalDurationSeconds": 4152,
      "playCount": 24
    },
    {
      "name": "love and hate",
      "artist": {
        "url": "https://www.last.fm/music/Camylio",
        "name": "Camylio"
      },
      "url": "https://www.last.fm/music/Camylio/_/love+and+hate",
      "duration": "03:10",
      "durationSeconds": 190,
      "totalDuration": "01:16:00",
      "totalDurationSeconds": 4560,
      "playCount": 24
    },
    {
      "name": "sometimes",
      "artist": {
        "url": "https://www.last.fm/music/Camylio",
        "name": "Camylio"
      },
      "url": "https://www.last.fm/music/Camylio/_/sometimes",
      "duration": "02:36",
      "durationSeconds": 156,
      "totalDuration": "01:02:24",
      "totalDurationSeconds": 3744,
      "playCount": 24
    },
    {
      "name": "How Do I Say Goodbye",
      "artist": {
        "url": "https://www.last.fm/music/Dean+Lewis",
        "name": "Dean Lewis"
      },
      "url": "https://www.last.fm/music/Dean+Lewis/_/How+Do+I+Say+Goodbye",
      "duration": "02:43",
      "durationSeconds": 163,
      "totalDuration": "51:37",
      "totalDurationSeconds": 3097,
      "playCount": 19
    },
    {
      "name": "Used To Love (with Dean Lewis)",
      "artist": {
        "url": "https://www.last.fm/music/Martin+Garrix",
        "name": "Martin Garrix"
      },
      "url": "https://www.last.fm/music/Martin+Garrix/_/Used+To+Love+(with+Dean+Lewis)",
      "duration": "",
      "durationSeconds": 0,
      "totalDuration": "",
      "totalDurationSeconds": 0,
      "playCount": 19
    },
    {
      "name": "Lose My Mind",
      "artist": {
        "url": "https://www.last.fm/music/Dean+Lewis",
        "name": "Dean Lewis"
      },
      "url": "https://www.last.fm/music/Dean+Lewis/_/Lose+My+Mind",
      "duration": "03:12",
      "durationSeconds": 192,
      "totalDuration": "54:24",
      "totalDurationSeconds": 3264,
      "playCount": 17
    },
    {
      "name": "Small Disasters",
      "artist": {
        "url": "https://www.last.fm/music/Dean+Lewis",
        "name": "Dean Lewis"
      },
      "url": "https://www.last.fm/music/Dean+Lewis/_/Small+Disasters",
      "duration": "03:18",
      "durationSeconds": 198,
      "totalDuration": "56:06",
      "totalDurationSeconds": 3366,
      "playCount": 17
    },
    {
      "name": "Lost Without You (with Dean Lewis)",
      "artist": {
        "url": "https://www.last.fm/music/Kygo",
        "name": "Kygo"
      },
      "url": "https://www.last.fm/music/Kygo/_/Lost+Without+You+(with+Dean+Lewis)",
      "duration": "03:23",
      "durationSeconds": 203,
      "totalDuration": "57:31",
      "totalDurationSeconds": 3451,
      "playCount": 17
    },
    {
      "name": "Half a Man",
      "artist": {
        "url": "https://www.last.fm/music/Dean+Lewis",
        "name": "Dean Lewis"
      },
      "url": "https://www.last.fm/music/Dean+Lewis/_/Half+a+Man",
      "duration": "02:59",
      "durationSeconds": 179,
      "totalDuration": "47:44",
      "totalDurationSeconds": 2864,
      "playCount": 16
    }
  ],
  "totalTracks": 124,
  "tracks": 20,
  "total": {
    "amount": 2467,
    "duration": "03:05:52:28",
    "timeSeconds": 280348
  },
  "subTotal": {
    "amount": 1875,
    "duration": "02:03:43:49",
    "timeSeconds": 186229
  },
  "year": 2023,
  "period": "in the last month",
  "dateGenerated": "Wednesday, 11 October 2023",
  "orderNumber": 6010,
  "username": "stef_dp",
  "cardHolder": "stef_dp",
  "authCode": 721532,
  "thanks": "Thank you for using stef's website"
}
```

{% endtab %}

{% tab title="Headers" %}

```http
Content-Type: application/json
```

{% endtab %}

{% tab title="Schema" %}

```json
{
  "type": "object",
  "properties": {
    "tracksData": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "The name of the song"
          },
          "artist": {
            "type": "object",
            "properties": {
              "url": {
                "type": "string",
                "description": "A link to the artist's last.fm profile"
              },
              "name": {
                "type": "string",
                "description": "The name of the artist of the song"
              }
            }
          },
          "url": {
            "type": "string",
            "description": "A link to the song on last.fm"
          },
          "duration": {
            "type": "string",
            "description": "Song duration, formatted as hh:mm:ss (if there days or more they get added too, example: dd:hh:mm:ss)"
          },
          "durationSeconds": {
            "type": "number",
            "description": "The song duration in seconds"
          },
          "totalDuration": {
            "type": "string",
            "description": "Song duration multiplied by the playCount, same format as duration field"
          },
          "totalDurationSeconds": {
            "type": "number",
            "description": "The song duration in seconds multiplied by the playCount"
          },
          "playCount": {
            "type": "number",
            "description": "Amount of times the user has played the track"
          }
        }
      },
      "description": "Array of Last.FM track objects"
    },
    "totalTracks": {
      "type": "number",
      "description": "The amount of tracks selected"
    },
    "tracks": {
      "type": "string",
      "description": "The selected amount of tracks to show"
    },
    "total": {
      "type": "object",
      "properties": {
        "amount": {
          "type": "number",
          "description": "Sum of the playCount of all the tracks the user has listened to"
        },
        "duration": {
          "type": "string",
          "description": "Sum of the duration of all the tracks the user has listened to (same format as track duration)"
        },
        "timeSeconds": {
          "type": "number",
          "description": "Sum of the duration in seconds of all the tracks the user has listened to"
        }
      }
    },
    "subTotal": {
      "type": "object",
      "properties": {
        "amount": {
          "type": "number",
          "description": "Sum of the playCount of the selected amount of tracks"
        },
        "duration": {
          "type": "string",
          "description": "Sum of the duration of the selected amount of tracks (same format as track duration)"
        },
        "timeSeconds": {
          "type": "number",
          "description": "Sum of the duration in seconds of the selected amount of tracks"
        }
      }
    },
    "year": {
      "type": "number",
      "description": "Current year"
    },
    "period": {
      "type": "string",
      "description": "The selected period"
    },
    "dateGenerated": {
      "type": "string",
      "description": "The date when the receipt data was generated"
    },
    "orderNumber": {
      "type": "number",
      "description": "The order number to show on the receipt (generated randomly if not given through query)"
    },
    "username": {
      "type": "string",
      "description": "The Last.FM username of the user to fetch the receipt of"
    },
    "cardHolder": {
      "type": "string",
      "description": "The username to show next to the card holder field and on top"
    },
    "authCode": {
      "type": "number",
      "description": "The auth code of the user (generated randomly if not given through query)"
    },
    "thanks": {
      "type": "string",
      "description": "The footer"
    }
  }
}
```

{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="403: Forbidden The user has been banned" %}
{% tabs %}
{% tab title="Body" %}

```json
{
    "code": 2000,
    "message": "This user is banned from the site"
}
```

{% endtab %}

{% tab title="Headers" %}

```http
Content-Type: application/json
```

{% endtab %}

{% tab title="Schema" %}

```json
{
  "type": "object",
  "properties": {
    "code": {
      "type": "number",
      "description": "The code of the error"
    },
    "message": {
      "type": "string",
      "description": "A description of the error"
    }
  }
}
```

{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="500: Internal Server Error Something went wrong in the request to last.fm" %}
{% tabs %}
{% tab title="Body" %}

```json
{
    "code": 500,
    "message": "Something went wrong"
}
```

{% endtab %}

{% tab title="Headers" %}

```http
Content-Type: application/json
```

{% endtab %}

{% tab title="Schema" %}

```json
{
  "type": "object",
  "properties": {
    "code": {
      "type": "number",
      "description": "The code of the error"
    },
    "message": {
      "type": "string",
      "description": "A description of the error"
    }
  }
}
```

{% endtab %}
{% endtabs %}
{% endtab %}
{% endtabs %}

## Examples

{% tabs %}
{% tab title="cURL" %}

```sh
curl 'https://api.stefdp.com/receiptData/last.fm?user=stef_dp'
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
fetch('https://api.stefdp.com/receiptData/last.fm?user=stef_dp')
```

### Try it out!

{% @runkit/embed content="const user = 'stef\_dp', // your last.fm username, required
trackCount = '', // amount of tracks to display, defaults to "20"
period = '', // the period to fetch, defaults to "1month"
cardHolder = '', // the name to show on top and next to card holder value, defaults to the last.fm username
order = '', // number to show next to order number, defaults to a random 4 digit number
authCode = '', // number to show next to auth ode, defaults to a random 6 digit number
thanks = '' // text to show on bottom, defaults to "Thank you for using stef's website"

fetch(`https://api.stefdp.lol/receiptData/last.fm?user=${user}&trackCount=${trackCount}&period=${period}&cardHolder=${cardHolder}&order=${order}&authCode=${authCode}&thanks=${thanks}`).then(res => res.json()).then(console.log)
" nodeVersion="18.x.x" %}
{% endtab %}
{% endtabs %}
