pythonapipython-requestshttp-status-code-404gupshup

Gupshup can't send request to create webview


I'm trying to create webview for my python facebook bot, but always get 404 error in response. Code (without token and callback-url):

import requests
from json import loads, dumps
from urllib.parse import quote_plus as urlencode

API_URL = "https://api.gupshup.io/sm/api/"

fields = [{
        "type": "input",
        "name": "curr_time",
        "label": "Enter time"
    }, {
        "type": "input",
        "name": "name",
        "label": "Apartment address"
    }]

headers = {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Accept': 'text/plain',
    'apikey': 'my_token',
}

data = {
    "title": 'Create apartment',
    "autoClose": True,
    "message": 'Apartment created!',
    "callback-url": 'https://mycallback_url',
    "fields": fields,
    "users": ['My first form']
}

data = dumps(data)
data = 'formJSON=' + urlencode(data)

r = requests.post(API_URL + "facebook/smartmsg/form/create", data=data, headers=headers)

print(r)
print(r.content)
print(r.text)

When i tried to remove apitoken from headers it gave me "401 Unauthorized. Please pass the API key"

Docs: https://www.gupshup.io/developer/docs/bot-platform/guide/serverless-webviews-using-gupshup

And online api: https://www.gupshup.io/developer/ent-apis


Solution

  • Change your headers to one of the following and it should start working

    headers = {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Accept': 'application/json',
    'apikey': 'Your_apikey'
    }
    

    or

    headers = {
    'Content-Type': 'application/x-www-form-urlencoded',
    'apikey': 'Your_apikey'
    }