May 012016
 

I am creating an interface to Constant Contact. I need to get the list numbers the company uses.

So I need to call the following viagra sans-serif; font-size: 13px; line-height: 32px; background-color: #eeeeee;”>https://api.constantcontact.com/v2/lists

The resulting JSON looks like this

[
{
"id": "1",
"name": "General Interest",
"status": "ACTIVE",
"createddate": "2013-03-11T20:37:28.000Z",
"modifieddate": "2013-03-11T20:41:42.000Z",
"contactcount": 143
},
{
"id": "2",
"name": "Great News!",
"status": "ACTIVE",
"createddate": "2012-12-19T21:33:22.000Z",
"modifieddate": "2013-02-01T17:54:43.000Z",
"contactcount": 53
},
{
"id": "3",
"name": "Monthly Specials!",
"status": "ACTIVE",
"createddate": "2012-12-19T21:33:50.000Z",
"modifieddate": "2013-02-01T17:54:43.000Z",
"contactcount": 375
},
{
"id": "4",
"name": "Tips, Tricks, & Fun!",
"status": "HIDDEN",
"createddate": "2012-12-19T21:33:50.000Z",
"modifieddate": "2013-02-01T17:54:43.000Z",
"contactcount": 2
}
]

The problem with this JSON is that when I run the wizard to create the schema, I get the following error

I essentially need to add a header, and give it a name

I created a String Resource called EnhancedFormat and the value is {{“{0}”:{1}}}

Here is the pipeline code (took me about 10 minutes to write)

using CCListModifier.Properties;
using Microsoft.BizTalk.Component.Interop;
using Microsoft.BizTalk.Message.Interop;
using System;
using System.Collections;
using System.IO;
using System.Text;

namespace ConstantContact
{
[ComponentCategory(CategoryTypes.CATIDPipelineComponent)]
[ComponentCategory(CategoryTypes.CATIDDecoder)]
[System.Runtime.InteropServices.Guid("7CC58BBC-2DC4-48AC-976B-1E1E4B98FD4D")]
public class JSONFixer : Microsoft.BizTalk.Component.Interop.IBaseComponent,
Microsoft.BizTalk.Component.Interop.IComponent,
Microsoft.BizTalk.Component.Interop.IPersistPropertyBag,
Microsoft.BizTalk.Component.Interop.IComponentUI
{
private string rootNode = null;
public string RootNode
{
get { return rootNode; }
set { rootNode = value; }
}
public IntPtr Icon
{
get { return IntPtr.Zero; }
}
public IEnumerator Validate(object projectSystem)
{
if (projectSystem == null)
throw new System.ArgumentNullException("No project system");
IEnumerator enumerator = null;
ArrayList strList = new ArrayList();
try
{
}
catch (Exception e)
{
strList.Add(e.Message);
enumerator = strList.GetEnumerator();
}
return enumerator;
}
public void GetClassID(out Guid classID)
{
classID = new System.Guid("7CC58BBC-2DC4-48AC-976B-1E1E4B98FD4D");
}
public void InitNew()
{}
public void Load(IPropertyBag propertyBag, int errorLog)
{
string val = (string)ReadPropertyBag(propertyBag, "RootNode");
if (val != null) rootNode = val;
}
private static object ReadPropertyBag(IPropertyBag propertyBag, string propName)
{
object val = null;
try
{
propertyBag.Read(propName, out val, 0);
}

catch (System.ArgumentException)
{
return val;
}
catch (Exception ex)
{
throw new ApplicationException(ex.Message);
}
return val;
}
public void Save(IPropertyBag propertyBag, bool clearDirty, bool saveAllProperties)
{
object val = (object)rootNode;
WritePropertyBag(propertyBag, "RootNode", val);
}
private static void WritePropertyBag(IPropertyBag propertyBag, string propName, object val)
{
try
{
propertyBag.Write(propName, ref val);
}
catch (Exception ex)
{
throw new ApplicationException(ex.Message);
}
}
public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
{
pInMsg.BodyPart.Data = EnhanceMessage(pInMsg.BodyPart.Data);
return pInMsg;
}
private Stream EnhanceMessage(Stream stream)
{
StreamReader reader = new StreamReader(stream);
string text = reader.ReadToEnd();
text = string.Format(Resources.EnhancedFormat, RootNode, text);
byte[] byteArray = Encoding.UTF8.GetBytes(text);
MemoryStream resultingStream = new MemoryStream(byteArray);
resultingStream.Position = 0;
return resultingStream;
}
public string Description
{
get { return "Enhance JSON Pipeline Component"; }
}
public string Name
{
get { return "Enhance JSON"; }
}
public string Version
{
get { return "1.0"; }
}
}

}

Here is the pipeline configuration

So when the pipeline executes it adds {“List”: to the beginning and } to the end

So here is the resulting xml

<?xml version="1.0" encoding="utf-8"?>
<ns0:Response xmlns:ns0="http://ConstantContactDefinition.ListOfLists">
<List>
<id>1</id>
<name>General Interest</name>
<status>ACTIVE</status>
<created_date>2013-03-11T20:37:28Z</created_date>
<modified_date>2013-03-11T20:41:42Z</modified_date>
<contact_count>143</contact_count>
</List>
<List>
<id>2</id>
<name>Great News!</name>
<status>ACTIVE</status>
<created_date>2012-12-19T21:33:22Z</created_date>
<modified_date>2013-02-01T17:54:43Z</modified_date>
<contact_count>53</contact_count>
</List>
<List>
<id>3</id>
<name>Monthly Specials!</name>
<status>ACTIVE</status>
<created_date>2012-12-19T21:33:50Z</created_date>
<modified_date>2013-02-01T17:54:43Z</modified_date>
<contact_count>375</contact_count>
</List>
<List>
<id>4</id>
<name>Tips, Tricks, &amp; Fun!</name>
<status>HIDDEN</status>
<created_date>2012-12-19T21:33:50Z</created_date>
<modified_date>2013-02-01T17:54:43Z</modified_date>
<contact_count>2</contact_count>
</List>
</ns0:Response>

Sorry, the comment form is closed at this time.