Posts tagged with api

Currently, I am using WhatsApp Business api cloud on one of my web project, I would like to register a customer's phone number but via api instead through meta, developer platform like following:

"Here is the image to register customer's number in the meta developer platform"

I want do this: (managing the phone numbers)

but via api, and later of that send the verification code via api as well. If someone can help me , telling me if that is possible and sharing documentation or the endpoint I would appreciate it very much, I've been looking at the documentation and postman's examples for 2 days without any success.

I'm sorry I didn't share the pictures directly, it is my first question on Stackoverflow

Thanks in advance, Greetings!

I have multiple keywords for which I am looking for some related keyword ideas along with their metrics. For that, I am using google-ads-api's GenerateKeywordIdeasRequest. It takes a list of keywords, but right now I am passing a single keyword at a time. After that I convert the output into a dataframe and pick the top 3 keywords ideas based on their monthly search volume.

for example: if passed "bottle", it would return

and from there I would extract the top 3 keyword searches suggested for "bottle".

But with this approach, it takes a lot of time to generate ideas for all input keywords. So I tried passing all input keywords at once, which reduce the processing time dramatically but the issue is, I am not able to get the top 3 suggested keyword for each input keyword separately as all suggested keywords ideas for each input are now mixed. And It is hard to tell which is suggested for which passed input.

Here is the code I am using

import pandas as pd from google.ads.googleads.client import GoogleAdsClient class GoogleAD:     def __init__(self):       pass          def get_keywords_search_volume(client, customer_id, location_ids, language_id, keyword_texts, page_url= None):         """function to get keyword search volume from google ads API """         keyword_plan_idea_service = client.get_service("KeywordPlanIdeaService")         keyword_competition_level_enum = (client.enums.KeywordPlanCompetitionLevelEnum)         keyword_plan_network = (client.enums.KeywordPlanNetworkEnum.GOOGLE_SEARCH_AND_PARTNERS)         location_rns = GoogleAD.map_locations_ids_to_resource_names(client, location_ids)         language_rn = client.get_service("GoogleAdsService").language_constant_path(language_id)                  # Either keywords or a page_url are required to generate keyword ideas         # so this raises an error if neither are provided.         if not (keyword_texts or page_url):             raise ValueError(                 "At least one of keywords or page URL is required, "                 "but neither was specified."             )                  # Only one of the fields "url_seed", "keyword_seed", or         # "keyword_and_url_seed" can be set on the request, depending on whether         # keywords, a page_url or both were passed to this function.         request = client.get_type("GenerateKeywordIdeasRequest")         request.customer_id = customer_id         request.language = language_rn         request.geo_target_constants = location_rns         request.include_adult_keywords = False         request.keyword_plan_network = keyword_plan_network                  # To generate keyword ideas with only a page_url and no keywords we need         # to initialize a UrlSeed object with the page_url as the "url" field.         if not keyword_texts and page_url:             request.url_seed.url = page_url                  # To generate keyword ideas with only a list of keywords and no page_url         # we need to initialize a KeywordSeed object and set the "keywords" field         # to be a list of StringValue objects.         if keyword_texts and not page_url:             request.keyword_seed.keywords.extend(keyword_texts)                  # To generate keyword ideas using both a list of keywords and a page_url we         # need to initialize a KeywordAndUrlSeed object, setting both the "url" and         # "keywords" fields.         if keyword_texts and page_url:             request.keyword_and_url_seed.url = page_url             request.keyword_and_url_seed.keywords.extend(keyword_texts)                  keyword_ideas = keyword_plan_idea_service.generate_keyword_ideas(request=request)                  for idea in keyword_ideas:             competition_value = idea.keyword_idea_metrics.competition.name         return keyword_ideas          def map_locations_ids_to_resource_names(client, location_ids):             """Converts a list of location IDs to resource names.             Args:                 client: an initialized GoogleAdsClient instance.                 location_ids: a list of location ID strings.             Returns:                 a list of resource name strings using the given location IDs.             """             build_resource_name = client.get_service(                 "GeoTargetConstantService"             ).geo_target_constant_path             return [build_resource_name(location_id) for location_id in location_ids]          def get_keyword_df(key_word):          """function to generate dataframe with keyword search volume"""         try:             client = GoogleAdsClient.load_from_storage('desc.yaml')             list_keywords = GoogleAD.get_keywords_search_volume(client, "686xxxxx647", ["2840"], "1000", key_word, None)             keyword_df = pd.DataFrame()             for idea in list_keywords:                 keyword_dict = {}                 competition_value = idea.keyword_idea_metrics.competition.name                 idea_text = idea.text                 monthly_search_volume = idea.keyword_idea_metrics.avg_monthly_searches                 keyword_dict['idea_text'] = idea_text                 keyword_dict['monthly_search_volume'] = int(monthly_search_volume)                 keyword_dict['competition_value'] = competition_value                 keyword_dict['key_word'] = key_word                 keyword_dict['key_word_modified'] = key_word.replace('%',' percent')                 keyword_series = pd.Series(keyword_dict)                 keyword_df = keyword_df.append(keyword_series, ignore_index = True)         except Exception as e:             print(e)             # print(e.args[2])             keyword_df = pd.DataFrame()         return keyword_df suggestion_df = GoogleAD.get_keyword_df(['bottle']) 

