Setting Global Configuration Segment Does Not Store Content

Hello,

I’m updating an extension to use a ‘global’ segment for the configuration service vs. a ‘broadcaster’ segment (which we were previously setting with the helper method ‘set’). I understand that setting the ‘global’ segment requires an EBS and hitting the API directly.

So, I’ve moved the call to the ‘https://api.twitch.tv/extensions/client-id/configurations’ endpoint to my (testing) EBS, which uses the Color Cycler/Hello World boilerplate for setting the JWT.

The call is made successfully (204 response), but the actual content does not appear to be saved (or event successfully stored). I try to view it in the rig, as well as by logging ‘twitch.configuration.global’ in my viewer.js file (on the frontend), and it’s undefined.

Here’s my code:

 function makeServerToken() {
  const payload = {
    exp: Math.floor(Date.now() / 1000) + serverTokenDurationSec,
    user_id: ownerId, 
    role: 'external',
    pubsub_perms: {
      send: ['*'],
    },
  };
  return jsonwebtoken.sign(payload, secret, { algorithm: 'HS256' });
}

function setGlobalConfig() {
    const headers = {
      'Client-ID': client_id,
      'Content-Type': 'application/json',
      'Authorization': bearerPrefix + makeServerToken(),
    };

    const payload = JSON.stringify({
        "segment":"global",
        "content":{"foo":"bar"}
    });

    request(
      `https://api.twitch.tv/extensions/${client_id}/configurations/`,
      {
        method: 'PUT',
        headers: headers,
        body: payload
      }
      , (err, res) => {
        if (err) {
          console.log(STRINGS.messageSendError, err);
        } else {
          console.log(res);
          verboseLog(STRINGS.pubsubResponse, res.statusCode);
        }
      });
}

Any idea why the data is not being stored?

Thanks for the help.

The rig does not automatically refresh the configuration service at that point.
Can you try to get the global segment of your configuration service, from the “configuration service” tab of your extension in the rig :)?

If you want to have the direct update you can test on the Twitch website in local test mode :slight_smile:

Thanks for the reply @Breci.

Regarding the refreshing of the config service in the rig, I noticed that it wasn’t refreshing automatically and so I would stop and restart the backend, refresh the manifest, and even close and reopen the project in the rig to attempt to refresh the config service. This actually worked when I was setting the ‘broadcast’ segment previously, but obviously has not worked for the ‘global’ segment.

I also have attempted to view the global segment in the “configuration service” tab, but there’s no option to “fetch configuration” like there is with developer/broadcaster. So, perhaps I’m not doing it correctly. But when I attempt to view the global segment content in that tab, it’s always empty.

When you say “test on the Twitch website in local test mode” do you mean upload the assets to hosted test, and then view it there? Or is there a way to test on the Twitch website without uploading to hosted test?

For the configuration service, if you get a 204 code response it should have worked. Make sure the content you send is not undefined, it can happen that you miss a small detail in your code :smiley:

You can do local test on the Twitch website. Just install the extension on your channel/test channel and it will be linked to the url you specified in your configuration for local testing. The rig only copy what twitch do.

Thanks again @Breci.

I updated my code to see if hitting the API directly would allow me to fetch the global segment content I’m setting. This actually works and I can verify that the content is being set correctly. Here’s that code:

function fetchGlobalConfig() {

    const headers = {
      'Client-ID': client_id,
      'Content-Type': 'application/json',
      'Authorization': bearerPrefix + makeServerToken(),
    };

    request(
      `https://api.twitch.tv/extensions/${client_id}/configurations/segments/global`,
      {
        method: 'GET',
        headers: headers
      }
      , (err, res) => {
        if (err) {
          console.log(STRINGS.messageSendError, err);
        } else {
            let respBody = JSON.parse(res.body);
            let globalConfig = respBody["global:"];
            let content = globalConfig.record.content;
            console.log(content);
        }
      });
}

However, when I attempt to get the configuration content using the helper function on the frontend, the content is still undefined. Perhaps, this is because I’m testing locally (?) and it will work as expected when I move to hosted test.

Anyways, do you see any issues with how I’m fetching the content from the global config in my code above? The “respBody[“global:”]” makes me a little nervous, but that’s how the response body object is structured.

I also notice that the maximum requests per minute to the endpoint above is 20, so that makes me a little nervous as well.

Do you have any other suggestions here, or should this be an adequate method for fetching the global configuration content?

Thanks again for all your help.

There was an update on the developer rig to fix the problem with the configuration service. Can you try again :smiley: ?

Make sure you are running at least version 1.1.4 of the Developer Rig. If you are running a version older than 1.1.1, it will not update automatically. In that case, please download it from https://dev.twitch.tv/docs/extensions/rig/#starting-up-the-rig.