Microsoft Ads 'AccountPerformanceReportRequest' data contract. The deserializer has no knowledge of any type that maps to this contract - soap

I'm trying to use the Microsoft Bing Ads' Reporting API to gather ad performance data such as clicks, spend, etc. programmatically. Below, I describe the steps taken.
There are two issues -
1 - I have to request for user consent again and again as access token
is short lived and refreshed token also giving unauthenticated token
error.
2 - After following the steps I don't get the expected SOAP
Response. Instead I get below response.
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:DeserializationFailed</faultcode>
<faultstring>The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter https://bingads.microsoft.com/Reporting/v13:ReportRequest. The InnerException message was 'Error in line 13 position 71. Element 'https://bingads.microsoft.com/Reporting/v13:ReportRequest' contains data of the ':AccountPerformanceReportRequest' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'AccountPerformanceReportRequest' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.</faultstring>
</s:Fault>
</s:Body>
</s:Envelope>
I'm using Postman to test the service and my end goal is to use http to do the same in Mulesoft later. This is the URL I am using
https://reporting.api.bingads.microsoft.com/Api/Advertiser/Reporting/V13/ReportingService.svc
Authentication
I have followed their OAuth 2.0 Authentication Flow in that, I have:
Registered my Application (using the Developer Account)
Requested user consent (through the Ad account)
Generated the Access Token and Refresh Token Every time I hit the API.
**
I generate a new Access Token by requesting user consent again and again as refreshing
token is also not working.
**
Making the Request
The documentation describes a Reporting Service Operation which follows an asynchronous approach. First we need to use SubmitGenerateReport to make a request to the Reporting Service. This returns a ResponseRequestId which we can then use to repeatedly poll the service using PollGenerateReport till we get the requested report in response.
SubmitGenerateReport
SubmitGenerateReport has to be in SOAP XML Format as stated here. Following is the document I generated for my use case looking at the provided example in the documentation. Action I am passing as header attribute - SOAPAction:SubmitGenerateReport
<x:Envelope
xmlns:x="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v="https://bingads.microsoft.com/Reporting/v13"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<x:Header>
<v:AuthenticationToken>****</v:AuthenticationToken>
<v:CustomerAccountId>****</v:CustomerAccountId>
<v:CustomerId>****</v:CustomerId>
<v:DeveloperToken>****</v:DeveloperToken>
</x:Header>
<x:Body>
<v:SubmitGenerateReportRequest>
<v:ReportRequest i:type="AccountPerformanceReportRequest">
<v:Format>Csv</v:Format>
<v:ReportName>AccountPerformanceReportRequest</v:ReportName>
<v:Aggregation>Summary</v:Aggregation>
</v:ReportRequest>
</v:SubmitGenerateReportRequest>
</x:Body>
</x:Envelope>
I even tried passing all the input variables, scope, time etc but getting some error again. I understand error clearly tells me where the error is but the report types I am using are given in Microsoft documentations.
Any help and suggestion would be really helpful.

