Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 424 Vote(s) - 3.55 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Pass customfields in c# whmcs

#1
I want to add the customfields in add order api. How to create an array like that: "an array of base64 encoded serialized array of product custom field values"


[To see links please register here]


I have tried with


``` lang-c#
Dictionary<string, string> customfiled = new Dictionary<string, string>();

customfiled.Add("1", "Hello");

var tt2 = JsonConvert.SerializeObject(customfiled);

string str =Base64Encode(tt2);

```
Reply

#2
I have created a class that will hold the list of key/values serialized as JSON.

Here is the class:

```
class ArrayOfBase64Array
{
// serialized JSON
private List<string> list = new List<string>();

public void Add(NameValueCollection collection)
{
foreach(var key in collection.AllKeys)
{
this.Add(key, collection[key]);
}
}

public void Add<T>(string key, T value) {
var dict = new Dictionary<string,T>();
dict.Add(key, value);
var json = JsonConvert.SerializeObject(dict);
list.Add(Base64Encode(json));
}

public string[] ToArray()
{
return list.ToArray();
}

string Base64Encode(string value)
{
return Convert.ToBase64String(Encoding.UTF8.GetBytes(value));
}
}
```

The AddOrder payload expects a shape that matches this C# class:

```
// lots of fields omitted for brevity
class AddOrder
{
public string action {get;set;}
public string[] domain {get;set;}
public string[] customfields {get;set;}
}
```

To create an AddOrder instance with customfields you can now do this:

```
// create an AddOrder instance
var addOrder = new AddOrder
{
action = "AddOrder",
domain = new [] {"one.example.com", "two.example.com"}
};

// build our customfields collection
var cfarray = new ArrayOfBase64Array();
cfarray.Add("1", "FuBar");
cfarray.Add("2", 999);
cfarray.Add("3", true);
cfarray.Add("4", new JObject(new JProperty("Foo", 4711.42)));

// or if you have a namevaluecollection
var nvc = new NameValueCollection { {"5", "test namevalue 1"}, {"6", "another value"} };
cfarray.Add(nvc);

// store the customfields as an array of strings
addOrder.customfields = cfarray.ToArray();
```

This is what the data looks like when POST-ed to the server:

```JSON
{ "action":"AddOrder",
"domain":["one.example.com","two.example.com"],
"customfields":[
"eyIxIjoiRnVCYXIifQ==",
"eyIyIjo5OTl9",
"eyIzIjp0cnVlfQ==",
"eyI0Ijp7IkZvbyI6NDcxMS40Mn19",
"eyI1IjoidGVzdCBuYW1ldmFsdWUgMSJ9",
"eyI2IjoiYW5vdGhlciB2YWx1ZSJ9"]
}
```

And this is what is in each of the encoded base64 strings:

```JSON
{"1":"FuBar"}
{"2":999}
{"3":true}
{"4":{"Foo":4711.42}}
{"5":"test namevalue 1"}
{"6":"another value"}
```
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through