Steps to reproduce error: https://blog.getpostman.com/2016/11/09/generate-spotify-playlists-using-a-postman-collection/
I have been following the above tutorial for sending an API request to Spotify. I am successful in getting the authorisation codes, however, Postman has an error when running the collection for Spotify despite following the tutorial correctly.
From looking at the console, there is an error at the line shown below:
Error message reads
XPath runner/search already exists
Error running scripts: JSONError | Unexpected token u in JSON at position 0
Error executing pre-request scripts for Get Artist Top Tracks: JSONError: Unexpected token u in JSON at position 0
Two others experienced the issue but they were never replied to. Any ideas how to fix this? I am new to API requests so any help would be muchly appreciated!
Pre request script for auth:
var client_credentials = (environment.client_id + ':' + environment.client_secret).encodeBase64();
postman.setEnvironmentVariable("client_credentials", client_credentials);
environment.cloned_environment && (delete environment.cloned_environment);
var environmentObjClone = _.cloneDeep(environment);
postman.setEnvironmentVariable("cloned_environment", JSON.stringify(environmentObjClone));
Pre-Request Script for artist:
try {
var artist_id = _.sample(JSON.parse(environment.artists));
postman.setEnvironmentVariable("id", artist_id);
}
catch (e) {
console.log(e);
throw false;
}
JSON:
{
"id": "b2b45667-7ec9-4d5d-9e38-c976d181c2bd",
"name": "SpotifyGenV1.template1",
"values": [
{
"key": "artists",
"value": "[“2DaxqgrOhkeH0fpeiQq2f4”, “2ooIqOf4X2uz4mMptXCtie”]",
"enabled": true
},
{
"key": "N",
"value": "5",
"enabled": true
},
{
"key": "user_id",
"value": "marcz2007",
"enabled": true
},
{
"key": "country_code",
"value": "US",
"enabled": true
},
{
"key": "client_id",
"value": "744a1316f9374a27b7ec9bc7eabb0f92",
"enabled": true
},
{
"key": "client_secret",
"value": "---secret--",
"enabled": true
},
{
"key": "refresh_token",
"value": "AQAf0rvuNBo23wiIiyWQRfavFvx7JdTjvGYLufOBAM1ABtvXWvfqqo_I0IfhFAelTPIh8w2cscS4C1k8QLKOc1rqn18CjKJbmczfu1X-EfEFaWjcDbIPYGCIGZmbNZv5DgiJ9w",
"enabled": true
},
{
"key": "client_credentials",
"value": "NzQ0YTEzMTZmOTM3NGEyN2I3ZWM5YmM3ZWFiYjBmOTI6M2ZiNWM2MDBkODRhNDU1ODhmZTNiZWM4MTI5N2E4M2Y=",
"enabled": true
},
{
"key": "cloned_environment",
"value": "{\"artists\":\"[“2DaxqgrOhkeH0fpeiQq2f4”, “2ooIqOf4X2uz4mMptXCtie”]\",\"N\":\"5\",\"user_id\":\"marcz2007\",\"country_code\":\"US\",\"client_id\":\"744a1316f9374a27b7ec9bc7eabb0f92\",\"client_secret\":\"3fb5c600d84a45588fe3bec81297a83f\",\"refresh_token\":\"AQAf0rvuNBo23wiIiyWQRfavFvx7JdTjvGYLufOBAM1ABtvXWvfqqo_I0IfhFAelTPIh8w2cscS4C1k8QLKOc1rqn18CjKJbmczfu1X-EfEFaWjcDbIPYGCIGZmbNZv5DgiJ9w\",\"client_credentials\":\"NzQ0YTEzMTZmOTM3NGEyN2I3ZWM5YmM3ZWFiYjBmOTI6M2ZiNWM2MDBkODRhNDU1ODhmZTNiZWM4MTI5N2E4M2Y=\",\"authorization\":\"BQD6I914g3iIt3zs1lpZl7nriwNgkFNMuIjIPjEa6ElTZw_PEbx3ewZkb38zlhypR5BfuyXLUxdJ0WyZ1TWETMSPYpPwBk7Olf6E5J49Q67BhgFWp5A4HyxYHgXNO-56sbOGx1aszETJ24Q8uGfOizzsv9WhpVU2cuC8lJdA3K2aYqc0L-8JnmD0VIrQhwX0\",\"playlist_id\":\"0cfptAtDW6jHMeWauwQ13w\",\"artist_name\":\"Oasis\",\"artistID\":\"2DaxqgrOhkeH0fpeiQq2f4\",\"trackID\":\"4AKUOaCRcoKTFnVI9LtsrN\"}",
"enabled": true
},
{
"key": "authorization",
"value": "BQD6I914g3iIt3zs1lpZl7nriwNgkFNMuIjIPjEa6ElTZw_PEbx3ewZkb38zlhypR5BfuyXLUxdJ0WyZ1TWETMSPYpPwBk7Olf6E5J49Q67BhgFWp5A4HyxYHgXNO-56sbOGx1aszETJ24Q8uGfOizzsv9WhpVU2cuC8lJdA3K2aYqc0L-8JnmD0VIrQhwX0",
"enabled": true
},
{
"key": "playlist_id",
"value": "0cfptAtDW6jHMeWauwQ13w",
"enabled": true
},
{
"key": "artist_name",
"value": "Oasis",
"enabled": true
},
{
"key": "artist_id",
"value": "2DaxqgrOhkeH0fpeiQq2f4",
"enabled": true
},
],
"_postman_variable_scope": "environment",
"_postman_exported_at": "2019-07-28T12:45:10.195Z",
"_postman_exported_using": "Postman/7.3.4"
}
I haven't read your question in detail, but
JSONError: Unexpected token u in JSON at position 0
is the typical
error message when you try to GET a Postman variable that doesn't
exist.
(Because of misspelling or whatever.)
Closely related is the error message
JSONError: Unexpected token '<' at 1:1<!doctype html>^
which
typically occurs when you try to request a URL that doesn't exist.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With