This is specific to the walmart api. I feel as though I configured the headers accurately and provided the required headers as they asked according to the documentation. However, I still get a 403 error. When I tested in postman, I still got a 403 error and it mentioned that the server was refusing a valid request. Here is the logged data below. I used Node.js on the backend with axios and crypto-js libraries. Can anyone let me know what is wrong here? Please let me know if there is anything else I should add to the question. (I purposely removed the consumer ID value):
Starting Walmart API call...
[0] Error: Request failed with status code 403
[0] at createError (C:\Projects\node_modules\axios\lib\core\createError.js:16:15)
[0] at settle (C:\Projects\node_modules\axios\lib\core\settle.js:17:12)
[0] at Unzip.handleStreamEnd (C:\Projects\node_modules\axios\lib\adapters\http.js:260:11)
[0] at Unzip.emit (events.js:400:28)
[0] at Unzip.emit (domain.js:470:12)
[0] at endReadableNT (internal/streams/readable.js:1317:12)
[0] at processTicksAndRejections (internal/process/task_queues.js:82:21) {
[0] config: {
[0] url: 'https://developer.api.walmart.com/api-proxy/service/affil/product/v2/paginated/items',
[0] method: 'get',
[0] headers: {
[0] Accept: 'application/json, text/plain, */*',
[0] 'WM_SEC.KEY_VERSION': '1',
[0] 'WM_SEC.TIMESTAMP': '1630376129289',
[0] 'WM_SEC.AUTH_SIGNATURE': [Promise],
[0] 'WM_CONSUMER.ID': '',
[0] 'User-Agent': 'axios/0.21.1'
[0] },
[0] transformRequest: [ [Function: transformRequest] ],
[0] transformResponse: [ [Function: transformResponse] ],
[0] timeout: 0,
[0] adapter: [Function: httpAdapter],
[0] xsrfCookieName: 'XSRF-TOKEN',
[0] xsrfHeaderName: 'X-XSRF-TOKEN',
[0] maxContentLength: -1,
[0] maxBodyLength: -1,
[0] validateStatus: [Function: validateStatus],
[0] data: undefined
[0] },
[0] request: <ref *1> ClientRequest {
[0] _events: [Object: null prototype] {
[0] abort: [Function (anonymous)],
[0] aborted: [Function (anonymous)],
[0] connect: [Function (anonymous)],
[0] error: [Function (anonymous)],
[0] socket: [Function (anonymous)],
[0] timeout: [Function (anonymous)],
[0] prefinish: [Function: requestOnPrefinish]
[0] },
[0] _eventsCount: 7,
[0] _maxListeners: undefined,
[0] outputData: [],
[0] outputSize: 0,
[0] writable: true,
[0] destroyed: true,
[0] _last: true,
[0] chunkedEncoding: false,
[0] shouldKeepAlive: false,
[0] _defaultKeepAlive: true,
[0] useChunkedEncodingByDefault: false,
[0] sendDate: false,
[0] _removedConnection: false,
[0] _removedContLen: false,
[0] _removedTE: false,
[0] _contentLength: 0,
[0] _hasBody: true,
[0] _trailer: '',
[0] finished: true,
[0] _headerSent: true,
[0] socket: TLSSocket {
[0] _tlsOptions: [Object],
[0] _secureEstablished: true,
[0] _securePending: false,
[0] _newSessionPending: false,
[0] _controlReleased: true,
[0] secureConnecting: false,
[0] _SNICallback: null,
[0] servername: 'developer.api.walmart.com',
[0] alpnProtocol: false,
[0] authorized: true,
[0] authorizationError: null,
[0] encrypted: true,
[0] _events: [Object: null prototype],
[0] _eventsCount: 12,
[0] connecting: false,
[0] _hadError: false,
[0] _parent: null,
[0] _host: 'developer.api.walmart.com',
[0] _readableState: [ReadableState],
[0] _maxListeners: undefined,
[0] _writableState: [WritableState],
[0] allowHalfOpen: false,
[0] _sockname: null,
[0] _pendingData: null,
[0] _pendingEncoding: '',
[0] server: undefined,
[0] _server: null,
[0] ssl: null,
[0] _requestCert: true,
[0] _rejectUnauthorized: true,
[0] parser: null,
[0] _httpMessage: [Circular *1],
[0] write: [Function: writeAfterFIN],
[0] [Symbol(res)]: null,
[0] [Symbol(verified)]: true,
[0] [Symbol(pendingSession)]: null,
[0] [Symbol(async_id_symbol)]: 124,
[0] [Symbol(kHandle)]: null,
[0] [Symbol(kSetNoDelay)]: false,
[0] [Symbol(lastWriteQueueSize)]: 0,
[0] [Symbol(timeout)]: null,
[0] [Symbol(kBuffer)]: null,
[0] [Symbol(kBufferCb)]: null,
[0] [Symbol(kBufferGen)]: null,
[0] [Symbol(kCapture)]: false,
[0] [Symbol(kBytesRead)]: 715,
[0] [Symbol(kBytesWritten)]: 340,
[0] [Symbol(connect-options)]: [Object],
[0] [Symbol(RequestTimeout)]: undefined
[0] },
[0] _header: 'GET /api-proxy/service/affil/product/v2/paginated/items HTTP/1.1\r\n' +
[0] 'Accept: application/json, text/plain, */*\r\n' +
[0] 'WM_SEC.KEY_VERSION: 1\r\n' +
[0] 'WM_SEC.TIMESTAMP: 1630376129289\r\n' +
[0] 'WM_SEC.AUTH_SIGNATURE: [object Promise]\r\n' +
[0] 'WM_CONSUMER.ID: ...\r\n' +
[0] 'User-Agent: axios/0.21.1\r\n' +
[0] 'Host: developer.api.walmart.com\r\n' +
[0] 'Connection: close\r\n' +
[0] '\r\n',
[0] _keepAliveTimeout: 0,
[0] _onPendingData: [Function: noopPendingOutput],
[0] agent: Agent {
[0] _events: [Object: null prototype],
[0] _eventsCount: 2,
[0] _maxListeners: undefined,
[0] defaultPort: 443,
[0] protocol: 'https:',
[0] options: [Object],
[0] requests: {},
[0] sockets: {},
[0] freeSockets: {},
[0] keepAliveMsecs: 1000,
[0] keepAlive: false,
[0] maxSockets: Infinity,
[0] maxFreeSockets: 256,
[0] scheduling: 'lifo',
[0] maxTotalSockets: Infinity,
[0] totalSocketCount: 0,
[0] maxCachedSessions: 100,
[0] _sessionCache: [Object],
[0] [Symbol(kCapture)]: false
[0] },
[0] socketPath: undefined,
[0] method: 'GET',
[0] maxHeaderSize: undefined,
[0] insecureHTTPParser: undefined,
[0] path: '/api-proxy/service/affil/product/v2/paginated/items',
[0] _ended: true,
[0] res: IncomingMessage {
[0] _readableState: [ReadableState],
[0] _events: [Object: null prototype],
[0] _eventsCount: 1,
[0] _maxListeners: undefined,
[0] socket: [TLSSocket],
[0] httpVersionMajor: 1,
[0] httpVersionMinor: 1,
[0] httpVersion: '1.1',
[0] complete: true,
[0] headers: [Object],
[0] rawHeaders: [Array],
[0] trailers: {},
[0] rawTrailers: [],
[0] aborted: false,
[0] upgrade: false,
[0] url: '',
[0] method: null,
[0] statusCode: 403,
[0] statusMessage: 'Forbidden',
[0] client: [TLSSocket],
[0] _consuming: true,
[0] _dumped: false,
[0] req: [Circular *1],
[0] responseUrl: 'https://developer.api.walmart.com/api-proxy/service/affil/product/v2/paginated/items',
[0] redirects: [],
[0] [Symbol(kCapture)]: false,
[0] [Symbol(RequestTimeout)]: undefined
[0] },
[0] aborted: false,
[0] timeoutCb: null,
[0] upgradeOrConnect: false,
[0] parser: null,
[0] maxHeadersCount: null,
[0] reusedSocket: false,
[0] host: 'developer.api.walmart.com',
[0] protocol: 'https:',
[0] _redirectable: Writable {
[0] _writableState: [WritableState],
[0] _events: [Object: null prototype],
[0] _eventsCount: 2,
[0] _maxListeners: undefined,
[0] _options: [Object],
[0] _ended: true,
[0] _ending: true,
[0] _redirectCount: 0,
[0] _redirects: [],
[0] _requestBodyLength: 0,
[0] _requestBodyBuffers: [],
[0] _onNativeResponse: [Function (anonymous)],
[0] _currentRequest: [Circular *1],
[0] _currentUrl: 'https://developer.api.walmart.com/api-proxy/service/affil/product/v2/paginated/items',
[0] [Symbol(kCapture)]: false
[0] },
[0] [Symbol(kCapture)]: false,
[0] [Symbol(kNeedDrain)]: false,
[0] [Symbol(corked)]: 0,
[0] [Symbol(kOutHeaders)]: [Object: null prototype] {
[0] accept: [Array],
[0] 'wm_sec.key_version': [Array],
[0] 'wm_sec.timestamp': [Array],
[0] 'wm_sec.auth_signature': [Array],
[0] 'wm_consumer.id': [Array],
[0] 'user-agent': [Array],
[0] host: [Array]
[0] }
[0] },
[0] response: {
[0] status: 403,
[0] statusText: 'Forbidden',
[0] headers: {
[0] 'content-type': 'application/json;charset=utf-8',
[0] 'last-modified': 'Tue, 31 Aug 2021 02:18:31 GMT',
[0] 'strict-transport-security': 'max-age=86400',
[0] 'wm_svc.env': 'prod',
[0] 'wm_svc.name': 'affil-product',
[0] 'wm_svc.version': '2.0.0',
[0] 'x-lua-strict-transport-security': 'max-age=86400',
[0] 'x-tb': '1',
[0] 'x-tb-optimization-total-bytes-saved': '0',
[0] date: 'Tue, 31 Aug 2021 02:18:31 GMT',
[0] connection: 'close',
[0] 'set-cookie': [Array]
[0] },
[0] config: {
[0] url: 'https://developer.api.walmart.com/api-proxy/service/affil/product/v2/paginated/items',
[0] method: 'get',
[0] headers: [Object],
[0] transformRequest: [Array],
[0] transformResponse: [Array],
[0] timeout: 0,
[0] adapter: [Function: httpAdapter],
[0] xsrfCookieName: 'XSRF-TOKEN',
[0] xsrfHeaderName: 'X-XSRF-TOKEN',
[0] maxContentLength: -1,
[0] maxBodyLength: -1,
[0] validateStatus: [Function: validateStatus],
[0] data: undefined
[0] },
[0] request: <ref *1> ClientRequest {
[0] _events: [Object: null prototype],
[0] _eventsCount: 7,
[0] _maxListeners: undefined,
[0] outputData: [],
[0] outputSize: 0,
[0] writable: true,
[0] destroyed: true,
[0] _last: true,
[0] chunkedEncoding: false,
[0] shouldKeepAlive: false,
[0] _defaultKeepAlive: true,
[0] useChunkedEncodingByDefault: false,
[0] sendDate: false,
[0] _removedConnection: false,
[0] _removedContLen: false,
[0] _removedTE: false,
[0] _contentLength: 0,
[0] _hasBody: true,
[0] _trailer: '',
[0] finished: true,
[0] _headerSent: true,
[0] socket: [TLSSocket],
[0] _header: 'GET /api-proxy/service/affil/product/v2/paginated/items HTTP/1.1\r\n' +
[0] 'Accept: application/json, text/plain, */*\r\n' +
[0] 'WM_SEC.KEY_VERSION: 1\r\n' +
[0] 'WM_SEC.TIMESTAMP: 1630376129289\r\n' +
[0] 'WM_SEC.AUTH_SIGNATURE: [object Promise]\r\n' +
[0] 'WM_CONSUMER.ID: 0ea59601-ea5c-448b-9003-d1baea61e4d6\r\n' +
[0] 'User-Agent: axios/0.21.1\r\n' +
[0] 'Host: developer.api.walmart.com\r\n' +
[0] 'Connection: close\r\n' +
[0] '\r\n',
[0] _keepAliveTimeout: 0,
[0] _onPendingData: [Function: noopPendingOutput],
[0] agent: [Agent],
[0] socketPath: undefined,
[0] method: 'GET',
[0] maxHeaderSize: undefined,
[0] insecureHTTPParser: undefined,
[0] path: '/api-proxy/service/affil/product/v2/paginated/items',
[0] _ended: true,
[0] res: [IncomingMessage],
[0] aborted: false,
[0] timeoutCb: null,
[0] upgradeOrConnect: false,
[0] parser: null,
[0] maxHeadersCount: null,
[0] reusedSocket: false,
[0] host: 'developer.api.walmart.com',
[0] protocol: 'https:',
[0] _redirectable: [Writable],
[0] [Symbol(kCapture)]: false,
[0] [Symbol(kNeedDrain)]: false,
[0] [Symbol(corked)]: 0,
[0] [Symbol(kOutHeaders)]: [Object: null prototype]
[0] },
[0] data: { details: [Object] }
[0] },
[0] isAxiosError: true,
[0] toJSON: [Function: toJSON]
Related
Currently, I am trying to fetch data after communicating with the backend server through SSR through Next.js and sprinkle it on the page.
However, one problem is that when I run npm run dev locally, getServerSideProps runs well, but when I upload it to a container through Docker-compose, my API for getServerSideProps doesn't work.
const ResultMenu: NextPage<Props> = ({ CategoryData }) => {
...
};
export default ResultMenu;
export const getServerSideProps: GetServerSideProps = async (context) => {
try {
const { menuId } = context.query;
const response = await axios.get<CategoryType[]>(
"http://localhost:8080/category/get/menu",
{
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
params: {
menuId: menuId,
},
}
);
const data = response.data;
console.log(data);
return {
props: {
CategoryData: data,
},
};
} catch (err) {
console.log(err);
return {
props: {},
};
}
};
In the frontend container, this error code appears
Error: connect ECONNREFUSED 127.0.0.1:8080
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1195:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 8080,
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,
validateStatus: [Function: validateStatus],
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'User-Agent': 'axios/0.26.1'
},
params: { menuId: '1' },
method: 'get',
url: 'http://localhost:8080/category/get/menu',
data: undefined
},
request: <ref *1> Writable {
_writableState: WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: true,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: true,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
afterWriteTickInfo: null,
buffered: [],
bufferedIndex: 0,
allBuffers: true,
allNoop: true,
pendingcb: 0,
constructed: true,
prefinished: false,
errorEmitted: false,
emitClose: true,
autoDestroy: true,
errored: null,
closed: false,
closeEmitted: false,
[Symbol(kOnFinished)]: []
},
_events: [Object: null prototype] {
response: [Function: handleResponse],
error: [Function: handleRequestError],
socket: [Function: handleRequestSocket]
},
_eventsCount: 3,
_maxListeners: undefined,
_options: {
maxRedirects: 21,
maxBodyLength: 10485760,
protocol: 'http:',
path: '/category/get/menu?menuId=1',
method: 'GET',
headers: [Object],
agent: undefined,
agents: [Object],
auth: undefined,
hostname: 'localhost',
port: '8080',
nativeProtocols: [Object],
pathname: '/category/get/menu',
search: '?menuId=1'
},
_ended: true,
_ending: true,
_redirectCount: 0,
_redirects: [],
_requestBodyLength: 0,
_requestBodyBuffers: [],
_onNativeResponse: [Function (anonymous)],
_currentRequest: ClientRequest {
_events: [Object: null prototype],
_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: [Socket],
_header: 'GET /category/get/menu?menuId=1 HTTP/1.1\r\n' +
'Accept: application/json, text/plain, */*\r\n' +
'Content-Type: application/json\r\n' +
'Access-Control-Allow-Origin: *\r\n' +
'User-Agent: axios/0.26.1\r\n' +
'Host: localhost:8080\r\n' +
'Connection: close\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: [Agent],
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/category/get/menu?menuId=1',
_ended: false,
res: null,
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'localhost',
protocol: 'http:',
_redirectable: [Circular *1],
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype]
},
_currentUrl: 'http://localhost:8080/category/get/menu?menuId=1',
[Symbol(kCapture)]: false
},
response: undefined,
isAxiosError: true,
toJSON: [Function: toJSON]
}
1
undefined
Dockerfile
FROM node:12
ENV PORT 3000
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Installing dependencies
COPY package*.json /usr/src/app/
RUN npm install
# Copying source files
COPY . /usr/src/app
# Building app
RUN npm run build
EXPOSE 3000
# Running the app
CMD "npm" "run" "dev"
docker-compose.yml
version: "3"
services:
frontend:
container_name: frontend
build:
context: ./frontend
dockerfile: Dockerfile
ports:
- "3000:3000"
volumes:
- ./frontend:/usr/src/app
- /usr/src/app/node_modules
- /usr/src/app/.next
networks:
- network-tier
backend:
container_name: backend
build: ./backend
depends_on:
- mysqldb
ports:
- 8080:8080
environment:
spring.datasource.url: "jdbc:mysql://mysqldb:3306/test_db?useSSL=false&useLegacyDatetimeCode=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Seoul&characterEncoding=UTF-8&autoReconnect=true&createDatabaseIfNotExist=true"
volumes:
- ./menu-canvas:/usr/src/backend
networks:
- network-tier
tty: true
mysqldb:
image: mysql:5.7
container_name: mysqldb
environment:
MYSQL_DATABASE: test_db
MYSQL_ROOT_PASSWORD: "0000"
MYSQL_ROOT_HOST: "%"
CHARACTER_SET_SERVER: utf8
command:
[
"--character-set-server=utf8mb4",
"--collation-server=utf8mb4_unicode_ci",
]
volumes:
- ./menu-canvas:/usr/src/db
ports:
- "3306:3306"
networks:
- network-tier
platform: linux/amd64
networks:
network-tier:
external: true
volumes:
menu-canvas:
next.config.js
/** #type {import('next').NextConfig} */
const nextConfig = {
images: {
domains: ["localhost", "*"],
},
reactStrictMode: true,
};
module.exports = nextConfig;
package.json
{
"name": "frontend",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
...
},
"devDependencies": {
...
},
"proxy": {
"*": {
"target": "http://localhost:8080"
}
}
}
I've been thinking a lot all day, but I don't know how... Help!
When running the getServerSideProps the communication would be container to container. So for these requests, routes to localhost would not work. Instead it would need to be something like backend:8080 (when communicating from the frontend service to the backend service).
The localhost domain would work as expected on the client side requests assuming you were exposing all ports as expected.
When you run this without docker everything works because all services are on localhost. When run via docker-compose they no longer are.
If you really wanted to use localhost instead of the service name you may be able to use a network host https://docs.docker.com/network/host/
I need your help and thank you in advance !
I am trying to make a call to the api platform in a nuxt app through axios but I got error of getaddrinfo ENOTFOUND backend.localhost when trying to make a get request with axios in my nuxt app.
My configuration is:
api platform is dockerized through symfony and used as the backend
traefik is used as reverse proxy
nuxt is not dockerized and used as frontend
Here is how my docker-compose looks like:
version: "3.8"
services:
backend:
build:
context: ./
dockerfile: ./infra/docker/backend/Dockerfile.dev
user: "${PUID}:${PGID}"
restart: unless-stopped
environment:
DATABASE_CLIENT: ${DATABASE_CLIENT}
DATABASE_NAME: ${DATABASE_NAME}
DATABASE_HOST: ${DATABASE_HOST}
DATABASE_PORT: ${DATABASE_PORT}
DATABASE_USERNAME: ${DATABASE_USERNAME}
DATABASE_PASSWORD: ${DATABASE_PASSWORD}
expose:
- 80
depends_on:
- mysql
volumes:
- ./backend:/app:rw,cached
labels:
- "traefik.enable=true"
- "traefik.http.routers.backend.rule=Host(`backend.localhost`)"
- "traefik.http.routers.backend.entrypoints=web"
sysctls:
- net.ipv4.ip_unprivileged_port_start=0
portainer:
image: portainer/portainer
restart: unless-stopped
command: --no-auth -H unix:///var/run/docker.sock
expose:
- 9000
volumes:
- /var/run/docker.sock:/var/run/docker.sock
labels:
- "traefik.enable=true"
- "traefik.http.routers.portainer.rule=Host(`portainer.localhost`)"
- "traefik.http.routers.portainer.entrypoints=web"
traefik:
image: "traefik:v2.2.5"
command:
- "--log.level=DEBUG"
- "--api.insecure=true"
# Enabling docker provider
- "--providers.docker=true"
# Do not expose containers unless explicitly told so
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
ports:
- "80:80"
- "8080:8080"
labels:
- "traefik.enable=true"
- "traefik.http.routers.traefik.entrypoints=web"
- "traefik.http.routers.traefik.rule=Host(`monitor.localhost`)"
- "traefik.http.services.traefik.loadbalancer.server.port=8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
My nuxt.config.js:
...
axios: {
baseURL: 'http://backend.localhost/api'
}
....
I can access through the browser to the api UI via http://backend.localhost/api and everything works well there.
But making a request in my nuxt app code, leads to the error below:
Error: getaddrinfo ENOTFOUND backend.localhost
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:69:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'backend.localhost',
config: {
url: '/users',
method: 'get',
headers: {
connection: 'keep-alive',
'cache-control': 'max-age=0',
'sec-ch-ua': '"Chromium";v="94", "Google Chrome";v="94", ";Not A Brand";v="99"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36',
'sec-fetch-site': 'same-origin',
'sec-fetch-mode': 'navigate',
'sec-fetch-dest': 'document',
referer: 'http://localhost:3000/',
'accept-encoding': 'gzip, deflate',
'accept-language': 'en-GB,en;q=0.9,fr-FR;q=0.8,fr;q=0.7,en-US;q=0.6',
cookie: 'phpMyAdmin=46260be5bb513da7351adb73a0f4af8e; io=7IL9SV9Qq5sBDsGzAAAD; pmaAuth-1=%7B%22iv%22%3A%22yjzw8rQARGbpPBqg6BiNlQ%3D%3D%22%2C%22mac%22%3A%2213692b36a201adb505c7ce76926414461029f705%22%2C%22payload%22%3A%22oYBIB7LMEU96C4T5X6RxgQ%3D%3D%22%7D; i18n_redirected=fr',
'if-none-match': '"46616-dbF9UDJNzxIn7dMVplznpaaPF6s"',
Accept: 'application/json, text/plain, */*'
},
baseURL: 'http://backend.localhost/api',
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 0,
adapter: [Function: httpAdapter],
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
validateStatus: [Function: validateStatus],
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
},
data: undefined
},
request: <ref *1> Writable {
_writableState: WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: true,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: true,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
afterWriteTickInfo: null,
buffered: [],
bufferedIndex: 0,
allBuffers: true,
allNoop: true,
pendingcb: 0,
constructed: true,
prefinished: false,
errorEmitted: false,
emitClose: true,
autoDestroy: true,
errored: null,
closed: false,
closeEmitted: false,
[Symbol(kOnFinished)]: []
},
_events: [Object: null prototype] {
response: [Function: handleResponse],
error: [Function: handleRequestError]
},
_eventsCount: 2,
_maxListeners: undefined,
_options: {
maxRedirects: 21,
maxBodyLength: 10485760,
protocol: 'http:',
path: '/api/users',
method: 'GET',
headers: [Object],
agent: undefined,
agents: [Object],
auth: undefined,
hostname: 'backend.localhost',
port: null,
nativeProtocols: [Object],
pathname: '/api/users'
},
_ended: true,
_ending: true,
_redirectCount: 0,
_redirects: [],
_requestBodyLength: 0,
_requestBodyBuffers: [],
_onNativeResponse: [Function (anonymous)],
_currentRequest: ClientRequest {
_events: [Object: null prototype],
_eventsCount: 7,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: false,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: true,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: false,
socket: [Socket],
_header: 'GET /api/users HTTP/1.1\r\n' +
'connection: keep-alive\r\n' +
'cache-control: max-age=0\r\n' +
'sec-ch-ua: "Chromium";v="94", "Google Chrome";v="94", ";Not A Brand";v="99"\r\n' +
'sec-ch-ua-mobile: ?0\r\n' +
'sec-ch-ua-platform: "Windows"\r\n' +
'upgrade-insecure-requests: 1\r\n' +
'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36\r\n' +
'sec-fetch-site: same-origin\r\n' +
'sec-fetch-mode: navigate\r\n' +
'sec-fetch-dest: document\r\n' +
'referer: http://localhost:3000/\r\n' +
'accept-encoding: gzip, deflate\r\n' +
'accept-language: en-GB,en;q=0.9,fr-FR;q=0.8,fr;q=0.7,en-US;q=0.6\r\n' +
'cookie: phpMyAdmin=46260be5bb513da7351adb73a0f4af8e; io=7IL9SV9Qq5sBDsGzAAAD; pmaAuth-1=%7B%22iv%22%3A%22yjzw8rQARGbpPBqg6BiNlQ%3D%3D%22%2C%22mac%22%3A%2213692b36a201adb505c7ce76926414461029f705%22%2C%22payload%22%3A%22oYBIB7LMEU96C4T5X6RxgQ%3D%3D%22%7D; i18n_redirected=fr\r\n' +
'if-none-match: "46616-dbF9UDJNzxIn7dMVplznpaaPF6s"\r\n' +
'Accept: application/json, text/plain, */*\r\n' +
'Host: backend.localhost\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Object],
agent: [Agent],
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/api/users',
_ended: false,
res: null,
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'backend.localhost',
protocol: 'http:',
_redirectable: [Circular *1],
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype]
},
_currentUrl: 'http://backend.localhost/api/users',
[Symbol(kCapture)]: false
},
response: undefined,
isAxiosError: true,
toJSON: [Function: toJSON]
}
Here is the way I made the request:
async fetch() {
....
await this.$axios.$get('/users')
...
}
I found the root cause of the issue.
Indeed, I am using a windows 10 Family edition. That windows version requires installing window sub linux wsl + docker desktop to be able to use docker.
So, using docker with wsl makes my backend.localhost NOT FOUND because docker is isolated into wsl and communicates with my host only by its own ipV4 that you can find by opening the wsl terminal and typing ipconfig.exe and locating ipV4 in ethernet vEthernet (WSL).
Replace the backend.localhost by that ip and exposing your backend service to the port 81 as ipV4:81 => you get everything working.
When requesting GET https://outlook.office.com/api/v2.0/me/calendars/{calendar_id}/events the response (for some events) does not have a Start and End date.
The full structure for such events is as follows:
{
'OriginalStartTimeZone': None,
'End': {
'TimeZone': 'tzone://Microsoft/Utc',
'DateTime': '0001-01-01T00:00:00.0000000Z'
},
'HasAttachments': False,
'ResponseRequested': True,
'ShowAs': 'Free',
'Recurrence': None,
'Start': {
'TimeZone': 'tzone://Microsoft/Utc',
'DateTime': '0001-01-01T00:00:00.0000000Z'
},
'BodyPreview': '',
'AllowNewTimeProposals': True,
'Location': {...},
'Attendees': [...],
'TransactionId': None,
'Type': 'SingleInstance',
'ResponseStatus': {
'Response': 'NotResponded',
'Time': '0001-01-01T00:00:00Z'
},
'Body': {...},
'OnlineMeeting': None,
'IsRoomRequested': False,
'OnlineMeetingProvider': 'Unknown',
'IsCancelled': False,
'IsAllDay': False,
'ReminderMinutesBeforeStart': 0,
'Subject': '...',
'Categories': [],
'LastModifiedDateTime': '2020-03-11T18:31:15.548Z',
'AutoRoomBookingOptions': None,
'OriginalEndTimeZone': None,
'CreatedDateTime': '2020-03-11T18:34:34.259429Z',
'IsOnlineMeeting': False,
'#odata.id': '...',
'IsDraft': False,
'WebLink': '...',
'ChangeKey': '...',
'SeriesMasterId': None,
'IsOrganizer': True,
'iCalUId': None,
'AutoRoomBookingStatus': 'None',
'Locations': [],
'Id': '...',
'IsReminderOn': False,
'Calendar#odata.associationLink': '...',
'Calendar#odata.navigationLink': '...',
'Importance': 'Normal',
'Organizer': {...},
'#odata.etag': '...',
'Sensitivity': 'Normal',
'OnlineMeetingUrl': None
}
Is this normal behavior? If so, how can this be displayed?
How can I create such an event to reproduce it?
I keep getting an error when trying to POST to Youtube v3 API.
I'm trying to get a response URI, so I can upload a Youtube video.
This is the documentation I'm referencing: https://developers.google.com/youtube/v3/docs/videos/insert#go
Does anyone know what I'm doing wrong? Error log is below.
My code:
axios({
method: 'POST',
baseURL: 'https://www.googleapis.com',
url: '/upload/youtube/v3/videos',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Content-Length': 167,
'X-Upload-Content-Length': 302080,
'X-Upload-Content-Type': 'video/mp4',
'Authorization': `Bearer <MY_ACCESS_TOKEN>`, // has my actual access_token
},
params: {
'uploadType': 'resumable',
'key': <MY_API_KEY>, // has my actual app API key
'part': 'snippet,status'
},
data: {
'snippet': {
'title': 'Test Upload 1',
'description': 'Test Description 1',
'tags': ['tag1', 'tag2'],
},
'status': {
'privacyStatus': 'private',
}
}
})
.then(response => {
res.json(response.data);
})
.catch(err => console.log(err));
Error Log:
Error: Request failed with status code 400
at createError (/mnt/e/Dev/20200316_youtube_api/node_modules/axios/lib/core/createError.js:16:15)
at settle (/mnt/e/Dev/20200316_youtube_api/node_modules/axios/lib/core/settle.js:17:12)
at IncomingMessage.handleStreamEnd (/mnt/e/Dev/20200316_youtube_api/node_modules/axios/lib/adapters/http.js:236:11)
at IncomingMessage.emit (events.js:323:22)
at endReadableNT (_stream_readable.js:1204:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
config: {
url: '/upload/youtube/v3/videos',
method: 'post',
params: {
key: '<MY_API_KEY>',
part: 'snippet,status'
},
data: '{"snippet":{"title":"Test Upload 1","description":"Test Description 1","tags":["tag1","tag2"]},"status":{"privacyStatus":"private"}}',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'Content-Length': 132,
'X-Upload-Content-Length': 302080,
'X-Upload-Content-Type': 'video/mp4',
Authorization: 'Bearer <MY_ACCESS_TOKEN>',
'User-Agent': 'axios/0.19.2'
},
baseURL: 'https://www.googleapis.com',
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 0,
adapter: [Function: httpAdapter],
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus]
},
request: ClientRequest {
_events: [Object: null prototype] {
socket: [Function],
abort: [Function],
aborted: [Function],
error: [Function],
timeout: [Function],
prefinish: [Function: requestOnPrefinish]
},
_eventsCount: 6,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: null,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: TLSSocket {
_tlsOptions: [Object],
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
_SNICallback: null,
servername: 'www.googleapis.com',
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: [Object: null prototype],
_eventsCount: 9,
connecting: false,
_hadError: false,
_parent: null,
_host: 'www.googleapis.com',
_readableState: [ReadableState],
readable: true,
_maxListeners: undefined,
_writableState: [WritableState],
writable: false,
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: [TLSWrap],
_requestCert: true,
_rejectUnauthorized: true,
parser: null,
_httpMessage: [Circular],
[Symbol(res)]: [TLSWrap],
[Symbol(asyncId)]: 6,
[Symbol(kHandle)]: [TLSWrap],
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBuffer)]: null,
[Symbol(kBufferCb)]: null,
[Symbol(kBufferGen)]: null,
[Symbol(kCapture)]: false,
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0,
[Symbol(connect-options)]: [Object]
},
connection: TLSSocket {
_tlsOptions: [Object],
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
_SNICallback: null,
servername: 'www.googleapis.com',
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: [Object: null prototype],
_eventsCount: 9,
connecting: false,
_hadError: false,
_parent: null,
_host: 'www.googleapis.com',
_readableState: [ReadableState],
readable: true,
_maxListeners: undefined,
_writableState: [WritableState],
writable: false,
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: [TLSWrap],
_requestCert: true,
_rejectUnauthorized: true,
parser: null,
_httpMessage: [Circular],
[Symbol(res)]: [TLSWrap],
[Symbol(asyncId)]: 6,
[Symbol(kHandle)]: [TLSWrap],
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBuffer)]: null,
[Symbol(kBufferCb)]: null,
[Symbol(kBufferGen)]: null,
[Symbol(kCapture)]: false,
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0,
[Symbol(connect-options)]: [Object]
},
_header: 'POST /upload/youtube/v3/videos?key=<MY_API_KEY>&part=snippet,status HTTP/1.1\r\n' +
'Accept: application/json\r\n' +
'Content-Type: application/json\r\n' +
'Content-Length: 132\r\n' +
'X-Upload-Content-Length: 302080\r\n' +
'X-Upload-Content-Type: video/mp4\r\n' +
'Authorization: Bearer <MY_ACCESS_TOKEN>\r\n' +
'User-Agent: axios/0.19.2\r\n' +
'Host: www.googleapis.com\r\n' +
'Connection: close\r\n' +
'\r\n',
_onPendingData: [Function: noopPendingOutput],
agent: Agent {
_events: [Object: null prototype],
_eventsCount: 2,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: [Object],
requests: {},
sockets: [Object],
freeSockets: {},
keepAliveMsecs: 1000,
keepAlive: false,
maxSockets: Infinity,
maxFreeSockets: 256,
maxCachedSessions: 100,
_sessionCache: [Object],
[Symbol(kCapture)]: false
},
socketPath: undefined,
method: 'POST',
insecureHTTPParser: undefined,
path: '/upload/youtube/v3/videos?key=<MY_API_KEY>&part=snippet,status',
_ended: true,
res: IncomingMessage {
_readableState: [ReadableState],
readable: false,
_events: [Object: null prototype],
_eventsCount: 3,
_maxListeners: undefined,
socket: [TLSSocket],
connection: [TLSSocket],
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: '1.1',
complete: true,
headers: [Object],
rawHeaders: [Array],
trailers: {},
rawTrailers: [],
aborted: false,
upgrade: false,
url: '',
method: null,
statusCode: 400,
statusMessage: 'Bad Request',
client: [TLSSocket],
_consuming: false,
_dumped: false,
req: [Circular],
responseUrl: 'https://www.googleapis.com/upload/youtube/v3/videos?key=<MY_API_KEY>&part=snippet,status',
redirects: [],
[Symbol(kCapture)]: false
},
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
_redirectable: Writable {
_writableState: [WritableState],
writable: true,
_events: [Object: null prototype],
_eventsCount: 2,
_maxListeners: undefined,
_options: [Object],
_redirectCount: 0,
_redirects: [],
_requestBodyLength: 132,
_requestBodyBuffers: [],
_onNativeResponse: [Function],
_currentRequest: [Circular],
_currentUrl: 'https://www.googleapis.com/upload/youtube/v3/videos?key=<MY_API_KEY>&part=snippet,status',
[Symbol(kCapture)]: false
},
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype] {
accept: [Array],
'content-type': [Array],
'content-length': [Array],
'x-upload-content-length': [Array],
'x-upload-content-type': [Array],
authorization: [Array],
'user-agent': [Array],
host: [Array]
}
},
response: {
status: 400,
statusText: 'Bad Request',
headers: {
'x-guploader-uploadid': '<REPONSE_ID_THAT_I_REMOVED>',
vary: 'Origin, X-Origin',
'content-type': 'application/json; charset=UTF-8',
'content-length': '353',
date: 'Sun, 07 Jun 2020 22:45:50 GMT',
server: 'UploadServer',
'alt-svc': 'h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443";
ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"',
connection: 'close'
},
config: {
url: '/upload/youtube/v3/videos',
method: 'post',
params: [Object],
data: '{"snippet":{"title":"Test Upload 1","description":"Test Description 1","tags":["tag1","tag2"]},"status":{"privacyStatus":"private"}}',
headers: [Object],
baseURL: 'https://www.googleapis.com',
transformRequest: [Array],
transformResponse: [Array],
timeout: 0,
adapter: [Function: httpAdapter],
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus]
},
request: ClientRequest {
_events: [Object: null prototype],
_eventsCount: 6,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: null,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: [TLSSocket],
connection: [TLSSocket],
_header: 'POST /upload/youtube/v3/videos?key=<MY_API_KEY>&part=snippet,status HTTP/1.1\r\n' +
'Accept: application/json\r\n' +
'Content-Type: application/json\r\n' +
'Content-Length: 132\r\n' +
'X-Upload-Content-Length: 302080\r\n' +
'X-Upload-Content-Type: video/mp4\r\n' +
'Authorization: Bearer <MY_ACCESS_TOKEN>\r\n' +
'User-Agent: axios/0.19.2\r\n' +
'Host: www.googleapis.com\r\n' +
'Connection: close\r\n' +
'\r\n',
_onPendingData: [Function: noopPendingOutput],
agent: [Agent],
socketPath: undefined,
method: 'POST',
insecureHTTPParser: undefined,
path: '/upload/youtube/v3/videos?key=<MY_API_KEY>&part=snippet,status',
_ended: true,
res: [IncomingMessage],
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
_redirectable: [Writable],
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype]
},
data: { error: [Object] }
},
isAxiosError: true,
toJSON: [Function]
}
That request is not for uploading video, that request returns a url to which the video can be uploaded.
I am using OneNote /content endpoint to retrieve page content as described here: https://learn.microsoft.com/en-us/graph/api/page-get?view=graph-rest-1.0
However, calling GET on /me/onenote/pages/{id}/content[?includeIDs=true] returns me this:
{
"error": {
"code": "BadRequest",
"message": "Resource not found for the segment 'content['.",
"innerError": {
"request-id": "6b7e5549-32a5-4b6f-80ed-ecacp9v41699",
"date": "2020-03-31T00:05:27"
}
}
}
calling GET on /me/onenote/pages/{id}/content returns this:
{
"_readableState": {
"objectMode": false,
"highWaterMark": 16384,
"buffer": {
"head": null,
"tail": null,
"length": 0
},
"length": 0,
"pipes": [],
"flowing": null,
"ended": false,
"endEmitted": false,
"reading": false,
"sync": false,
"needReadable": false,
"emittedReadable": false,
"readableListening": false,
"resumeScheduled": false,
"errorEmitted": false,
"emitClose": true,
"autoDestroy": false,
"destroyed": false,
"defaultEncoding": "utf8",
"awaitDrainWriters": null,
"multiAwaitDrain": false,
"readingMore": false,
"decoder": null,
"encoding": null
},
"readable": true,
"_events": {},
"_eventsCount": 5,
"_writableState": {
"objectMode": false,
"highWaterMark": 16384,
"finalCalled": false,
"needDrain": false,
"ending": false,
"ended": false,
"finished": false,
"destroyed": false,
"decodeStrings": true,
"defaultEncoding": "utf8",
"length": 0,
"writing": false,
"corked": 0,
"sync": true,
"bufferProcessing": false,
"writecb": null,
"writelen": 0,
"afterWriteTickInfo": null,
"bufferedRequest": null,
"lastBufferedRequest": null,
"pendingcb": 0,
"prefinished": false,
"errorEmitted": false,
"emitClose": true,
"autoDestroy": false,
"errored": false,
"bufferedRequestCount": 0,
"corkedRequestsFree": {
"next": null,
"entry": null
}
},
"writable": true,
"allowHalfOpen": true,
"_transformState": {
"needTransform": false,
"transforming": false,
"writecb": null,
"writechunk": null,
"writeencoding": null
}
}
Neither returns the actual page content. Any idea?
The "includeIDs" is an optional query parameter. Remove the square brackets around it to get rid of the Bad Request error. So the request should be GET on /me/onenote/pages/{id}/content?includeIDs=true