Posts tagged with rest

Hope you all are doing well. I am new working with Google ads api. I have to retrieve information regarding keywords i.e how many people searched certain keywords , how many clicks and so on... so I have created a manager account on Google ads and under that I have created client account. In client account I have added keywords under keyword planner and I am getting all information mentioned above but I want to get it through REST API in python.

I have everything needed to access API: (Developer token login_customer_id Client ID Client Secret refresh token) I have given this information in the .yaml file. and I assume login_customer_id is the manager account id. Below is the code to access all the keywords information. here I have given the client_idfrom which I want to access keywords information.

import argparse import sys from google.ads.googleads.client import GoogleAdsClient from google.ads.googleads.errors import GoogleAdsException

def main(client, customer_id): ga_service = client.get_service("GoogleAdsService")

query = """     SELECT       campaign.id,       campaign.name,       ad_group.id,       ad_group.name,       ad_group_criterion.criterion_id,       ad_group_criterion.keyword.text,       ad_group_criterion.keyword.match_type,       metrics.impressions,       metrics.clicks,       metrics.cost_micros     FROM keyword_view WHERE segments.date DURING LAST_7_DAYS     AND campaign.advertising_channel_type = 'SEARCH'     AND ad_group.status = 'ENABLED'     AND ad_group_criterion.status IN ('ENABLED', 'PAUSED')     ORDER BY metrics.impressions DESC     LIMIT 50""" # Issues a search request using streaming. search_request = client.get_type("SearchGoogleAdsStreamRequest") search_request.customer_id = customer_id search_request.query = query response = ga_service.search_stream(search_request) for batch in response:     for row in batch.results:         campaign = row.campaign         ad_group = row.ad_group         criterion = row.ad_group_criterion         metrics = row.metrics         print(             f'Keyword text "{criterion.keyword.text}" with '             f'match type "{criterion.keyword.match_type.name}" '             f"and ID {criterion.criterion_id} in "             f'ad group "{ad_group.name}" '             f'with ID "{ad_group.id}" '             f'in campaign "{campaign.name}" '             f"with ID {campaign.id} "             f"had {metrics.impressions} impression(s), "             f"{metrics.clicks} click(s), and "             f"{metrics.cost_micros} cost (in micros) during "             "the last 7 days."         ) # [END get_keyword_stats] 

if name == "main":

googleads_client=GoogleAdsClient.load_from_storage("C:\Users\AnoshpaBansari\PycharmProjects\GoogleAPI\src\creds\googleads.yaml")

parser = argparse.ArgumentParser(     description=("Retrieves a campaign's negative keywords.") ) # The following argument(s) should be provided to run the example. #parser.add_argument(  #   "-c",   #  "--customer_id",    # type=str,     #required=True,     #help="The Google Ads customer ID.", #) #args = parser.parse_args() try:     main(googleads_client, "----------") except GoogleAdsException as ex:     print(         f'Request with ID "{ex.request_id}" failed with status '         f'"{ex.error.code().name}" and includes the following errors:'     )     for error in ex.failure.errors:         print(f'\tError with message "{error.message}".')         if error.location:             for field_path_element in error.location.field_path_elements:                 print(f"\t\tOn field: {field_path_element.field_name}")     sys.exit(1) 

but when I run the code I receive this error. I don't know what I am doing wrong.. Can anyone please help? enter image description here

