Make the request keeping the parameter string array - c#

I add 2 fields on my update request and I still didnt found a way to pass these 2 fields. I try someting link StringArrayContent, or ArrayContent that does not exist. I also try MultipartContent. How can I sent my request keeping downloadableInternal and downloadableExternal as string array?
The values usually are empty [] or ["original", "pdf"]
return new ShowpadUpdateAssetRequest()
{
ExternalFileUri = externalFileUri,
externalDate = externalDate,
externalId = externalId,
file = file,
name = name,
isDivisionShared = isDivisionShared,
downloadableInternal = downloadableInternal,
downloadableExternal = downloadableExternal,
Url = url,
Bearer = bearer,
ResponseType = typeof(ShowpadUpdateAssetResponse),
Content = new MultipartFormDataContent()
{
{new StringContent(externalId), nameof(externalId)},
{new StringContent(name), nameof(name)},
{new StringContent(externalDate), nameof(externalDate)},
{new StringContent(isDivisionShared.ToString()), nameof(isDivisionShared) },
{new StringContent(downloadableInternal.ToString()) ,nameof(downloadableInternal) },
{new StringContent(downloadableExternal.ToString()) ,nameof(downloadableExternal) },
{new ByteArrayContent((await fileContent.ReadAsByteArrayAsync())), nameof(file), file}
}
};

This depends on how your service handles the request. Here is an example you can try. You can also try to remove the [] suffix, some service may regard repetitive query parameters as an array.
var c = new MultipartFormDataContent();
var key = nameof(downloadableInternal) + "[]";
foreach(string data in downloadableInternal)
c.Add(new StringContent(data), key);

Related

Add and populate an IEnumerable property to an API call

I'm using an older 3rd party API to connect to a legacy system.
Here is the code:
AutoMaximizer.AuthUser yourCredentials = new AutoMaximizer.AuthUser
{
UserKey = "x1213"
};
AutoMaximizer.Pagers availableCars = new AutoMaximizer.Pagers
{
TotalCalls = 65,
Router = 91220
};
ISessionManagement s = new ManagementClient();
FactoryResponse response;
response = await s.GetAll(yourCredentials, new ListRequest
{
Pagers = availableCars,
SortIncreasing = true
});
It's working, but I want to add another property when I make the request.
The property is called Types and is a IEnumerable<Type>. The API docs state:
Types = Gets or sets an enumeration of types to include in the response.
And in the API reference, I found it:
public enum Type : int
{
[System.Runtime.Serialization.EnumMemberAttribute()]
Auto = 0,
[System.Runtime.Serialization.EnumMemberAttribute()]
Truck = 1,
[System.Runtime.Serialization.EnumMemberAttribute()]
Motorcycle = 2
}
But I'm not quite sure how to add it to the GetAll method.
I tried adding this:
List<AutoMaximizer.Type> types = new List<AutoMaximizer.Type>();
types.Add(AutoMaximizer.Type.Auto);
types.Add(AutoMaximizer.Type.Truck);
types.Add(AutoMaximizer.Type.Motorcycle);
And then this:
response = await s.GetAll(yourCredentials, new ListRequest
{
Pagers = availableCars,
SortIncreasing = true,
Types = types
});
But that gives me this error:
Cannot implicitly convert type Systems.Collections.Generic.List<AutoMaximizer.Type> to AutoMaximizer.Type[]
I am not sure what to do now...
Is there a way to get this to work?
Thanks!
Read your error, it wants an array, not a list:
response = await s.GetAll(yourCredentials, new ListRequest
{
Pagers = availableCars,
SortIncreasing = true,
Types = new[] { Type.Auto, Type.Truck, Type.Motorcycle },
});
According to the error, the ListRequest is specifically looking for an array, not any generic collection. You can convert the list to an array:
response = await s.GetAll(yourCredentials, new ListRequest
{
Pagers = availableCars,
SortIncreasing = true,
Types = types.ToArray()
});
Or just use an array to begin with:
AutoMaximizer.Type[] types = new [] { AutoMaximizer.Type.Auto, AutoMaximizer.Type.Truck, AutoMaximizer.Type.Motorcycle };

Can you have a returnUrlRequest for a sender view generated from a bulk send?

