Self-deploying flow with credentials

Hi! I'm trying to have a flow do a self-deploy with adminAuth credentials. I get the auth token, add the Bearer prefix in the headers, but the GET /flows returns "unauthorized". Does anybody know what I'm missing? Here's the self-deploy code I'm using:

[
    {
        "id": "f03c48f9.385fc8",
        "type": "http request",
        "z": "7a83f86f.55d4f8",
        "name": "POST /flows",
        "method": "POST",
        "ret": "txt",
        "url": "http://localhost:1880/flows",
        "tls": "",
        "x": 1010,
        "y": 660,
        "wires": [
            [
                "2756ff49.7a67"
            ]
        ]
    },
    {
        "id": "2756ff49.7a67",
        "type": "debug",
        "z": "7a83f86f.55d4f8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "x": 1150,
        "y": 660,
        "wires": []
    },
    {
        "id": "b93f6d0a.9aca3",
        "type": "inject",
        "z": "7a83f86f.55d4f8",
        "name": "",
        "topic": "",
        "payload": "{}",
        "payloadType": "json",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 230,
        "y": 560,
        "wires": [
            [
                "b96df551.e84528"
            ]
        ]
    },
    {
        "id": "e2cfaaa6.081f68",
        "type": "http request",
        "z": "7a83f86f.55d4f8",
        "name": "POST /auth/token",
        "method": "POST",
        "ret": "txt",
        "url": "http://localhost:1880/auth/token",
        "tls": "",
        "x": 570,
        "y": 560,
        "wires": [
            [
                "ec48a95e.ec3ee8"
            ]
        ]
    },
    {
        "id": "b96df551.e84528",
        "type": "change",
        "z": "7a83f86f.55d4f8",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload.client_id",
                "pt": "msg",
                "to": "node-red-editor",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "payload.grant_type",
                "pt": "msg",
                "to": "password",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "payload.scope",
                "pt": "msg",
                "to": "*",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "payload.username",
                "pt": "msg",
                "to": "CHANGE_ME!",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "payload.password",
                "pt": "msg",
                "to": "CHANGE_ME!",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 380,
        "y": 560,
        "wires": [
            [
                "e2cfaaa6.081f68"
            ]
        ]
    },
    {
        "id": "d5b253f4.a73b9",
        "type": "change",
        "z": "7a83f86f.55d4f8",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "token",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1040,
        "y": 560,
        "wires": [
            [
                "672dcc9f.b60984"
            ]
        ]
    },
    {
        "id": "ec48a95e.ec3ee8",
        "type": "json",
        "z": "7a83f86f.55d4f8",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 730,
        "y": 560,
        "wires": [
            [
                "77702c60.df33e4"
            ]
        ]
    },
    {
        "id": "df2e5d9c.3664a",
        "type": "http request",
        "z": "7a83f86f.55d4f8",
        "name": "GET /flows",
        "method": "GET",
        "ret": "txt",
        "url": "http://localhost:1880/flows",
        "tls": "",
        "x": 630,
        "y": 660,
        "wires": [
            [
                "d8494003.bc263",
                "398be1ed.e0ffce"
            ]
        ]
    },
    {
        "id": "672dcc9f.b60984",
        "type": "change",
        "z": "7a83f86f.55d4f8",
        "name": "",
        "rules": [
            {
                "t": "delete",
                "p": "headers",
                "pt": "msg"
            },
            {
                "t": "set",
                "p": "headers.Authorization",
                "pt": "msg",
                "to": "token.access_token",
                "tot": "flow"
            },
            {
                "t": "set",
                "p": "headers.Node-RED-API-Version",
                "pt": "msg",
                "to": "v1",
                "tot": "str"
            },
            {
                "t": "delete",
                "p": "statusCode",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "filename",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "responseUrl",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 440,
        "y": 660,
        "wires": [
            [
                "df2e5d9c.3664a",
                "b699581d.56b368"
            ]
        ]
    },
    {
        "id": "b699581d.56b368",
        "type": "debug",
        "z": "7a83f86f.55d4f8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "x": 590,
        "y": 700,
        "wires": []
    },
    {
        "id": "398be1ed.e0ffce",
        "type": "change",
        "z": "7a83f86f.55d4f8",
        "name": "",
        "rules": [
            {
                "t": "delete",
                "p": "headers",
                "pt": "msg"
            },
            {
                "t": "set",
                "p": "headers.Authorization",
                "pt": "msg",
                "to": "token.access_token",
                "tot": "flow"
            },
            {
                "t": "set",
                "p": "headers.Node-RED-API-Version",
                "pt": "msg",
                "to": "v1",
                "tot": "str"
            },
            {
                "t": "delete",
                "p": "statusCode",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "filename",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "responseUrl",
                "pt": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 820,
        "y": 660,
        "wires": [
            [
                "f03c48f9.385fc8"
            ]
        ]
    },
    {
        "id": "ddff717.ad4279",
        "type": "comment",
        "z": "7a83f86f.55d4f8",
        "name": "Change user/pass below",
        "info": "",
        "x": 380,
        "y": 520,
        "wires": []
    },
    {
        "id": "d8494003.bc263",
        "type": "debug",
        "z": "7a83f86f.55d4f8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "x": 770,
        "y": 700,
        "wires": []
    },
    {
        "id": "77702c60.df33e4",
        "type": "function",
        "z": "7a83f86f.55d4f8",
        "name": "Bearer",
        "func": "msg.payload.access_token = \"Bearer \" + msg.payload.access_token\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 870,
        "y": 560,
        "wires": [
            [
                "d5b253f4.a73b9"
            ]
        ]
    }
]

Any volunteer to help?

Hi @hugobox

I've just tested your flow - up to the GET (I cut the wire going to the POST as I didn't want to screw up my local flows... :wink: ) - and it worked fine (once I put my username and password in the first Change node).

So not sure what to suggest, other than check you've not typo'd your username/password.

Ok! Go it working! My bad! I tried on a different setup, the GET part is now working so probably a password typo, but the POST part was throwing errors and then I found that the http GET request was outputting as a string instead of JSON.

[
    {
        "id": "2756ff49.7a67",
        "type": "debug",
        "z": "7a83f86f.55d4f8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "x": 1150,
        "y": 660,
        "wires": []
    },
    {
        "id": "b93f6d0a.9aca3",
        "type": "inject",
        "z": "7a83f86f.55d4f8",
        "name": "",
        "topic": "",
        "payload": "{}",
        "payloadType": "json",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 230,
        "y": 560,
        "wires": [
            [
                "b96df551.e84528"
            ]
        ]
    },
    {
        "id": "e2cfaaa6.081f68",
        "type": "http request",
        "z": "7a83f86f.55d4f8",
        "name": "POST /auth/token",
        "method": "POST",
        "ret": "txt",
        "url": "http://localhost:1880/auth/token",
        "tls": "",
        "x": 570,
        "y": 560,
        "wires": [
            [
                "ec48a95e.ec3ee8"
            ]
        ]
    },
    {
        "id": "b96df551.e84528",
        "type": "change",
        "z": "7a83f86f.55d4f8",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload.client_id",
                "pt": "msg",
                "to": "node-red-editor",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "payload.grant_type",
                "pt": "msg",
                "to": "password",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "payload.scope",
                "pt": "msg",
                "to": "*",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "payload.username",
                "pt": "msg",
                "to": "CHANGE_ME!",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "payload.password",
                "pt": "msg",
                "to": "CHANGE_ME!",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 380,
        "y": 560,
        "wires": [
            [
                "e2cfaaa6.081f68"
            ]
        ]
    },
    {
        "id": "d5b253f4.a73b9",
        "type": "change",
        "z": "7a83f86f.55d4f8",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "token",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1040,
        "y": 560,
        "wires": [
            [
                "672dcc9f.b60984"
            ]
        ]
    },
    {
        "id": "ec48a95e.ec3ee8",
        "type": "json",
        "z": "7a83f86f.55d4f8",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 730,
        "y": 560,
        "wires": [
            [
                "77702c60.df33e4"
            ]
        ]
    },
    {
        "id": "df2e5d9c.3664a",
        "type": "http request",
        "z": "7a83f86f.55d4f8",
        "name": "GET /flows",
        "method": "GET",
        "ret": "obj",
        "url": "http://localhost:1880/flows",
        "tls": "",
        "x": 630,
        "y": 660,
        "wires": [
            [
                "398be1ed.e0ffce"
            ]
        ]
    },
    {
        "id": "672dcc9f.b60984",
        "type": "change",
        "z": "7a83f86f.55d4f8",
        "name": "",
        "rules": [
            {
                "t": "delete",
                "p": "headers",
                "pt": "msg"
            },
            {
                "t": "set",
                "p": "headers.Authorization",
                "pt": "msg",
                "to": "token.access_token",
                "tot": "flow"
            },
            {
                "t": "set",
                "p": "headers.Node-RED-API-Version",
                "pt": "msg",
                "to": "v1",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 440,
        "y": 660,
        "wires": [
            [
                "df2e5d9c.3664a"
            ]
        ]
    },
    {
        "id": "398be1ed.e0ffce",
        "type": "change",
        "z": "7a83f86f.55d4f8",
        "name": "",
        "rules": [
            {
                "t": "delete",
                "p": "headers",
                "pt": "msg"
            },
            {
                "t": "set",
                "p": "headers.Authorization",
                "pt": "msg",
                "to": "token.access_token",
                "tot": "flow"
            },
            {
                "t": "set",
                "p": "headers.Node-RED-API-Version",
                "pt": "msg",
                "to": "v1",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 820,
        "y": 660,
        "wires": [
            [
                "f03c48f9.385fc8"
            ]
        ]
    },
    {
        "id": "ddff717.ad4279",
        "type": "comment",
        "z": "7a83f86f.55d4f8",
        "name": "Change user/pass below",
        "info": "",
        "x": 380,
        "y": 520,
        "wires": []
    },
    {
        "id": "77702c60.df33e4",
        "type": "function",
        "z": "7a83f86f.55d4f8",
        "name": "Bearer",
        "func": "msg.payload.access_token = \"Bearer \" + msg.payload.access_token\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 870,
        "y": 560,
        "wires": [
            [
                "d5b253f4.a73b9"
            ]
        ]
    },
    {
        "id": "f03c48f9.385fc8",
        "type": "http request",
        "z": "7a83f86f.55d4f8",
        "name": "POST /flows",
        "method": "POST",
        "ret": "txt",
        "url": "http://localhost:1880/flows",
        "tls": "",
        "x": 1010,
        "y": 660,
        "wires": [
            [
                "2756ff49.7a67"
            ]
        ]
    }
]