Using apigee-edge-js to bulk-create target servers

Hello!

My name is Paweł, I'm new to Apigee community and I need some help.

I'm using the apigee-edge-js tools to try bulk-create target servers from a json file, for tests in the public cloud. @Dino-at-Google, I have found in your GitHub account such a piece of code for creating target servers:

const edgejs = require('apigee-edge-js');
const apigeeEdge = edgejs.edge;
var options = {org: 'MyOrg', netrc: true, no_token:true, verbosity: 1 };
apigeeEdge.connect(options)
  .then ( (org) => {
    console.log('org: ' + org.conn.orgname);
    return org.targetservers.create({
      environment : 'test',
      target : {
        name : 'targetserver1',
        host: "api.example.com",
        port: 8080,
        sSLInfo : { enabled : true }
      }
    });
  })
  .catch ( (e) => {
    console.log('error: ' + e.stack);
  });

I have a json file (array of objects) like this:

[
    {
        "name": "server1",
        "host": "www.mocky.io",
        "port": "80",
        "isEnabled": "true",
        "sSLInfo": "true"
    },
	...
]

Just for testing purposes, I have enabled the option "no_token" and set it to true in the object "options".

I constantly get the same type of error:

TypeError: Cannot read property 'headers' of undefined at safeJsonParse (/home/tutkapaw/apigee-edge/apigee_createTS/node_modules/apigee-edge-js/lib/common.js:60:39)

At the point where this error occurs is something like:

  function safeJsonParse(response, body) {
    let isJson = jsonRe.test(response.headers["content-type"]);
    // this simple approach does not work because the
    // Edge API sometimes claims application/json erroneously.

1. Since the property "headers" of undefined cannot be read, do I have to input some kind of body into the request? If so, how can I do that?

2. What does it mean "Edge API sometimes claims application/json erroneously."? Can this be changed? If so, where can the code be modified?

Responses with examples how to use this tool would be much appreciated, as with this one tool I can't find any.

Cheers!

PS. If I'm asking dumb questions, or my questions aren't precise enough, please do tell me so. I'll take no offense.

0 1 200
1 REPLY 1

Let me look.