1. I have to request for user consent again and again as access token is short lived and refreshed token also giving unauthenticated token error.
I would like to point you to these tutorial, as reference for my code below.
https://learn.microsoft.com/en-us/advertising/guides/get-started?view=bingads-13
https://learn.microsoft.com/en-us/advertising/guides/authentication-oauth-quick-start?view=bingads-13
In the first step, you fetch code, for this you need browser verification.
$clientId = '...'
Start-Process "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=$clientId&scope=openid%20profile%20https://ads.microsoft.com/msads.manage%20offline_access&response_type=code&redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclient&state=ClientStateGoesHere&prompt=login"
$code = 'https://login.microsoftonline.com/common/oauth2/nativeclient?code=<code>&state=ClientStateGoesHere'
$code = $code -match 'code=(.*)\&'
$code = $Matches[1]
Now, using this code, you get accessToken/refreshToken.
$response = Invoke-WebRequest https://login.microsoftonline.com/common/oauth2/v2.0/token -ContentType application/x-www-form-urlencoded -Method POST -Body "client_id=$clientId&scope=https://ads.microsoft.com/msads.manage%20offline_access&code=$code&grant_type=authorization_code&redirect_uri=https%3A%2F%2Flogin.microsoftonline.com%2Fcommon%2Foauth2%2Fnativeclient"
$oauthTokens = ($response.Content | ConvertFrom-Json)
Since, this access token $oauthTokens.access_token will expire after one hour, use the refresh token to get new access and refresh tokens. This process you need to do periodically, say on 1/2 hourly basis.
Process to refresh is the following. This does not require you to login.
$response = Invoke-WebRequest https://login.microsoftonline.com/common/oauth2/v2.0/token -ContentType application/x-www-form-urlencoded -Method POST -Body "client_id=$clientId&scope=https://ads.microsoft.com/msads.manage%20offline_access&code=$code&grant_type=refresh_token&refresh_token=$($oauthTokens.refresh_token)"
$oauthTokens = ($response.Content | ConvertFrom-Json)
PS, I'm unclear if we could refresh infinitely or whether it is bound to a day. I verified that an expired accessToken could be renewed via refreshToken via this method after 1.5 hours - no need of generating code again via relogin.
2. After following the steps I don't get the expected SOAP Response. Instead I get below response
Thank you for providing the detailed soap xmls. I tried the same on my test account and able to repro exact same error message.
Here's the udpated SOAP xml request I used to get it to work.
<s:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header xmlns="https://bingads.microsoft.com/Reporting/v13">
<AuthenticationToken i:nil="false">here goes token</AuthenticationToken>
<CustomerAccountId i:nil="false">176045209</CustomerAccountId>
<CustomerId i:nil="false">169549046</CustomerId>
<DeveloperToken i:nil="false">here goes dev Token</DeveloperToken>
</s:Header>
<s:Body>
<SubmitGenerateReportRequest xmlns="https://bingads.microsoft.com/Reporting/v13">
<ReportRequest i:nil="false" i:type="AccountPerformanceReportRequest">
<Format i:nil="false">Csv</Format>
<ReportName i:nil="false">reportName1</ReportName>
<!--These fields are applicable if the derived type attribute is set to AccountPerformanceReportRequest-->
<Aggregation>Summary</Aggregation>
<Columns i:nil="false">
<AccountPerformanceReportColumn>Impressions</AccountPerformanceReportColumn>
<AccountPerformanceReportColumn>Revenue</AccountPerformanceReportColumn>
<AccountPerformanceReportColumn>AccountName</AccountPerformanceReportColumn>
</Columns>
<Scope i:nil="false">
<AccountIds i:nil="false" xmlns:a1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<a1:long>176045209</a1:long>
</AccountIds>
</Scope>
<Time i:nil="false">
<CustomDateRangeEnd i:nil="false">
<Day>22</Day>
<Month>07</Month>
<Year>2022</Year>
</CustomDateRangeEnd>
<CustomDateRangeStart i:nil="false">
<Day>01</Day>
<Month>07</Month>
<Year>2022</Year>
</CustomDateRangeStart>
</Time>
</ReportRequest>
</SubmitGenerateReportRequest>
</s:Body>
</s:Envelope>
Here's the postman result.
PS, I received error, when some fields were missing. I did not use xml namespaces.
Hope this helps.

Related

Invoke-WebReqeust - XML String needs to be stored in a form field called REQUEST and should be sent to our servers via HTTP POST method

Stuck following some poor documentation. Attempting to connect to a vendors API to pull orders into my own DB. The vendor has only one line and example (not even a proper url that I am still attempting to get).
Documentation =
XML String needs to be stored in a form field called REQUEST and should be sent to our servers via HTTP POST method. All of the methods described in this document must follow this standard.
Example =
GET ORDERS method XML format:
<?xml version="1.0" encoding="utf-8"?>
<OrderXML>
<Method>GET ORDERS</Method>
<Authentication>
<Username>Your Username</Username>
<Password>Your Password</Password>
</Authentication>
</OrderXML>
Tried in Postman and PowerShell just cannot figure out how to get "Request" form.
My code returns bad request and I am not sure if due to URL or not getting the "Request" form coded correctly.
$URI = "https://orders.website.com/webservice/default.cfm"
[xml]$requestXML = #'
REQUEST=
<OrderXML>
<Method>GET ORDERS</Method>
<TestMode>YES</TestMode>
<Authentication>
<Username>USERNAME</Username>
<Password>PASSWORD</Password>
</Authentication>
</OrderXML>
'#
Invoke-WebRequest -Uri $URI -Method Post -Body $requestXML
Thank you
So finally figured it out in Postman.
Used the form control instead of Raw XML.
With Key being the required "REQUEST" and the Value being the XML.

"Missing Authentication Token" Error when calling DVLA MOT history API with Postman

