I want to get the "offer-listing" using amazon API.
I have explored by myself but there is not clue to get it.
it would be nice if someone suggest me the API end point to get the offer-listing or alternative
You can either scrap the offering page or use the Amazon's Product's API and call:
GetLowestOfferListingsForSKU to get offer listing including your self(you can use $request->setExcludeMe(TRUE) to exclude your self)
GetMyPriceForSKU to get just your offer listing
This API calls will return Landing price,Shipping price,Listing price where Landing price is your selling price + shipping price. None of above API call includes seller's name or any identity, so if you'r after seller's name and selling price you better of scrapping the offering page.
Here is the code I used:
$asin amazon product's ASIN
$sku is amazon product's SKU
$pos_data array contains all Amazon API's credentials
$fba_check is 'Y' or 'N' whether the ASIN is FBA(Fulfilled by Amazon) or not
function init_pro_api($asin, $sku, $pos_data, $fba_check)
{
$try = 0;
while($try < 2)
{
$offers_list = "";
$AWS_ACCESS_KEY_ID = $pos_data['azn_access_key'];
$AWS_SECRET_ACCESS_KEY = $pos_data['azn_secret_access_key'];
$APPLICATION_NAME = $pos_data['azn_app_name'];
$APPLICATION_VERSION = $pos_data['azn_app_version'];
$MERCHANT_ID = $pos_data['azn_merchant_id'];
$MARKETPLACE_ID = $pos_data['azn_marketplace_id'];
$platform = $pos_data['azn_platform_variant'];
if($platform == "uk")
{
$serviceURL = "https://mws.amazonservices.co.uk/Products/2011-10-01";
}
else
$serviceURL = "https://mws-eu.amazonservices.com/Products/2011-10-01";
$DATE_FORMAT = "Y-m-d";
$config = array(
'ServiceURL' => $serviceURL,
'ProxyHost' => null,
'ProxyPort' => -1,
'MaxErrorRetry' => 3,
);
$service = new MarketplaceWebServiceProducts_Client($AWS_ACCESS_KEY_ID, $AWS_SECRET_ACCESS_KEY, $APPLICATION_NAME, $APPLICATION_VERSION, $config);
// Get My Price
$request = new MarketplaceWebServiceProducts_Model_GetMyPriceForSKURequest();
$request->setSellerId($MERCHANT_ID);
$request->setMarketplaceId($MARKETPLACE_ID);
$sku_list = new MarketplaceWebServiceProducts_Model_SellerSKUListType();
$sku_list->setSellerSKU($sku);
$request->setSellerSKUList($sku_list);
$my_offer = invokeGetMyPriceForSKU($service, $request, $fba_check);
// Get Other Sellers Lowest Offering Price
$request = new MarketplaceWebServiceProducts_Model_GetLowestOfferListingsForSKURequest();
$request->setSellerId($MERCHANT_ID);
$request->setMarketplaceId($MARKETPLACE_ID);
$request->setItemCondition("New");
$request->setExcludeMe(TRUE);
$sku_list = new MarketplaceWebServiceProducts_Model_SellerSKUListType();
$sku_list->setSellerSKU($sku);
$request->setSellerSKUList($sku_list);
$other_low_offers = invokeGetLowestOfferListingsForSKU($service, $request);
if($my_offer != "" or $my_offer != NULL)
{
$offers_list["MyOffer"] = $my_offer;
}
if($other_low_offers != "" or $other_low_offers != NULL)
{
$offers_list["OtherOffer"] = $other_low_offers;
}
if(isset($offers_list["OtherOffer"][0]))
if($offers_list["OtherOffer"][0] != "")
break;
$try++;
}
return $offers_list;
}
function invokeGetMyPriceForSKU(MarketplaceWebServiceProducts_Interface $service, $request, $fba_check)
{
try
{
$my_response_data = "";
$pre_check_xml_data = array();
$xml_feed_counter = 0;
$response = $service->GetMyPriceForSKU($request);
$dom = new DOMDocument();
$dom->loadXML($response->toXML());
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$xml_data = $dom->saveXML();
$doc = new DOMDocument;
$doc->preserveWhiteSpace = FALSE;
$doc->loadXML($xml_data);
$offer_length = $doc->getElementsByTagName('Offer')->length;
$fba_index = "";
$normal_index = "";
for($o = 0; $o < $offer_length; $o++)
{
$pre_check_xml_data[$o]["LandedPrice"] = $doc->getElementsByTagName('LandedPrice')->item($o)->lastChild->nodeValue;
$pre_check_xml_data[$o]["ListingPrice"] = $doc->getElementsByTagName('ListingPrice')->item($o)->lastChild->nodeValue;
$pre_check_xml_data[$o]["Shipping"] = $doc->getElementsByTagName('Shipping')->item($o)->lastChild->nodeValue;
$pre_check_xml_data[$o]["FulfillmentChannel"] = $doc->getElementsByTagName('FulfillmentChannel')->item($o)->nodeValue;
if($fba_check == "Y")
{
if($doc->getElementsByTagName('FulfillmentChannel')->item($o)->nodeValue == "AMAZON")
{
$fba_index = $o;
break;
}
}
elseif($fba_check == "N")
{
if($doc->getElementsByTagName('FulfillmentChannel')->item($o)->nodeValue == "MERCHANT")
{
$normal_index = $o;
break;
}
}
}
if($fba_check == "Y")
{
if($fba_index === "")
{
$my_response_data[0]["LandedPrice"] = "";
$my_response_data[0]["ListingPrice"] = "";
$my_response_data[0]["Shipping"] = "";
$my_response_data[0]["Fulfillment"] = "";
return $my_response_data;
}
else
{
$my_response_data[0] = $pre_check_xml_data[$fba_index];
return $my_response_data;
}
}
else
{
$my_response_data[0] = $pre_check_xml_data[$normal_index];
return $my_response_data;
}
}
catch(MarketplaceWebServiceProducts_Exception $ex)
{
echo("Caught Exception: " . $ex->getMessage() . "\n");
echo("Response Status Code: " . $ex->getStatusCode() . "\n");
echo("Error Code: " . $ex->getErrorCode() . "\n");
echo("Error Type: " . $ex->getErrorType() . "\n");
echo("Request ID: " . $ex->getRequestId() . "\n");
echo("XML: " . $ex->getXML() . "\n");
echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n");
}
}
function invokeGetLowestOfferListingsForSKU(MarketplaceWebServiceProducts_Interface $service, $request)
{
try
{
$response_data = "";
$counter = 0;
$response = $service->getLowestOfferListingsForSKU($request);
$getLowestOfferListingsForSKUResultList = $response->getGetLowestOfferListingsForSKUResult();
foreach($getLowestOfferListingsForSKUResultList as $getLowestOfferListingsForSKUResult)
{
if($getLowestOfferListingsForSKUResult->isSetProduct())
{
$product = $getLowestOfferListingsForSKUResult->getProduct();
if($product->isSetLowestOfferListings())
{
$lowestOfferListings = $product->getLowestOfferListings();
$lowestOfferListingList = $lowestOfferListings->getLowestOfferListing();
foreach($lowestOfferListingList as $lowestOfferListing)
{
if($lowestOfferListing->isSetQualifiers())
{
$qualifiers = $lowestOfferListing->getQualifiers();
if($qualifiers->isSetFulfillmentChannel())
{
$response_data[$counter]["Fulfilled_By"] = $qualifiers->getFulfillmentChannel();
}
if($qualifiers->isSetShippingTime())
{
$shippingTime = $qualifiers->getShippingTime();
if($shippingTime->isSetMax())
{
$response_data[$counter]["ShippingTime"] = $shippingTime->getMax();
}
}
}
if($lowestOfferListing->isSetPrice())
{
$price1 = $lowestOfferListing->getPrice();
if($price1->isSetLandedPrice())
{
$landedPrice1 = $price1->getLandedPrice();
if($landedPrice1->isSetAmount())
{
$response_data[$counter]["LandedPrice"] = $landedPrice1->getAmount();
}
}
if($price1->isSetListingPrice())
{
$listingPrice1 = $price1->getListingPrice();
if($listingPrice1->isSetAmount())
{
$response_data[$counter]["ListingPrice"] = $listingPrice1->getAmount();
}
}
if($price1->isSetShipping())
{
$shipping1 = $price1->getShipping();
if($shipping1->isSetAmount())
{
$response_data[$counter]["Shipping"] = $shipping1->getAmount() . "\n";
}
}
}
$counter++;
}
}
}
if($getLowestOfferListingsForSKUResult->isSetError())
{
$error = $getLowestOfferListingsForSKUResult->getError();
if($error->isSetMessage())
{
$response_data = $error->getMessage() . "\n";
}
}
}
return $response_data;
}
catch(MarketplaceWebServiceProducts_Exception $ex)
{
echo("Caught Exception: " . $ex->getMessage() . "\n");
echo("Response Status Code: " . $ex->getStatusCode() . "\n");
echo("Error Code: " . $ex->getErrorCode() . "\n");
echo("Error Type: " . $ex->getErrorType() . "\n");
echo("Request ID: " . $ex->getRequestId() . "\n");
echo("XML: " . $ex->getXML() . "\n");
}
}
You can use the Amazon MWS products API like Keyur states. They provide PHP, C#, and Java example code and it's easy to work with.
If you want real-time price change notifications on products you are currently selling, subscribe to the AnyOfferChangedNotification notification. They have example code for that too. http://docs.developer.amazonservices.com/en_US/notifications/Notifications_AnyOfferChangedNotification.html
I'm doing some stuff with this right now and, if it helps anyone, I'm using the Advertising API and have found that if you make a request like this:
String requestString = "Service=AWSECommerceService"
+ "&Version=2009-03-31"
+ "&Operation=ItemLookup"
+ "&AssociateTag=some-associate-tag"
+ "&ItemId=" + your-item-id
+ "&ResponseGroup=BrowseNodes,OfferFull,ItemAttributes";
then you can look at the XPath //detailpageurl and you should get what you were expecting.
Related
I wrote a bot in C#, I used Selenium.
Problem: When I start more threads at same time, the bot does the work in the first window. All of the e-mail addresses are being added to the "E-mail" textbox in the same window instead of one e-mail address per window.
But it should look like:
Start function: DivisionStart()
private void DivisionStart() {
foreach(var account in BotConfig.AccountList) {
while (CurrentBotThreads >= BotConfig.MaxLoginsAtSameTime) {
Thread.Sleep(1000);
}
StartedBotThreads++;
CurrentBotThreads++;
int startIndex = (StartedBotThreads * BotConfig.AdsPerAccount + 1) - BotConfig.AdsPerAccount - 1;
int stopIndex = BotConfig.AdsPerAccount * CurrentBotThreads;
if (stopIndex > BotConfig.ProductList.Count) {
stopIndex = BotConfig.ProductList.Count;
}
Debug.Print("Thread: " + StartedBotThreads);
var adList = GetAdListBy(startIndex, stopIndex);
foreach(var ad in adList) {
Debug.Print("Für thread: " + StartedBotThreads + " | Anzeige: " + ad.AdTitle);
}
Debug.Print("Parallel");
var ebayBotThread = new Thread(() => {
var botOptions = new IBotOptionsModel() {
CaptchaSolverApiKey = CaptchaSolverApiKey,
ReCaptchaSiteKey = "6LcZlE0UAAAAAFQKM6e6WA2XynMyr6WFd5z1l1Nr",
StartPageUrl = "https://www.ebay-kleinanzeigen.de/m-einloggen.html?targetUrl=/",
EbayLoginEmail = account.AccountEmail,
EbayLoginPassword = account.AccountPassword,
Ads = adList,
};
var ebayBot = new EbayBot(this, botOptions);
ebayBot.Start(StartedBotThreads);
Thread.Sleep(5000);
});
ebayBotThread.Start();
}
}
The class with function which will be executed in each thread:
using OpenQA.Selenium;
using Selenium.WebDriver.UndetectedChromeDriver;
using System.Diagnostics;
using TwoCaptcha.Captcha;
using System.Drawing;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Chrome.ChromeDriverExtensions;
namespace EbayBot
{
class EbayBot
{
public Selenium.Extensions.SlDriver Driver;
private WebDriverHelper DriverHelper;
private Bot Sender;
private bool CaptchaSolved = false;
public IBotOptionsModel Options;
public EbayBot(Bot sender, IBotOptionsModel options)
{
Sender = sender;
Options = options;
}
public void Start(int threadIndex)
{
var chromeOptions = new ChromeOptions();
/*if (Sender.BotConfig.EnableProxy)
{
chromeOptions.AddHttpProxy(
Options.Proxy.IpAddress,
Options.Proxy.Port,
Options.Proxy.Username,
Options.Proxy.Password
);
}*/
Driver = UndetectedChromeDriver.Instance(null, chromeOptions);
DriverHelper = new WebDriverHelper(Driver);
string status = "";
Debug.Print("Bot-Thread: " + threadIndex);
Driver.Url = Options.StartPageUrl + Options.EbayLoginEmail;
PressAcceptCookiesButton();
Login();
if (!CaptchaSolved) return;
Driver.Wait(3);
if (LoginError() || !IsLoggedIn())
{
status = "Login für '" + Options.EbayLoginEmail + "' fehlgeschlagen!";
Debug.Print(status);
Sender.ProcessStatus = new IStatusModel(status, Color.Red);
return;
}
else
{
status = "Login für '" + Options.EbayLoginEmail + "' war erfolgreich!";
Debug.Print(status);
Sender.ProcessStatus = new IStatusModel(status, Color.Green);
}
Driver.Wait(5);
BeginFillFormular();
}
private bool CookiesAccepted()
{
try
{
var btnAcceptCookies = Driver.FindElement(By.Id(Config.PageElements["id_banner"]));
return btnAcceptCookies == null;
}
catch (Exception)
{
return true;
}
}
private void PressAcceptCookiesButton()
{
DriverHelper.WaitForElement(Config.PageElements["id_banner"], "", 10);
if (CookiesAccepted()) return;
var btnAcceptCookies = Driver.FindElement(By.Id(Config.PageElements["id_banner"]));
btnAcceptCookies.Click();
}
private bool IsLoggedIn()
{
Debug.Print("Check if logged in already");
try
{
var userEmail = Driver.FindElement(By.Id("user-email")).Text;
return userEmail.ToLower().Contains(Options.EbayLoginEmail);
}
catch (Exception)
{
return false;
}
}
private bool LoginError()
{
try
{
var loginErrorH1 = Driver.FindElements(By.TagName("h1"));
return loginErrorH1[0].Text.Contains("ungültig");
}
catch (Exception)
{
return false;
}
}
private void Login()
{
if (IsLoggedIn()) return;
string status = "Anmelden bei " + Options.EbayLoginEmail + "...";
Debug.Print(status);
Sender.ProcessStatus = Sender.ProcessStatus = new IStatusModel(status, Color.DimGray);
Driver.Wait(5);
var fieldEmail = Driver.FindElement(By.Id(Config.PageElements["id_login_email"]));
var fieldPassword = Driver.FindElement(By.Id(Config.PageElements["id_login_password"]));
var btnLoginSubmit = Driver.FindElement(By.Id(Config.PageElements["id_login_button"]));
fieldEmail.SendKeys(Options.EbayLoginEmail);
Driver.Wait(4);
fieldPassword.SendKeys(Options.EbayLoginPassword);
SolveCaptcha();
if (!CaptchaSolved)
{
return;
}
Debug.Print("Clicking login button");
btnLoginSubmit.Click();
}
public void BeginFillFormular()
{
Debug.Print("Formular setup, Inserate: " + Options.Ads.Count);
foreach (var adData in Options.Ads)
{
Debug.Print("Setting up formular for " + adData.AdTitle);
var adFormular = new AdFormular(Driver, adData, Options);
adFormular._EbayBot = this;
adFormular.CreateAd(Sender);
// 10 seconds
Debug.Print("Nächstes Insert für " + adData.AdTitle);
}
}
public string GetSolvedCaptchaAnswer(string captchaUrl = "")
{
string code = string.Empty;
var solver = new TwoCaptcha.TwoCaptcha(Options.CaptchaSolverApiKey);
var captcha = new ReCaptcha();
captcha.SetSiteKey(Options.ReCaptchaSiteKey);
captcha.SetUrl(captchaUrl == "" ? Options.StartPageUrl : captchaUrl);
try
{
solver.Solve(captcha).Wait();
code = captcha.Code;
}
catch (AggregateException e)
{
Sender.ProcessStatus = new IStatusModel("Captcha Api-Fehler: " + e.InnerExceptions.First().Message, Color.Red);
Driver.Wait(10);
}
return code;
}
public void SolveCaptcha(string captchaUrl = "")
{
Debug.Print("Solving captcha...");
var solvedCaptchaAnswer = GetSolvedCaptchaAnswer(captchaUrl);
if (solvedCaptchaAnswer == string.Empty)
{
Debug.Print("Captcha konnte nicht gelöst werden");
Sender.ProcessStatus = new IStatusModel("Captcha konnte nicht gelöst werden", Color.Red);
CaptchaSolved = false;
Driver.Wait(10);
return;
}
CaptchaSolved = true;
Debug.Print("Captcha answer: " + solvedCaptchaAnswer);
Driver.ExecuteScript("document.getElementById('g-recaptcha-response').innerHTML = '" + solvedCaptchaAnswer + "'");
Debug.Print("Captcha solved!");
Driver.Wait(2);
}
}
}
If I remove the Thread.Sleep(5000); in the DivisionStart function it will work, but I need it I actually want to wait for a found proxy but I simulated it with Thread.Sleep
How can I solve my problem?
Thanks for any answer!
I fixed it.
I used UndetectedChromeDriver wich does not use different ports.
I use another Undetected driver now.
Thank you all
Below is the function where I am trying to execute a function in the background and then carry on without waiting for a result from it.
When debugging the task itself is executed but the actual function within it does not. The rest of the code then carries on like normal.
What could be the issue as there is no error produced after that to indicate otherwise?
This is on a page load.
public ActionResult ExceptionReport(int? id)
{
var ExceptionList = db.Invoices.Where(m => m.ExceptionFlag == true && m.GlobalInvoiceID == id);
if (ExceptionList.Count() == 0)
{
globalInvoice.Status = "Exception Verification";
db.Entry(globalInvoice).State = EntityState.Modified;
db.SaveChanges();
Task.Run(() => ExceptionFinalTests(globalInvoice)); //Function To run in the background
TempData["warning"] = "Verifying all exceptions fixed. A notification will be sent when the verifications are complete.";
return RedirectToAction("Index", "GlobalInvoices");
}
return View(ExceptionList);
}
private void ExceptionFinalTests(GlobalInvoice globalInvoice)
{
RunTests(globalInvoice, true);
decimal TotalPaymentAmount = db.Invoices.Where(m => m.GlobalInvoiceID == globalInvoice.Id).Sum(m => m.Invoice_Amount) ?? 0;
}
GlobalInvoicesController globalInvoicesController = new GlobalInvoicesController();
var ApproverList = globalInvoicesController.GetUserEmailsInRole(globalInvoice, "Reviewer");
globalInvoicesController.Dispose();
var exceptionExistCompulsoryTest = db.Invoices.Where(m => m.ExceptionFlag == true && m.GlobalInvoiceID == globalInvoice.Id);
if (exceptionExistCompulsoryTest.Count() > 0)
{
try
{
string baseUrl = ConfigurationManager.AppSettings["site"];
EmailExtension emailExtension = new EmailExtension();
foreach (var approver in ApproverList)
{
string approvalLink = baseUrl + "/Invoices/ExceptionReport/" + globalInvoice.Id;
StringBuilder mailbody = new StringBuilder();
mailbody.AppendFormat("Hi<br/>");
mailbody.AppendFormat("There are " + exceptionExistCompulsoryTest.Count() + " exceptions for invoice #" + globalInvoice.Id + "that need attention before proceeding. - <a href='" + approvalLink + "'>Click Here</a> <br/><br/>");
mailbody.AppendFormat("Exception Count: {0}<br/>", exceptionExistCompulsoryTest.Count());
mailbody.AppendFormat("Invoice Amount: {0}<br/>", TotalPaymentAmount.ToString("C"));
mailbody.AppendFormat("Reviewed By: {0} <br/>", "");
mailbody.AppendFormat("Approved By: {0} <br/>", "");
EmailVM emailVM = new EmailVM()
{
Subject = "Invoice - #" + globalInvoice.Id,
EmailAddress = approver,
Message = mailbody.ToString()
};
emailExtension.SendEmail(emailVM);
}
}
catch (Exception ex)
{
LogWriter.WriteLog(ex.Message);
LogWriter.WriteLog(ex.StackTrace);
}
}
}
private void RunTests(GlobalInvoice globalInvoice, bool retestFlag = false)
{
List<Invoice> invoices;
var vendorTests = globalInvoice.Vendor.VendorTests;
string[] testsToRun = vendorTests.Split(',');
if (retestFlag == true)
{
if (globalInvoice.Vendor.VendorHasHierarchy == true)
{
testsToRun = new string[] { "Account Number", "Hierarchy" };
}
else
{
testsToRun = new string[] { "Account Number" };
}
}
using (var context = new MyContext())
{
invoices = context.Invoices.Where(m => m.GlobalInvoiceID == globalInvoiceToTestID).ToList();
}
foreach (var test in testsToRun)
{
if (test == "Account Number")
{
LogWriter.WriteLog("Starting Account Number Check : Invoice Batch ID - " + globalInvoice.Id);
AccountNumberCheck(invoices, globalInvoice.VendorID);
LogWriter.WriteLog("Account Number Check Complete : Invoice Batch ID - " + globalInvoice.Id);
}
if (test == "Hierarchy")
{
LogWriter.WriteLog("Starting Hierarchy Check : Invoice Batch ID - " + globalInvoice.Id);
BillingHierarchyCheck(invoices);
LogWriter.WriteLog("Hierarchy Check Complete : Invoice Batch ID - " + globalInvoice.Id);
}
}
}
I'm working with a third-party who are posting information via HTTP POST to a .NET site I host locally. The POST is successful but I need to have the site send a success/failure response to the POST.
I have looked around but have been unable to find any suggestions to meet this need.
Please let me know if I can further clarify anything.
Thank you.
Edit: To include the code.
if (!string.IsNullOrEmpty(nvc["id"]) )
{
/* Populate the variables with the POST data
* Check first that the data is not empty or null */
if (!string.IsNullOrEmpty(nvc["id"]))
{ leadID = nvc["id"]; }
if (!string.IsNullOrEmpty(nvc["FN"]))
{ fn = nvc["FN"]; }
if (!string.IsNullOrEmpty(nvc["LN"]))
{ ln = nvc["LN"]; }
if (!string.IsNullOrEmpty(nvc["EMAIL"]))
{ email = nvc["EMAIL"]; }
if (!string.IsNullOrEmpty(nvc["PHONE"]))
{ phone = nvc["PHONE"]; }
if (!string.IsNullOrEmpty(nvc["ADDRESS"]))
{ address = nvc["ADDRESS"]; }
if (!string.IsNullOrEmpty(nvc["CITY"]))
{ city = nvc["CITY"]; }
if (!string.IsNullOrEmpty(nvc["STATE"]))
{ state = nvc["STATE"]; }
if (!string.IsNullOrEmpty(nvc["ZIP"]))
{ zip = nvc["ZIP"]; }
if (!string.IsNullOrEmpty(nvc["GENDER"]))
{ gender = nvc["GENDER"]; }
if (!string.IsNullOrEmpty(nvc["BIRTHDAY"]))
{ birthday = nvc["BIRTHDAY"]; }
if (!string.IsNullOrEmpty(nvc["TB"]))
{ tobacco = nvc["tobacco"]; }
// if (!string.IsNullOrEmpty(nvc["PPCSource"]))
// { PPCSource = nvc["PPCSource"]; }
if (!string.IsNullOrEmpty(nvc["GC_Source"]))
{ GC_Source__c = nvc["GC_Source"]; }
if (!string.IsNullOrEmpty(nvc["GC_Medium"]))
{ GC_Medium__c = nvc["GC_Medium"]; }
if (!string.IsNullOrEmpty(nvc["GC_Term"]))
{ GC_Term__c = nvc["GC_Term"]; }
if (!string.IsNullOrEmpty(nvc["GC_Content"]))
{ GC_Content__c = nvc["GC_Content"]; }
if (!string.IsNullOrEmpty(nvc["GC_Campaign"]))
{ GC_Campaign__c = nvc["GC_Campaign"]; }
if (!string.IsNullOrEmpty(nvc["GC_Custom_Segment"]))
{ GC_Custom_Segment__c = nvc["GC_Custom_Segment"]; }
if (!string.IsNullOrEmpty(nvc["GC_Num_of_Visits"]))
{ GC_Num_of_Visits__c = nvc["GC_Num_of_Visits"]; }
googleCookie = "Source: " + GC_Source__c + "; Medium: " + GC_Medium__c + "; Term: " + GC_Term__c + "; Content: " + GC_Content__c + "; Camp: " + GC_Campaign__c + "; Segment: " + GC_Custom_Segment__c + "; Visits: " + GC_Num_of_Visits__c;
GC_Source__c = "PPCSource";
if (ln != null & !string.IsNullOrEmpty(ln))
{
/* Call SetClientFunction with the POST Parameters Passed */
string result = SetClient(leadID, fn, ln, email, phone, address,city, state, zip, gender, birthday, tobacco, PPCSource, googleCookie, 0, GC_Source__c, GC_Medium__c, GC_Term__c);
SendNotice(GC_Source__c, fn, ln, result);
}
I try to write a Webservice that can access to my exchange-server and search for names, companys and cities. At the moment i get the names like this:
ExchangeServiceBinding esb = new ExchangeServiceBinding();
esb.UseDefaultCredentials = true;
// Create the ResolveNamesType and set
// the unresolved entry.
ResolveNamesType rnType = new ResolveNamesType();
rnType.ReturnFullContactData = true;
rnType.UnresolvedEntry = "searchname";
// Resolve names.
ResolveNamesResponseType resolveNamesResponse
= esb.ResolveNames(rnType);
ArrayOfResponseMessagesType responses
= resolveNamesResponse.ResponseMessages;
// Check the result.
if (responses.Items.Length > 0 && responses.Items[0].ResponseClass != ResponseClassType.Error)
{
ResolveNamesResponseMessageType responseMessage = responses.Items[0] as
ResolveNamesResponseMessageType;
// Display the resolution information.
ResolutionType[] resolutions = responseMessage.ResolutionSet.Resolution;
foreach (ResolutionType resolution in resolutions)
{
Console.WriteLine(
"Name: " +
resolution.Contact.DisplayName
);
Console.WriteLine(
"EmailAddress: " +
resolution.Mailbox.EmailAddress
);
if (resolution.Contact.PhoneNumbers != null)
{
foreach (
PhoneNumberDictionaryEntryType phone
in resolution.Contact.PhoneNumbers)
{
Console.WriteLine(
phone.Key.ToString() +
" : " +
phone.Value
);
}
}
Console.WriteLine(
"Office location:" +
resolution.Contact.OfficeLocation
);
Console.WriteLine("\n");
}
}
But anybody know how i can serach for Propertys like Company and Street?
EWS only has limited Directory operations if your using OnPrem Exchange then the easiest way to do this is just use LDAP and lookup Active Directory directly. The resolveName operation is meant to be used to resolve a partial number and doesn't work with any other properties. If you have Exchange 2013 then there is the FindPeople operation http://msdn.microsoft.com/en-us/library/office/jj191039(v=exchg.150).aspx which supports using a QueryString which should work if those properties are indexed. eg
EWSProxy.FindPeopleType fpType = new EWSProxy.FindPeopleType();
EWSProxy.IndexedPageViewType indexPageView = new EWSProxy.IndexedPageViewType();
indexPageView.BasePoint = EWSProxy.IndexBasePointType.Beginning;
indexPageView.Offset = 0;
indexPageView.MaxEntriesReturned = 100;
indexPageView.MaxEntriesReturnedSpecified = true;
fpType.IndexedPageItemView = indexPageView;
fpType.ParentFolderId = new EWSProxy.TargetFolderIdType();
EWSProxy.DistinguishedFolderIdType Gal = new EWSProxy.DistinguishedFolderIdType();
Gal.Id = EWSProxy.DistinguishedFolderIdNameType.directory;
fpType.QueryString = "Office";
fpType.ParentFolderId.Item = Gal;
EWSProxy.FindPeopleResponseMessageType fpm = null;
do
{
fpm = esb.FindPeople(fpType);
if (fpm.ResponseClass == EWSProxy.ResponseClassType.Success)
{
foreach (EWSProxy.PersonaType PsCnt in fpm.People)
{
Console.WriteLine(PsCnt.EmailAddress.EmailAddress);
}
indexPageView.Offset += fpm.People.Length;
}
else
{
throw new Exception("Error");
}
} while (fpm.TotalNumberOfPeopleInView > indexPageView.Offset);
Cheers
Glen
I have a sample code I got from a documentation provided by a merchant. I think the code is in C#. I need to write a code for PHP but I don't have any idea about C# so I'm having a problem with this. I've tried to write a PHP code for this but it doesn't seem right.
By the way, this is a webservice kind of setup and it uses WCF to expose various endpoints. Here's the endpoint they've provided to me: http://services.scorpion.biz/Public/Leads/ExternalLead.svc
Here's the C# code:
public bool SubmitLead(string contactName, string contactNumber) {
bool outcome = false;
string message = string.Empty;
if (contactNumber.Length <= 9) {
message = "Telephone number is too short";
outcome = false;
} else if (contactNumber.Length > 11) {
message = "Telephone number is too long";
outcome = false;
} else if (contactNumber.Length == 10 && contactNumber[0] != '0') {
message = "Telephone must start with a ZERO";
outcome = false;
} else if (contactNumber.Length == 11 && contactNumber.Substring(0, 2) != "27") {
message = "Telephone must start with a 27";
outcome = false;
} else {
WSExternalLead.LeadRequestMessage request = new
WSExternalLead.LeadRequestMessage();
request.Message = “Your Keyword” + ". Contact Name: " + contactName + ".
Contact Number: " + contactNumber;
request.TelephoneNumber = contactNumber;
request.Network = “IMU”;
request.ReceivedTime = DateTime.Now;
using (WSExternalLead.ExternalLeadClient client = new WSExternalLead.ExternalLeadClient()) {
try {
WSExternalLead.LeadResponseMessage response = null;
response = client.GenerateLead(request);
if (response.Result != true) {
message = "We were unable to process your request at this
time. Error: " + response.ErrorMessage;
outcome = false;
} else {
message = "Thank you for your interest in Scorpion Legal
Protection. We will get back to you shortly.";
outcome = true;
}
} catch (FaultException fx) {
message = "We were unable to process your request at this time.
Fault: " + fx.Message;
outcome = false;
} catch (Exception ex) {
message = "We were unable to process your request at this time.
Exception: " + ex.Message;
outcome = false;
}
}
}
HttpContext.Current.Session["OUTCOME"] = outcome;
HttpContext.Current.Session["MESSAGE"] = message;
return outcome;
}
Here's the PHP code that I've written:
// Read values to variables
$username = $_GET['un'];
$usersurname = $_GET['ul'];
$phonesubmit= $_GET['up'];
$useremail = $_GET['ue'];
$aff_id = $_GET['aff'];
$unique_id = $_GET['uid'];
$rdate = date('m/d/Y G:i:s');
$rdate = date("c", strtotime($rdate));
$wsdlFile = "http://services.scorpion.biz/Public/Leads/ExternalLead.svc?WSDL";
$client = new SoapClient($wsdlFile);
$variables->TelephoneNumber = $phonesubmit;
$variables->Message = "IMU. Name: $username $usersurname. Contact Number: $phonesubmit";
$variables->Network = "IMU";
$variables->ReceivedTime = $rdate;
$result = $client->GenerateLead($variables);
$returnMessage = $result->Result;
$returnMessage = trim($returnMessage);
if ($returnMessage == ""){
$returnMessage = $result->ErrorMessage;
}
Any idea on how to solve this would be greatly appreciated. Thanks.