Skip to Content

Turn your connections into holiday cash with our new Customer Referral Program! Learn more

This documentation is for version 3.3 and earlier of Vinyl, the former name for App Builder. Access the latest documentation here.

Scripting example - Convert binary to response to text

This Plugin script example was used with a Microsoft Azure REST API, and works with a raw Binary response. The Plugin essentially converts the API endpoint response into something that Vinyl can consume/read.

For example, if the REST API endpoint returns something like:

"success"

Then the Plugin converts the response to something that Vinyl can read, like:

{
"Message": "success"
}

Script example

#r "Newtonsoft.Json.dll"
using System;
using System.Net.Http;
using Newtonsoft.Json;
// Read the response content
var messageBytes = await Response.Content.ReadAsByteArrayAsync();
var message = Convert.ToBase64String(messageBytes);
// Wrap the message in a json formatted text
message = JsonConvert.SerializeObject(new { Message = message });
// Replace the response content with the formatted json
Response.Content = new StringContent(message, null, "application/json");