using the below code to Try to get all the post but I am not getting all the post objects returned. Any pointers where I am wrong in hitting the API?
// Create a token without the client
const jwt = require('jsonwebtoken');
const axios = require('axios');
// Admin API key goes here
const key = 'xxxx';
// Split the key into ID and SECRET
const [id, secret] = key.split(':');
// Create the token (including decoding secret)
const token = jwt.sign({}, Buffer.from(secret, 'hex'), {
keyid: id,
algorithm: 'HS256',
expiresIn: '5m',
audience: `/admin/`
});
// Make an authenticated request to create a post
const url = 'https://play-with-ghost.com/barber-klimax2/ghost/admin/api/content/posts/?fields=title,url';
const headers = { Authorization: `Ghost ${token}` };
//const payload = { posts: [{ title: 'Hello World' }] };
axios.get(url,{ headers })
.then(response => console.log(response))
.catch(error => console.error(error));
Getting the following response.
{
status: 200,
statusText: 'OK',
headers: {
date: 'Mon, 30 May 2022 21:02:53 GMT',
'content-type': 'text/html; charset=UTF-8',
'transfer-encoding': 'chunked',
connection: 'close',
'cache-control': 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0',
'last-modified': 'Sat, 26 Oct 1985 08:15:00 GMT',
vary: 'Accept-Encoding',
'x-frame-options': 'sameorigin',
'x-powered-by': 'Express',
'cf-cache-status': 'DYNAMIC',
'expect-ct': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
'report-to': '{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=yVvRWz5poSZzwV%2BLe6%2BP9RucbaEltQTpwI%2FSe%2Bz59H7FmuF9fDSs6onid4pIdCqWGWneGNzwBMn4uL2MGo2dj6Dlc%2BVV54t6xMEYuGvTcOvjLj7jDnBW7WhupTi2gqQ2Ld5umQTF"}],"group":"cf-nel","max_age":604800}',
nel: '{"success_fraction":0,"report_to":"cf-nel","max_age":604800}',
server: 'cloudflare',
'cf-ray': '713a69d03c2ff3ff-LHR',
'alt-svc': 'h3=":443"; ma=86400, h3-29=":443"; ma=86400'
},
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
},
adapter: [Function: httpAdapter],
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: { FormData: [Function] },
validateStatus: [Function: validateStatus],
headers: {
Accept: 'application/json, text/plain, */*',
Authorization: 'Ghost eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjYyOTRjZmI2ZWNjZDcwMDAwMTcwYWRkZCJ9.eyJpYXQiOjE2NTM5NDQ1NzIsImV4cCI6MTY1Mzk0NDg3MiwiYXVkIjoiL2FkbWluLyJ9.mgC1FEtOeRiCY4v-ILY-hJKL9Uu5Op_CC9T-CDH9UdQ',
'User-Agent': 'axios/0.27.2'
},
method: 'get',
url: 'https://play-with-ghost.com/barber-klimax2/ghost/admin/api/content/posts/?fields=title,url',
data: undefined
},
request: <ref *1> ClientRequest {
_events: [Object: null prototype] {
abort: [Function (anonymous)],
aborted: [Function (anonymous)],
connect: [Function (anonymous)],
error: [Function (anonymous)],
socket: [Function (anonymous)],
timeout: [Function (anonymous)],
prefinish: [Function: requestOnPrefinish]
},
_eventsCount: 7,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: false,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: false,
socket: TLSSocket {
_tlsOptions: [Object],
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
secureConnecting: false,
_SNICallback: null,
servername: 'play-with-ghost.com',
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: [Object: null prototype],
_eventsCount: 10,
connecting: false,
_hadError: false,
_parent: null,
_host: 'play-with-ghost.com',
_readableState: [ReadableState],
_maxListeners: undefined,
_writableState: [WritableState],
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: [TLSWrap],
_requestCert: true,
_rejectUnauthorized: true,
parser: null,
_httpMessage: [Circular *1],
[Symbol(res)]: [TLSWrap],
[Symbol(verified)]: true,
[Symbol(pendingSession)]: null,
[Symbol(async_id_symbol)]: 19,
[Symbol(kHandle)]: [TLSWrap],
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBuffer)]: null,
[Symbol(kBufferCb)]: null,
[Symbol(kBufferGen)]: null,
[Symbol(kCapture)]: false,
[Symbol(kSetNoDelay)]: false,
[Symbol(kSetKeepAlive)]: true,
[Symbol(kSetKeepAliveInitialDelay)]: 60,
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0,
[Symbol(connect-options)]: [Object]
},
_header: 'GET /barber-klimax2/ghost/ HTTP/1.1\r\n' +
'Accept: application/json, text/plain, */*\r\n' +
'Authorization: Ghost eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjYyOTRjZmI2ZWNjZDcwMDAwMTcwYWRkZCJ9.eyJpYXQiOjE2NTM5NDQ1NzIsImV4cCI6MTY1Mzk0NDg3MiwiYXVkIjoiL2FkbWluLyJ9.mgC1FEtOeRiCY4v-ILY-hJKL9Uu5Op_CC9T-CDH9UdQ\r\n' +
'User-Agent: axios/0.27.2\r\n' +
'Host: play-with-ghost.com\r\n' +
'Connection: close\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: Agent {
_events: [Object: null prototype],
_eventsCount: 2,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: [Object: null prototype],
requests: [Object: null prototype] {},
sockets: [Object: null prototype],
freeSockets: [Object: null prototype] {},
keepAliveMsecs: 1000,
keepAlive: false,
maxSockets: Infinity,
maxFreeSockets: 256,
scheduling: 'lifo',
maxTotalSockets: Infinity,
totalSocketCount: 1,
maxCachedSessions: 100,
_sessionCache: [Object],
[Symbol(kCapture)]: false
},
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/barber-klimax2/ghost/',
_ended: true,
res: IncomingMessage {
_readableState: [ReadableState],
_events: [Object: null prototype],
_eventsCount: 4,
_maxListeners: undefined,
socket: [TLSSocket],
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: '1.1',
complete: true,
rawHeaders: [Array],
rawTrailers: [],
aborted: false,
upgrade: false,
url: '',
method: null,
statusCode: 200,
statusMessage: 'OK',
client: [TLSSocket],
_consuming: true,
_dumped: false,
req: [Circular *1],
responseUrl: 'https://play-with-ghost.com/barber-klimax2/ghost/#/admin/api/content/posts/?fields=title,url',
redirects: [],
[Symbol(kCapture)]: false,
[Symbol(kHeaders)]: [Object],
[Symbol(kHeadersCount)]: 32,
[Symbol(kTrailers)]: null,
[Symbol(kTrailersCount)]: 0
},
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'play-with-ghost.com',
protocol: 'https:',
_redirectable: Writable {
_writableState: [WritableState],
_events: [Object: null prototype],
_eventsCount: 3,
_maxListeners: undefined,
_options: [Object],
_ended: true,
_ending: true,
_redirectCount: 1,
_redirects: [],
_requestBodyLength: 0,
_requestBodyBuffers: [],
_onNativeResponse: [Function (anonymous)],
_currentRequest: [Circular *1],
_currentUrl: 'https://play-with-ghost.com/barber-klimax2/ghost/#/admin/api/content/posts/?fields=title,url',
_isRedirect: true,
[Symbol(kCapture)]: false
},
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype] {
accept: [Array],
authorization: [Array],
'user-agent': [Array],
host: [Array]
}
},
data: '<!doctype html>\n' +
'<!--[if (IE 8)&!(IEMobile)]><html class="no-js lt-ie9" lang="en"><![endif]-->\n' +
'<!--[if (gte IE 9)| IEMobile |!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->\n' +
'<head>\n' +
' <meta http-equiv="Content-Type" content="text/html" charset="UTF-8" />\n' +
' <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />\n' +
'\n' +
' <title>Ghost Admin</title>\n' +
'\n' +
' \n' +
'<meta name="ghost-admin/config/environment" content="%7B%22modulePrefix%22%3A%22ghost-admin%22%2C%22environment%22%3A%22production%22%2C%22rootURL%22%3A%22%2F%22%2C%22locationType%22%3A%22trailing-hash%22%2C%22EmberENV%22%3A%7B%22FEATURES%22%3A%7B%7D%2C%22EXTEND_PROTOTYPES%22%3A%7B%22Date%22%3Afalse%2C%22Array%22%3Atrue%2C%22String%22%3Atrue%2C%22Function%22%3Afalse%7D%2C%22_APPLICATION_TEMPLATE_WRAPPER%22%3Afalse%2C%22_JQUERY_INTEGRATION%22%3Atrue%2C%22_TEMPLATE_ONLY_GLIMMER_COMPONENTS%22%3Atrue%7D%2C%22APP%22%3A%7B%22version%22%3A%224.41%22%2C%22name%22%3A%22ghost-admin%22%7D%2C%22ember-simple-auth%22%3A%7B%7D%2C%22moment%22%3A%7B%22includeTimezone%22%3A%22all%22%7D%2C%22%40sentry%2Fember%22%3A%7B%22disablePerformance%22%3Atrue%2C%22sentry%22%3A%7B%7D%7D%2C%22ember-cli-mirage%22%3A%7B%22usingProxy%22%3Afalse%2C%22useDefaultPassthroughs%22%3Atrue%7D%2C%22exportApplicationGlobal%22%3Afalse%2C%22ember-load%22%3A%7B%22loadingIndicatorClass%22%3A%22ember-load-indicator%22%7D%7D" />\n' +
'\n' +
' <meta name="HandheldFriendly" content="True" />\n' +
' <meta name="MobileOptimized" content="320" />\n' +
' <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1, minimal-ui, viewport-fit=cover" />\n' +
' <meta name="pinterest" content="nopin" />\n' +
'\n' +
' <meta http-equiv="cleartype" content="on" />\n' +
' <meta name="apple-mobile-web-app-capable" content="yes" />\n' +
' <meta name="apple-mobile-web-app-status-bar-style" content="black" />\n' +
' <meta name="apple-mobile-web-app-title" content="Ghost" />\n' +
'\n' +
' <link rel="shortcut icon" href="assets/img/favicon.ico" />\n' +
' <link rel="apple-touch-icon" href="assets/img/apple-touch-icon-74680e326a7e87b159d366c7d4fb3d4b.png" />\n' +
'\n' +
' <meta name="application-name" content="Ghost" />\n' +
' <meta name="msapplication-TileColor" content="#15171A" />\n' +
' <meta name="msapplication-square70x70logo" content="assets/img/small-b90396925485f17b2ca82c31be42de5f.png" />\n' +
' <meta name="msapplication-square150x150logo" content="assets/img/medium-fef07013cffd5c45a655a250912a0ad7.png" />\n' +
' <meta name="msapplication-square310x310logo" content="assets/img/large-ac90af7c93a4b47e8d956fa9fef31d9d.png" />\n' +
'\n' +
" <!-- variables that we don't want postcss-custom-properties to remove -->\n" +
' <style>\n' +
' :root {\n' +
' --editor-sidebar-width: 0px;\n' +
' }\n' +
' </style>\n' +
'\n' +
' \n' +
' <link rel="stylesheet" href="assets/vendor.min-2c8ad32b7960bb605ebc20097fee5ebd.css">\n' +
' <link rel="stylesheet" href="assets/ghost.min-a73b150c7eecc4641d377cc73fb5eecd.css" title="light">\n' +
' \n' +
'\n' +
' \n' +
'</head>\n' +
'<body>\n' +
'\n' +
'<div class="ember-load-indicator">\n' +
' <div class="gh-loading-content">\n' +
' <div class="gh-loading-spinner"></div>\n' +
' </div>\n' +
'</div>\n' +
'\n' +
'\n' +
'\n' +
'<div id="ember-basic-dropdown-wormhole"></div>\n' +
'\n' +
'\n' +
' <script src="assets/vendor.min-9094db77ba3190cb10876f8e42e1d90d.js"></script>\n' +
' <script src="assets/ghost.min-1abf114ca26a71e8e1f09054f3592614.js"></script>\n' +
' \n' +
'</body>\n' +
'</html>\n'