Note - I am very much new to all this. Apologies if anything is unclear.
My overriding aim is to pull out MOT history data for a large batch of vehicles from the DVLA API. I understand that this can be done using Postman, which I am using (on a 64-bit Windows laptop if at all relevant).
The DVLA provide the following instructions
====================================================
Getting started
All API interfaces are implemented as restful APIs and accessed over https.
To access API you will need an API key that uniquely identifies the source of the request. DVSA will give you an API key if it approves your application.
You should keep your API key secure, as DVSA manages throttling and quotas at an API key level.
Each request must have the following mandatory fields in the header:
Accept: application/json+v6
x-api-key:
Content-type field confirms that the response type is in JSON format, and the x-api-key field serves your API key to identify the source of the request.
Technical resources
Access the API at https://beta.check-mot.service.gov.uk/
This root URL will change when the service moves from beta to live.
These 4 endpoints equate to the 4 methods of using the API:
/trade/vehicles/mot-tests?registration={registration}
‘Registration’ is the vehicle registration number.
===================================================
In order to test that this is possible, I am entering the following single request into the bar in Postman, selecting "POST" and hitting "SEND"
https://beta.check-mot.service.gov.uk/trade/vehicles/mot-tests?Content-type=application/json&x-api-key=ABCDEFGH&registration=MYREG
n.b. no inverted commas or other punctuation surrounds the actual values for ABCDEFH or MYREG
Expected result: Some sort of JSON with MOT history for this vehicle
Actual result: {"message": "Missing Authentication Token"}{"message": "Missing Authentication Token"}
I am unclear on:
- whether I should be using POST
what the +v6 after the application is necessary (other documentation leaves it out)
Why "Accept" and "Content-type" appear to be used interchangeably in the documentation
Whether the ordering of the parameters matters
Whether this can be equally tested by simply pasting the url into a browser
Thanks for any help
Reading through the Documentation found here:
https://dvsa.github.io/mot-history-api-documentation/
It mentions that those fields should be added as Headers:
Each request must have the following mandatory fields in
the header:
- Accept: application/json+v6
- x-api-key: <your api key>
There are example cURL requests on the site to help you with creating the request.
If you use Postman's Import feature within the app (found in the top right), you can add this cURL request in the Paste Raw Text tab.
curl -H "Accept: application/json+v6" -H "x-api-key: <your_api_key>" https://beta.check-mot.service.gov.uk/trade/vehicles/mot-tests\?registration=ZZ99ABC
This will give you an example request of what it should look like. From here, you will be able to add in your own API Token and send the request.
If you are using Postman, you can use the Authorization tab right under the request to give the required mandatory header fields. Select Header from Add to drop down. You can also add additional headers information using the next tab named Headers. (for example, the accept-headers).
Edit:
Authorization:
Headers Tab
Normally, you should be getting the authorization token when you register to the site in question(x-api-key here).You need to figure out the value of that token from the initial call's response headers. According to the document which Danny shared, you will be getting x-api-key from them once they approve your request.
Edit:
Alternatively, you can use import feature as Danny suggested in his answer. At the end of the day, you need to add the values as headers instead of query parameters.
For anyone using Python with the MOT history api and getting the same error message, try GET:
import requests
url = f'https://beta.check-mot.service.gov.uk/trade/vehicles/mot-tests?registration={plate_number}'
payload = {}
headers = {
'Accept': 'application/json+v6',
'x-api-key': 'your-api-key'}
response = requests.get(url, headers=headers, data=payload)
data = response.json()
model = data[0]['model'] # get the vehicle model for example
print(model)

QBWC: "Index Out Of Range" in do_authenticate()