I'm trying to create a workflow where a user can do a bulk send through docusign within my application. They would select the clients they want to send forms to for a signature, be presented with a sender view to specify what fields they require, send it off, then have it post back to my application in order to generate emails for embedded signing. However, currently, it doesn't return back to my application after the user has sent off the bulk request despite the return url request being set. Is this currently not possible with a bulk send request?
The following is just some code to generate the sender view url:
// Create envelope definition
var envelopeDefinition = new EnvelopeDefinition
{
EmailSubject = documentDesc,
Documents = new List<Document>(),
Recipients = new Recipients { Signers = new List<Signer> {
new Signer
{
Name = "Multi Bulk Recipient::signer",
Email = "multiBulkRecipients-signer#docusign.com",
RoleName = "signer",
RoutingOrder = "1",
Status = "sent",
DeliveryMethod = "Email",
RecipientId = "1",
RecipientType = "signer"
}
} },
CustomFields = new CustomFields()
{
TextCustomFields = new List<TextCustomField>()
{
new TextCustomField() {Name = "Client", Value = _config.DatabaseName},
new TextCustomField() {Name = "Server", Value = _config.DatabaseServer},
new TextCustomField() {Name = "DocId", Value = documentId.ToString()}
}
},
EnvelopeIdStamping = "true",
};
// Read a file from disk to use as a document.
byte[] fileBytes = File.ReadAllBytes("test.pdf");
// Add a document to the envelope
Document doc = new Document();
doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes);
doc.Name = "TestFile.pdf";
doc.DocumentId = "1";
envDef.Documents = new List<Document>();
envDef.Documents.Add(doc);
// Add each recipient and add them to the envelope definition
var recipients = new List<BulkSendingCopyRecipient>();
var recipients = new List<BulkSendingCopyRecipient> {
new BulkSendingCopyRecipient
{
Name = "Bob Ross",
Email = "bobross#happymistakes.com",
ClientUserId = "1234",
CustomFields = new List<string>()
{
"A custom field for internal use"
},
RoleName = "signer"
},
new BulkSendingCopyRecipient
{
Name = "Fred Rogers",
Email = "mrrogers#neighborhood.com",
ClientUserId = "5678",
CustomFields = new List<string>()
{
"Another custom field for internal use"
},
RoleName = "signer"
}
};
var bulkSendingCopy = new BulkSendingCopy
{
Recipients = recipients
};
var bulkCopies = new List<BulkSendingCopy>
{
bulkSendingCopy
};
var bulkSendingList = new BulkSendingList
{
BulkCopies = bulkCopies
};
bulkSendingList.Name = "A document name";
envelopeDefinition.Status = "created";
var envelopesApi = new EnvelopesApi(config);
var bulkEnvelopesApi = new BulkEnvelopesApi();
var createBulkListResult = bulkEnvelopesApi.CreateBulkSendList(AccountId, bulkSendingList);
envelopeDefinition.CustomFields.TextCustomFields.Add(
new TextCustomField
{
Name = "mailingListId",
Required = "false",
Show = "false",
Value = createBulkListResult.ListId //Adding the BULK_LIST_ID as an Envelope Custom Field
}
);
var envelopeSummary = envelopesApi.CreateEnvelope(AccountId, envelopeDefinition);
var options = new ReturnUrlRequest
{
ReturnUrl = HttpContext.Current.Request.Url.Scheme + "://" +
HttpContext.Current.Request.Url.Authority +
HttpContext.Current.Request.ApplicationPath +
"/SIP/ConfirmTagSendAndPublish.aspx?idockey=" + documentId
};
var senderView = envelopesApi.CreateSenderView(AccountId, envelopeSummary.EnvelopeId, options);
var senderViewInfo = new string[2];
senderViewInfo[0] = senderView.Url;
senderViewInfo[1] = envelopeSummary.EnvelopeId;
return senderViewInfo;
When the sender view comes up and you hit send it just takes me to the Sent tab in docusign
What I see after send
So in order for you to do the scenario you're asking to do, you will have to take a slightly different approach:
Generate a regular envelope in draft mode with the things you need.
Have user interact with it in embedded sending experience.
Generate a bulk using the CreateBulkList() method based on the envelope from #2 and the users you add like in your code.
(to do #3 you may need to copy custom fields etc. from the initial envelope to the one used for custom fields)

How to create complex filter in c# for Magento API

I am trying to create a complex filter in c# to get data from magento API. I already written the following code
MagentoService mservice = new MagentoService();
var mlogin = mservice.login("***", "****");
var result = mservice.storeList(mlogin);
var cpf = new complexFilter[2];
cpf[0] = new complexFilter
{
key = "created_in",
value = new associativeEntity
{
key = "in",
value = "website A"
}
};
cpf[1] = new complexFilter
{
key = "bv_customer_number",
value = new associativeEntity
{
key = "in",
value = "Not Approved"
}
};
var filters = new filters();
filters.complex_filter = cpf;
var result3 = mservice.customerCustomerList(mlogin, filters);
This code works perfect the only issue is I want to add the multiple values in my key = "created_in" with value = "website a", "website b"
Anyone got any ideas on how to properly pass multiple values for a single key?
I solved this problem by aggregating values into 1 value with ',' as separator:
new complexFilter
{
key = "created_in",
value = new associativeEntity
{
key = "in",
value = "websiteA,websiteB,websiteC"
}
};

Do I need to create a two-dimensional array to add reference data with an id column into Entity Framework?

I have the following code that I am using to create ContentType data:
var contentTypeNames = new[]
{
"Menu", // = 0,
"Article", // = 1,
"FavoritesList", // = 2,
"Topic", // = 6,
"List", // = 7,
"Dummy", // = 99
};
foreach (string contentTypeName in contentTypeNames)
{
_uow.ContentTypes.Add(
new ContentType
{
id = ??,
Name = contentTypeName
});
}
I need to somehow add the values after the comments in as id columns. Is there a simple way that I can do this? I was thinking to create a two dimensional array but maybe there is an easier way.
List<ContentType> contentTypes = new List<ContentType>();
//Fill Your List With Names and IDs
//Eg: contentTypes.Add(new ContentType(0,"Menu")) and so on and so forth then:
foreach (ContentType contentType in contentTypes )
{
_uow.ContentTypes.Add(contentType);
}

Amazon Product Advertising API - searching for multiple UPCs

Using the Amazon Product Advertising API I am searching for 2 different UPCs:
// prepare the first ItemSearchRequest
// prepare a second ItemSearchRequest
ItemSearchRequest request1 = new ItemSearchRequest();
request1.SearchIndex = "All";
//request1.Keywords = table.Rows[i].ItemArray[0].ToString();
request1.Keywords="9120031340270";
request1.ItemPage = "1";
request1.ResponseGroup = new string[] { "OfferSummary" };
ItemSearchRequest request2 = new ItemSearchRequest();
request2.SearchIndex = "All";
//request2.Keywords = table.Rows[i+1].ItemArray[0].ToString();
request2.Keywords = "9120031340300";
request2.ItemPage = "1";
request2.ResponseGroup = new string[] { "OfferSummary" };
// batch the two requests together
ItemSearch itemSearch = new ItemSearch();
itemSearch.Request = new ItemSearchRequest[] { request1,request2 };
itemSearch.AWSAccessKeyId = accessKeyId;
// issue the ItemSearch request
ItemSearchResponse response = client.ItemSearch(itemSearch);
foreach (var item in response.Items[0].Item)
{
}
foreach (var item in response.Items[1].Item)
{
}
Is it possible to combine these two separate requests into one request and just have the first request return 2 items by setting keywords = "9120031340256 and 9120031340270"
Does anyone know how to do this?
Do I need to specifically search the UPC?
From looking at the API docs I think you may want to use an ItemLookup if you want to get results for multiple UPCs.
ItemLookup itemLookup = new ItemLookup(){
AssociateTag = "myaffiliatetag-20"
};
itemLookup.AWSAccessKeyId = MY_AWS_ID;
ItemLookupRequest itemLookupRequest = new ItemLookupRequest();
itemLookupRequest.IdTypeSpecified = true;
itemLookupRequest.IdType = ItemLookupRequestIdType.UPC;
itemLookupRequest.ItemId = new String[] { "9120031340300", "9120031340270" };
itemLookupRequest.ResponseGroup = new String[] { "OfferSummary" };
itemLookup.Request = new ItemLookupRequest[] { itemLookupRequest };
ItemLookupResponse response = client.ItemLookup(itemLookup);
foreach(var item in response.Items[0])
{
//Do something...
Console.WriteLine(item.ItemAttributes.Title);
}
That being said, if you are not working with lookups by some ID (UPC, ASIN, etc) your original code of doing batched keyword searches appears to be only way to make multiple keyword searches in a single request (that I could find..). If doing keyword searches you could always make a ItemSearchRequest generator method to cut down on duplicate code when creating multiples.
You can use the following nuget
package.
PM> Install-Package Nager.AmazonProductAdvertising
Example
var authentication = new AmazonAuthentication("accesskey", "secretkey");
var client = new AmazonProductAdvertisingClient(authentication, AmazonEndpoint.US);
var result = await client.GetItemsAsync(new string[] { "B00BYPW00I", "B004MKNBJG" });

Categories