0

I am writing a program in nodejs using the request-promise-native module to create a startup script,receive the script ID then create a server and apply the script ID, however even after gathering the script ID and passing it to the request to create the server it does not get applied. I have made sure that the value of the variable I am passing for the scriptID is in the correct form of data type but it still seems not to work for some reason

var scriptRequest = require('request-promise-native');
var serverRequest = require('request-promise-native');
var headers = {
    'API-Key': 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
};

var scriptOptions = {
    url: "https://api.vultr.com/v1/startupscript/create",
    method: "POST",
    headers: headers,
    form: {
    name: "test script",
    script: "#!/bin/bash \napt-get update (not the actual script, just shortened it since the script itself is long and as of now the vultr server doesn't even make it this far)"}
};

var serverOptions = {
    url: 'https://api.vultr.com/v1/server/create',
    method: 'POST',
    headers: headers,
    form: {
        DCID: '6',
        VPSPLANID: '202',
        OSID: '215',
        SCRIPTID: scriptResponse
    }
}; 

var scriptResponse;

async function main(){
    const response = await scriptRequest({...scriptOptions, json:true})
    const json = response.SCRIPTID
    scriptResponse = json
    await serverRequest(serverOptions)
}

main() 

as you can see I have had to make the scriptRequest variable global, if I try to set it in the main function it gives me an undefined error in the serverOptions block

EDIT: just to clarify, the script ID I want to apply to the scriptResponse variable is returned upon making the scriptRequest post request

0 Answers0