Let me know if there's any more information I can provide.

I am trying to setup a webhook in AWS Lambda (using API Gateway) for Meta's WhatsApp Business API. They have the following guidelines:

Whenever your endpoint receives a verification request, it must:

Verify that the hub.verify_token value matches the string you set in the Verify Token field when you configure Webhooks in your App Dashboard (you haven't set up this token string yet). Respond with the hub.challenge value."

I have setup all the query strings it needs in the API gateway. Here is what my lambda handler looks like:

def lambda_handler(event, context):     response = {         "status": 400,         "body" : "failed"     }          print(str(event))          print("Received context" + str(context))          if(len(event) != 0 and (event['hub.verify_token'] == "some value")):         response['status'] = 200         response['body'] = event['hub.challenge']         return event['hub.challenge']               #print(response)         #returnResponse = re.findall('[0-9]+', event['hub.challenge'])         #return returnResponse[0]              else:         return(response) 

the event looks like:

{     "hub.mode" : "some value",     "hub.verify_token": "some value",     "hub.challenge": "1158201444" } 

The response in AWS console looks like "1158201444" but on meta's end, the response looks like "\"1158201444\"" and the webhook confirmation fails in Meta's dashboard.

How can remove the extra characters and decode the string? I have already tried regex and still getting the extra characters (\"\").

I have created a WhatsApp Business Platform Test account. I am able to send and receive the hello-world template message but when I send a test message without template(as specified by the api) it doesn't push it to the mobile phone. Strangely I get success response in both cases.

Url: https://graph.facebook.com/v15.0/11ZZZZZZZZZZZZZ/messages

Here are the jsons and their responses

{    "messaging_product":"whatsapp",    "to":"91ZZZZZZZZZZ",    "type":"template",    "template":{       "name":"hello_world",       "language":{          "code":"en_US"       }    } } {    "messaging_product":"whatsapp",    "contacts":[       {          "input":"91ZZZZZZZZZZ",          "wa_id":"91ZZZZZZZZZZ"       }    ],    "messages":[       {          "id":"wamid.HBgMOTE3MjkwMDIxMzYwFQIAERgSMjZCRkQ3RDc0RjM0QkNEZZZZZZ=="       }    ] } 

In these case I successfully receive message on the mobile

{    "messaging_product":"whatsapp",    "to":"91ZZZZZZZZZZ",    "type":"text",    "text":{       "preview_url":false,       "body":"Hello World Testing"    } } {    "messaging_product":"whatsapp",    "contacts":[       {          "input":"91ZZZZZZZZZZ",          "wa_id":"91ZZZZZZZZZZ"       }    ],    "messages":[       {          "id":"wamid.HBgMOTE3MjkwMDIxMzYwFQIAERgSQUJERkM2RUE1RTEwQTExZZZZZZ=="       }    ] } 

However I don't receive message on the mobile. Is there anything I am missing in the second case?