Beanymattd
Member
- Joined
- Oct 12, 2023
- Messages
- 6
- Programming Experience
- Beginner
Good morning,
I have a folder full of json format files which need to be sent via C# inside a script task inside SSIS to an API. The SSIS will loop through (foreach it setup) and send each file.
Below is the format of all the files(all same format but different values etc):
Can anybody assist or point me in the right direction on how to do this please?
I've been digging around online and found the following example starting point. Not sure if this can be adapted accordingly? Any help is appreciated.
I have a folder full of json format files which need to be sent via C# inside a script task inside SSIS to an API. The SSIS will loop through (foreach it setup) and send each file.
Below is the format of all the files(all same format but different values etc):
Json:
"Time":"2018-10-21T00:08:03",
"Control_Code": "JKX",
"metrics": [
{
"Metric": 3721,
"Organisation":"AD450",
"Value": 20,
"Datetime":"2018-10-21T00:08:00"
},
{
"Metric": 1234,
"Organisation":"HG650",
"value": 88,
"datetime":"2018-10-21T00:08:00"
}
]
}
Can anybody assist or point me in the right direction on how to do this please?
I've been digging around online and found the following example starting point. Not sure if this can be adapted accordingly? Any help is appreciated.
C#:
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("baseurl");
var data = JObject.FromObject(new
{
name = "some value",
version = new {type = "some value", ver = 2}
});
var response = client.PostAsync("/urlpath",
new StringContent(JsonConvert.SerializeObject(data),
Encoding.UTF8, "application/json")).Result;
response.EnsureSuccessStatusCode();
var responseContent = await response.Content.ReadAsStringAsync();
dynamic json = JsonConvert.DeserializeObject(responseContent);
dynamic r = json.result;
result = r.someproperty.ToString().Equals("resultdata");
}