I'm using QuickBooks WebConnector 2.2.0.71 and my WCF web service (on .NET 4.6.1). After pressing "Update selected" in WebConnector serverVersion and clientVersion requests successfully processed, but authenticate failed:
20170705.06:31:00 UTC : QBWebConnector.SOAPWebService.do_authenticate() : *** Calling authenticate() with following parameters:<userName="username"><password=<MaskedForSecurity>
20170705.06:31:00 UTC : QBWebConnector.SOAPWebService.do_authenticate() : QBWC1012: Authentication failed due to following error message.
Index Out Of Range.
More info:
StackTrace = в QBWebConnector.WebService.do_authenticate(String& ticket, String& companyFileName)
Source = QBWebConnector
Response of my WCF service (from WCF Test Client):
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header />
<s:Body>
<authenticateResponse xmlns="http://developer.intuit.com/">
<authenticateResult xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:string>a3f10876-e027-419d-8dd8-3752a852ddae</a:string>
<a:string>nvu</a:string>
<a:string>3</a:string>
<a:string>60</a:string>
<a:string>60</a:string>
</authenticateResult>
</authenticateResponse>
</s:Body>
</s:Envelope>
Docs says "Your callback must return A string array with 4 possible elements. The first element contains either NONE or NVU (invalid user) or BUSY., or empty
string, or a string that is the QB company file name." but in samples first element is guid token, so I send array of 5 elements.
Same error occured when I send not an array, but int value, so I guess - maybe something wrong with my xml?
Page 21 of the QBWC Programmers Guide.
Your return to the authenticate call will be a string array with a maximum of four strings.
The first member of the array is a session token, which could be a GUID or anything else that you want to use to identify the session. This token will be returned by QBWC in subsequent callbacks in the session.
The second member of the string array can contain a variety of things.
a. If the username and password in the authenticate call is invalid, you would supply the value “nvu”.
b. If on the other hand the user data is valid but you have no work to do for that user, you would supply the value “none”.
c. If you do have work to do for the that user, you can supply the full pathname of the company to be used in the current update.
d. If you want to use whatever QuickBooks company is currently open at the client end, simply supply an empty string.
The optional third member of the string array contains the number of seconds to wait before the next update. You would use this to in effect tell that QBWC client not to bother you for a specified time.
The optional fourth member of the string array contains the number of seconds to be used as the MinimumRunEveryNSeconds time for your web service, which tells QBWC how frequently your web service needs to be contacted.
I am not sure why the Authenticate at the end of the doc is different than this.
Solved by adding [XmlSerializerFormat] to IService, so responce become
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header />
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<authenticateResponse xmlns="http://developer.intuit.com/">
<authenticateResult>
<string>d0297d33-859d-4259-a598-5fbf328bac3b</string>
<string>nvu</string>
<string>3</string>
<string>60</string>
</authenticateResult>
</authenticateResponse>
</s:Body>
</s:Envelope>

How can I pass a parameter from XML Response tag in a new GET XML Request in Soap UI?

I have tried to find a solution in this community in different threads but yet to find one that I am looking for.
I am using SoapUI version 5.3.0 My Application have a couple of RESTful APIs. Initially I am sending json request to a WebService and getting back the following XML Response:
<StartDataExtractResult xmlns="http://schemas.datacontract.org/2004/07/AriaTechCore" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<StatusCode>1</StatusCode>
<StatusText>success</StatusText>
<RequestNumber>397</RequestNumber>
</StartDataExtractResult>
As soon as RequestNumber tag is generated. I have to access to 2 more XML EndPoints (where the value of RequestNumber is appended) to know the Status as below:
A. http://quickextract.quickaudit.in/webs/quickextract.svc/GetExtractionDetails/396
B.
http://quickextract.quickaudit.in/webs/quickextract.svc/GetRequestStatus/396
As of now, I have created the 2 seperateTestSteps for the above mentioned XML Endpoints:
A. http://quickextract.quickaudit.in/webs/quickextract.svc/GetExtractionDetails/
B. http://quickextract.quickaudit.in/webs/quickextract.svc/GetRequestStatus/
Now I need to append the value within tag in the GET Request to get back a response from the WebServices.
Update:
I have created a 'Property Transfer' at Testsuite level as "TSreqNum". This 'Property Transfer' is getting updated as per the initial Response. But I am not sure how would I append "TSreqNum" to construct the complete GET Request as:
http://quickextract.quickaudit.in/webs/quickextract.svc/GetExtractionDetails/TSreqNum
Can anyone help me out please?
You can use the property within the URL of the GET request:
http://host:port/path/${#TestSuite#TSreqNum}
The URL gets updated with the property value.

insufficient_scope errors with /me/activities feed

I am failing at retrieving my activities feed (/me/activities) from Soundcloud & thought someone might be able to point out what I'm doing incorrectly.
I can access the /connect endpoint, but only if I specify a scope value of non-expiring. Using a value of * returns the error invalid_scope with an error_description of:
The requested scope is invalid, unknown or malformed.
I can exchange the resulting code for a token at the /oauth2/token endpoint, but only when setting grant_type to client_credentials.
I've attempted to request /me/activities with both GET and POST, providing oauth_token (and trying with and without a limit argument) and am being met with a 403 response * the following response header error:
OAuth realm="SoundCloud", error="insufficient_scope"
Requesting a grant_type of authorization_code when requesting at /oauth2/token fixed the issue.

Categories