I need to send a Calendar file (ICS) from the REST Api but i can`t.

Nevertheless, I could send a jpg file. In this article Twilio staff announced that users can send images and videos, but also PDFs, text files, and audio files using the Twilio API for WhatsApp.

This is my call with JPG file that attach the media in a whatsapp message OK:

curl -X POST \ https://api.twilio.com/2010-04-01/Accounts/ACYYYYYYYYYYYYYYYYY/Messages.json \ -H 'authorization: Basic  XXXXXXXXXXXXX' \ -H 'cache-control: no-cache' \ -H 'content-type: application/x-www-form-urlencoded' \ -H 'postman-token: 58fa6aca-3b92-66d4-f675-9906bed37302' \ -d 'To=whatsapp%3A%2BXXXXXXXX&From=whatsapp%3A%2BYYYYYYY&Body=Hola%20probando2&MediaUrl=https%3A%2F%2Flh4.googleusercontent.com%2F-nbafRpNzZAc%2FWjHLp8y3NOI%2FAAAAAAAAAAA%2Fc8CSoPlcgcAazvZFKSU3uYxwo3HZ7FVewCOQCEAE%2Fs128-c-k%2Fphoto.jpg%0A' 

When i substitute MediaUrl path with a txt file path or ics file, the message wasn't attach the file:

for example something like this:

curl -X POST \ https://api.twilio.com/2010-04-01/Accounts/ACYYYYYYYYYYYYYYYYY/Messages.json \ -H 'authorization: Basic  XXXXXXXXXXXXX' \ -H 'cache-control: no-cache' \ -H 'content-type: application/x-www-form-urlencoded' \ -H 'postman-token: 58fa6aca-3b92-66d4-f675-9906bed37302' \ -d 'To=whatsapp%3A%2BXXXXXXXX&From=whatsapp%3A%2BYYYYYYY&Body=Hola%20probando2&MediaUrl=https:%2F%2Faaa.bbb.com%2Fccc%2Fcalendar.ics%0A' 

Following to this documentation https://developers.facebook.com/docs/whatsapp/business-management-api/phone-numbers about whatsapp business accounts, it is possible to have multiple phone numbers in one account. Does someone know how you can define from which number a message is send, when sending a message to a client? There is nothing in the api about sending messages.

following to the documentation you can read the phone numbers and their whatsapp id via

curl -X GET \ 'https://graph.facebook.com/v3.3/your-whatsapp-business-account-id/phone_numbers' \   -d 'access_token=your-access-token' 

example result

{   "data": [     {       "verified_name": "Jasper's Market",       "display_phone_number": "+1 631-555-5555",       "id": "1906385232743451",       "quality_rating": "GREEN"     },     {       "verified_name": "Jasper's Ice Cream",       "display_phone_number": "+1 631-555-5556",       "id": "1913623884432103",       "quality_rating": "NA"     }   ], } 

I would expect something like a senderId field when sending a message.

I am new to .net-core and docker. The problem I am going to explain here is a bit tricky, but if you have any type of questions please do ask me and I will explain it more clearly.

So, I have a docker container running on my localhost for whatsapp business api, as explained in Whatsapp Business Api Documentation.

I have already downloaded Postman Collection of Whatsapp Business Api from Whatsapp Business Postman Collection.

Everything seems to be working perfectly fine. But now I want to call these pre-built apis with .net-core and get the responses. As I couldn't find anything good, or also as a newbie it's difficult for me to understand. So for some knowledge I would like to know How can I call them and get the effective response. For example, take an example of a post request for admin login

API: {{URL}}/v1/users/login Authorization -> (Basic Auth) username: admin password: **** 
RESPONSE: {     "users": [         {             "token": "eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.eyJ1c2VyIjoiYWRtaW4iLCJpYXQiOjE1NTk5MTE1NTUsImV4cCI6MTU2MDUxNjM1NSwid2E6cmFuZCI6LTQxMzgyNDE0MjYwMDI5NjA1OTl9.PYAhEilXX3GDhRo0O-M0V0aXWfL5THJkG65LfIesxh4",             "expires_after": "2019-06-14 12:45:55+00:00"         }     ],     "meta": {         "version": "v2.23.4",         "api_status": "stable"     } } 

the images for more explanation can be seen below in the request and response links.

The Login Authentication UI Image.

The Login Authentication Postman Image.

The Login Authentication Response New Password UI Image.

The Login Authentication Response Postman Image.

Now with this token I can create more users by other api calls. How can I call an api like this and get the response with token and use that token for more functionalities or api calls with .netcore.

Thank you.