none
How do I get the access token via postman? RRS feed

  • Question

  • Hey

    I have an issue with the OAuth 

    I’m getting the access token when I using the browser directly(it’s open authentication to Microsoft and than go to my redirect webpage) but not via Postman API call. I saw an error about  using JavaScript but I’m not sure if it’s limitation or I’m missing something.

    My idea is to only use POST/GET/SOAP calls without using C# or Python, is it possible?

    Can you share an example of getting the OAuth via postman? I have the app_id and redirect webpage url.

    Thanks!

    Tuesday, April 24, 2018 4:37 PM

Answers

  • Following this doc, I set the service endpoint for POST and Content-Type to text/xml. Although the doc did not mention it, I also had to set SOAPAction with the name of the service operation. 

    SubmitGenerateReport headers via Postman

    Then set the type to "raw" and paste the SOAP request into the editor.

    SubmitGenerateReport body via Postman

    That worked for me. If you observe further issues please provide repro steps in addition to the error.

    I hope this helps,

    Eric

    • Marked as answer by shayohayo Tuesday, May 15, 2018 5:06 AM
    Tuesday, May 15, 2018 2:23 AM
    Owner

All replies

  • You'll first need to grant consent via the browser i.e., steps 1-3 of Authorization Code Grant Flow. Once you have the 'code' you can use it via Postman to get the access and refresh tokens as follows:

    To refresh the token, update the grant type and use the refresh token from the previous call.

    These examples are for sandbox OAuth i.e., login.live-int.com. For production MSA authentication, use login.live.com. Also note that if you set the content-length header as I did in the first example, it must be exact. You can omit content-length, as shown in the second example.

    I hope this helps!

    Eric

    Wednesday, April 25, 2018 12:54 PM
    Owner
  • Hey Eric,
    Thanks for your response!

    2 things I'm not sure about:
    1. The 'code' is also expired after x minutes? How I can get it without needing to grant consent via the browser?
    2. what is the Platform type and URI I need to add in order to test it via Postman? I tried web platform with 
    https://www.getpostman.com/oauth2/callback but it's not working. 

    Thanks!

    Shay

    Wednesday, April 25, 2018 6:44 PM
  • Hey Eric,

    Have you seen my questions above?

    Thanks,
    Shay
    • Edited by shayohayo Friday, April 27, 2018 7:42 PM
    Friday, April 27, 2018 6:08 PM
  • As mentioned above you need to grant consent via the browser at least once. Then use the code right away. Thereafter you can use grant_type=refresh_token (with the latest refresh token) to get subsequent tokens without browser interaction.

    I have not experimented with web platform in Postman although if you registered a web app I suspect you can get the first refresh token in Postman using the login.live.com (or int) URI and thereafter refresh the token via the web site. If you have more details on the repro you tried and/or the final scenario you want to implement I'm happy to help troubleshoot further.

    Best regards,

    Eric

    Saturday, April 28, 2018 11:20 AM
    Owner
  • Hi Eric,

    I have the same issue as OP. I first get the authentication code then I send my POST request following your screenshots (with login.live.com instead of login.live-int.com). After some time I get the following:

    Could not get any Response

    There was an error connecting to https://login.live.com/oauth20_token.srf.

    Any suggestion on how to solve this issue?

    Thanks in advance




    Thursday, May 3, 2018 1:39 PM
  • I don't recall ever observing the 'Could not get any Response' error, although here are some suggestions via another forum.

    I hope this helps,

    Eric

    Friday, May 4, 2018 8:15 PM
    Owner
  • Hey Eric,

    Thanks for the article, can you send me the postman example for the actual report request?

    I have custom report that I created and I want to pull it via the API so it should be simple. When I'm looking here https://docs.microsoft.com/en-us/bingads/reporting-service/submitgeneratereport?view=bingads-12#response-header I'm not sure how to adjust it exactly to custom report so it will be amazing if you can help with that.
    in case it's not possible to get custom report , an example of Campaign Report would be great (campaign name, date, spend)

    Also one thing I'm not sure about is which tokens/code exactly I need to generate each time I requesting the report (let's say once a day):
    1. is the code is one time thing?
    2. In order to get new refresh token I need to use the previous one?  even if it expired? 

    Thanks!


    • Edited by shayohayo Thursday, May 10, 2018 11:47 PM
    Thursday, May 10, 2018 11:09 PM
  • Actually I have not yet tried Postman for the Reporting service SOAP request. Some suggestions are in the Postman docs. You would need to form SubmitGenerateReport and PollGenerateReport as separate calls, and then make yet another call to download the compressed file (and then extract it, etc). Actually I would suggest using .NET, Java, or Python where the report file download details are abstracted e.g., Reporting Service Manager. If that is not an option for you, and you want to move forward with Postman, please let me know and I will help with some sample requests. 

    You can use Authorization Code Grant Flow to maintain the access token via refresh tokens. The access token only lasts an hour by design but the refresh token is long lived.

    Please keep in mind that public refresh tokens are only bound to the granted device. For example if you registered a Native app and use https://login.live.com/oauth20_desktop.srf as the redirect URI, we only guarantee that it can be refreshed on the same device. Refresh tokens are, and always will be, completely opaque to your application. They are long-lived e.g., 90 days for public clients, but the app should not be written to expect that a refresh token will last for any period of time. Refresh tokens can be invalidated at any moment, and the only way for an app to know if a refresh token is valid is to attempt to redeem it by making a token request. Even if you continuously refresh the token on the same device with the most recent refresh token, you should expect to start again from Step 1 and request user consent if, for example you signed the user out, the Microsoft Account user changed their password, removed a device from their list of trusted devices, or removed permissions for your application to authenticate on their behalf. At any time without prior warning Microsoft may determine that user consent should again be granted. In that case, the authorization service would return an invalid grant error. 

    I hope this helps,

    Eric

    Friday, May 11, 2018 3:39 AM
    Owner
  • Hey Eric,

    The tool we planning to use is very similar to postman and using SOAP.
    Yeah it will be great to get some sample requests examples from there I can investigate more.

    Ideally I want to request a report , then pull the data from the xml(assuming csv format) or get download url.

    Thanks!

    Friday, May 11, 2018 4:00 PM
  • Here is an example of SubmitGenerateReport where the report request type is CampaignPerformanceReportRequest (you can choose Csv or Tsv):

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    	<s:Header>
    		<h:ApplicationToken i:nil="true" xmlns:h="https://bingads.microsoft.com/Reporting/v12" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/>
    		<h:AuthenticationToken xmlns:h="https://bingads.microsoft.com/Reporting/v12">AccessTokenGoesHere</h:AuthenticationToken>
    		<h:CustomerAccountId xmlns:h="https://bingads.microsoft.com/Reporting/v12">AccountIdGoesHere</h:CustomerAccountId>
    		<h:CustomerId xmlns:h="https://bingads.microsoft.com/Reporting/v12">CustomerIdGoesHere</h:CustomerId>
    		<h:DeveloperToken xmlns:h="https://bingads.microsoft.com/Reporting/v12">DeveloperTokenGoesHere</h:DeveloperToken>
    		<h:Password i:nil="true" xmlns:h="https://bingads.microsoft.com/Reporting/v12" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/>
    		<h:UserName i:nil="true" xmlns:h="https://bingads.microsoft.com/Reporting/v12" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/>
    	</s:Header>
    	<s:Body>
    		<SubmitGenerateReportRequest xmlns="https://bingads.microsoft.com/Reporting/v12">
    			<ReportRequest i:type="CampaignPerformanceReportRequest" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    				<ExcludeColumnHeaders i:nil="true"/>
    				<ExcludeReportFooter i:nil="true"/>
    				<ExcludeReportHeader i:nil="true"/>
    				<Format>Csv</Format>
    				<Language>English</Language>
    				<ReportName>My Campaign Performance Report</ReportName>
    				<ReturnOnlyCompleteData>false</ReturnOnlyCompleteData>
    				<Aggregation>Daily</Aggregation>
    				<Columns>
    					<CampaignPerformanceReportColumn>TimePeriod</CampaignPerformanceReportColumn>
    					<CampaignPerformanceReportColumn>AccountId</CampaignPerformanceReportColumn>
    					<CampaignPerformanceReportColumn>CampaignId</CampaignPerformanceReportColumn>
    					<CampaignPerformanceReportColumn>DeviceType</CampaignPerformanceReportColumn>
    					<CampaignPerformanceReportColumn>BidMatchType</CampaignPerformanceReportColumn>
    					<CampaignPerformanceReportColumn>QualityScore</CampaignPerformanceReportColumn>
    					<CampaignPerformanceReportColumn>AdRelevance</CampaignPerformanceReportColumn>
    					<CampaignPerformanceReportColumn>LandingPageExperience</CampaignPerformanceReportColumn>
    					<CampaignPerformanceReportColumn>Revenue</CampaignPerformanceReportColumn>
    					<CampaignPerformanceReportColumn>Assists</CampaignPerformanceReportColumn>
    					<CampaignPerformanceReportColumn>ExpectedCtr</CampaignPerformanceReportColumn>
    					<CampaignPerformanceReportColumn>DeliveredMatchType</CampaignPerformanceReportColumn>
    					<CampaignPerformanceReportColumn>AveragePosition</CampaignPerformanceReportColumn>
    					<CampaignPerformanceReportColumn>Conversions</CampaignPerformanceReportColumn>
    					<CampaignPerformanceReportColumn>AdDistribution</CampaignPerformanceReportColumn>
    					<CampaignPerformanceReportColumn>Network</CampaignPerformanceReportColumn>
    					<CampaignPerformanceReportColumn>Clicks</CampaignPerformanceReportColumn>
    					<CampaignPerformanceReportColumn>Impressions</CampaignPerformanceReportColumn>
    					<CampaignPerformanceReportColumn>Ctr</CampaignPerformanceReportColumn>
    					<CampaignPerformanceReportColumn>AverageCpc</CampaignPerformanceReportColumn>
    					<CampaignPerformanceReportColumn>Spend</CampaignPerformanceReportColumn>
    					<CampaignPerformanceReportColumn>LowQualityClicks</CampaignPerformanceReportColumn>
    					<CampaignPerformanceReportColumn>LowQualityConversionRate</CampaignPerformanceReportColumn>
    				</Columns>
    				<Filter i:nil="true"/>
    				<Scope>
    					<AccountIds xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
    						<a:long>AccountIdGoesHere</a:long>
    					</AccountIds>
    					<Campaigns i:nil="true"/>
    				</Scope>
    				<Time>
    					<CustomDateRangeEnd i:nil="true"/>
    					<CustomDateRangeStart i:nil="true"/>
    					<PredefinedTime>Yesterday</PredefinedTime>
    					<ReportTimeZone i:nil="true"/>
    				</Time>
    			</ReportRequest>
    		</SubmitGenerateReportRequest>
    	</s:Body>
    </s:Envelope>

    You can get the ReportRequestId and use it in PollGenerateReport as follows:

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    	<s:Header>
    		<h:ApplicationToken i:nil="true" xmlns:h="https://bingads.microsoft.com/Reporting/v12" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/>
    		<h:AuthenticationToken xmlns:h="https://bingads.microsoft.com/Reporting/v12">AccessTokenGoesHere</h:AuthenticationToken>
    		<h:CustomerAccountId xmlns:h="https://bingads.microsoft.com/Reporting/v12">AccountIdGoesHere</h:CustomerAccountId>
    		<h:CustomerId xmlns:h="https://bingads.microsoft.com/Reporting/v12">CustomerIdGoesHere</h:CustomerId>
    		<h:DeveloperToken xmlns:h="https://bingads.microsoft.com/Reporting/v12">DeveloperTokenGoesHere</h:DeveloperToken>
    		<h:Password i:nil="true" xmlns:h="https://bingads.microsoft.com/Reporting/v12" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/>
    		<h:UserName i:nil="true" xmlns:h="https://bingads.microsoft.com/Reporting/v12" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/>
    	</s:Header>
    	<s:Body>
    		<PollGenerateReportRequest xmlns="https://bingads.microsoft.com/Reporting/v12">
    			<ReportRequestId>ReportRequestIdGoesHere</ReportRequestId>
    		</PollGenerateReportRequest>
    	</s:Body>
    </s:Envelope>

    Then use the ReportDownloadUrl to download the file. 

    I hope this helps!

    Monday, May 14, 2018 1:06 PM
    Owner
  • Hey Eric,

    Can you send an example from the actual Postman request like you sent me for the authentication part?

    I'm trying to run it but getting this response back:

    "Don&#39;t panic, but the page you&#39;re looking for isn&#39;t available.</h1>
                    <h4 class="error-description">
                        <p>Check your URL and try again, or you can
                            <a href='/signout.aspx'>sign back in to Bing Ads</a>."Thanks

    Shay

     
    Monday, May 14, 2018 11:43 PM
  • Following this doc, I set the service endpoint for POST and Content-Type to text/xml. Although the doc did not mention it, I also had to set SOAPAction with the name of the service operation. 

    SubmitGenerateReport headers via Postman

    Then set the type to "raw" and paste the SOAP request into the editor.

    SubmitGenerateReport body via Postman

    That worked for me. If you observe further issues please provide repro steps in addition to the error.

    I hope this helps,

    Eric

    • Marked as answer by shayohayo Tuesday, May 15, 2018 5:06 AM
    Tuesday, May 15, 2018 2:23 AM
    Owner
  • Hey Eric,

    I was missing the host name:
    https://reporting.api.bingads.microsoft.com/Api/Advertiser/Reporting/v12/ReportingService.svc
    I used before
    https://bingads.microsoft.com/Reporting/v12

    Now it's working!

    Thanks!

    Tuesday, May 15, 2018 5:04 AM
  • Hey Eric,

    Since the migration to V13 we have to have to specify the account ids in the report request
    Right now, I entered the accounts hard-coded for now, but there is away to pull automatically all the account ids?

    if you can sent a postman example that would be great 
    Thanks!
    Wednesday, April 29, 2020 5:10 PM
  • You could call SearchAccounts by UserId. Here's a SOAP request example:

    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="https://bingads.microsoft.com/Customer/v13" xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://bingads.microsoft.com/Customer/v13/Entities" xmlns:ns2="https://bingads.microsoft.com/Customer/v13">
      <SOAP-ENV:Header>
        <tns:AuthenticationToken>AccessTokenGoesHere</tns:AuthenticationToken>
        <tns:DeveloperToken>DeveloperTokenGoesHere</tns:DeveloperToken>
      </SOAP-ENV:Header>
      <ns0:Body>
        <ns2:SearchAccountsRequest>
          <ns2:Predicates>
            <ns1:Predicate>
              <ns1:Field>UserId</ns1:Field>
              <ns1:Operator>Equals</ns1:Operator>
              <ns1:Value>UserIdGoesHere</ns1:Value>
            </ns1:Predicate>
          </ns2:Predicates>
          <ns2:PageInfo>
            <ns1:Index>0</ns1:Index>
            <ns1:Size>100</ns1:Size>
          </ns2:PageInfo>
        </ns2:SearchAccountsRequest>
      </ns0:Body>
    </SOAP-ENV:Envelope>


    To get the user ID, please see this Quick Start

    I hope this helps!

    Eric


    Monday, May 4, 2020 2:30 AM
    Owner