# Using API to send notifications

**URL:** <https://forum.adalo.com/t/using-api-to-send-notifications/12105>\
**Category:** External Collections, Custom Actions & Collections\
**Created:** [May 1, 2021, 1:28pm UTC](https://forum.adalo.com/t/using-api-to-send-notifications/12105 "2021-05-01T13:28:42Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![arnevd](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.adalo.com/arnevd/32/8017_2.png) [@arnevd](https://forum.adalo.com/u/arnevd)\
**Post date:** [May 1, 2021, 1:28pm UTC](https://forum.adalo.com/t/using-api-to-send-notifications/12105/1 "2021-05-01T13:28:42Z")

</div>

Hi all.

I keep on getting a 400 response on this API request. With same appID and header I can make a succesful get request to retrieve all users. So it’s def not authentication. Email also certainly exists in my database.

Any ideas?

This is python:

```
import requests
import json

appID = xyz

head = {
    'Authorization': 'Bearer xyz',
    'Content-Type': 'application/json'
}

url = 'https://api.adalo.com/notifications'

body = {
  "appId": appID,
  "audience": {"email" : "abc@gmail.com"},
  "notification": {
    "titleText": "Hello There",
    "bodyText": "This is just a test..."
  }
}
notify = requests.post(url, headers=head, data=body)

print(notify)

```

results in 400 response.

---

<div class="post-metadata">

**Author:** ![Victor](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.adalo.com/victor/32/2054_2.png) [@Victor](https://forum.adalo.com/u/Victor)\
**Post date:** [May 1, 2021, 1:33pm UTC](https://forum.adalo.com/t/using-api-to-send-notifications/12105/2 "2021-05-01T13:33:32Z")

</div>

Hi @arnevd,

Did you try to check via curl or Postman, out of curiosity?

Best,  
Victor

---

<div class="post-metadata">

**Author:** ![arnevd](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.adalo.com/arnevd/32/8017_2.png) [@arnevd](https://forum.adalo.com/u/arnevd)\
**Post date:** [May 1, 2021, 1:54pm UTC](https://forum.adalo.com/t/using-api-to-send-notifications/12105/3 "2021-05-01T13:54:51Z")

</div>

Yes, same thing happens  
upload completely sent off: 178 out of 178 bytes  
\< HTTP/1.1 400 Bad Request  
\< Server: Cowboy  
\< Date: Sat, 01 May 2021 13:53:37 GMT  
\< Connection: close  
\< Via: 1.1 vegur

Full anonymised curl req:  
`curl -H '{"Authorization": "Bearer xyz","Content-Type": "application/json"}' -d '{"appId": "xyz","audience": {"email" : "abc@gmail.com"},"notification": {"titleText": "Hello There","bodyText": "This is just a test..."}}' --verbose -X POST https://api.adalo.com/notifications`

---

<div class="post-metadata">

**Author:** ![JL\_LJ](https://avatars.discourse-cdn.com/v4/letter/j/f08c70/32.png) [@JL\_LJ](https://forum.adalo.com/u/JL_LJ)\
**Post date:** [May 1, 2021, 1:55pm UTC](https://forum.adalo.com/t/using-api-to-send-notifications/12105/4 "2021-05-01T13:55:14Z")

</div>

> [@arnevd](#):
>
> ```auto
> "appId": appID,
> 
> ```

Taking a look at your code, I see two mistakes:

- You have “head” instead of “headers” in the authorization. Any reason you use headers=head?

Then it doesn’t seem you are quoting the appID:

You have  
“appId”: appID, Should be “appId”: “appId”,

---

<div class="post-metadata">

**Author:** ![arnevd](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.adalo.com/arnevd/32/8017_2.png) [@arnevd](https://forum.adalo.com/u/arnevd)\
**Post date:** [May 1, 2021, 1:57pm UTC](https://forum.adalo.com/t/using-api-to-send-notifications/12105/5 "2021-05-01T13:57:01Z")

</div>

Thx JL\_LJ,

head is a variable as is appID, just not initialized for privacy reasons here ;). With same header I can succesfully perform a GET request, so the header shouldn’t be the issue (neither should the appID, because in my get methodology I also use a variable).

---

<div class="post-metadata">

**Author:** ![JL\_LJ](https://avatars.discourse-cdn.com/v4/letter/j/f08c70/32.png) [@JL\_LJ](https://forum.adalo.com/u/JL_LJ)\
**Post date:** [May 1, 2021, 1:59pm UTC](https://forum.adalo.com/t/using-api-to-send-notifications/12105/6 "2021-05-01T13:59:11Z")

</div>

Yes,  
I see it as a variable “appID = xyz”, but still shouldn’t the variable be wrapped in “”?

---

<div class="post-metadata">

**Author:** ![arnevd](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.adalo.com/arnevd/32/8017_2.png) [@arnevd](https://forum.adalo.com/u/arnevd)\
**Post date:** [May 1, 2021, 2:00pm UTC](https://forum.adalo.com/t/using-api-to-send-notifications/12105/7 "2021-05-01T14:00:18Z")

</div>

No because then it wouldn’t be a variable anymore. It would be a string.

---

<div class="post-metadata">

**Author:** ![arnevd](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.adalo.com/arnevd/32/8017_2.png) [@arnevd](https://forum.adalo.com/u/arnevd)\
**Post date:** [May 1, 2021, 2:01pm UTC](https://forum.adalo.com/t/using-api-to-send-notifications/12105/8 "2021-05-01T14:01:05Z")

</div>

In any case, if I use the curl statement I use 0 variables, and get the same 400 error.

---

<div class="post-metadata">

**Author:** ![arnevd](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.adalo.com/arnevd/32/8017_2.png) [@arnevd](https://forum.adalo.com/u/arnevd)\
**Post date:** [May 1, 2021, 2:03pm UTC](https://forum.adalo.com/t/using-api-to-send-notifications/12105/9 "2021-05-01T14:03:18Z")

</div>

I should mention I am on integrations pack trial. Maybe that’s got something to do with it?

---

<div class="post-metadata">

**Author:** ![arnevd](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.adalo.com/arnevd/32/8017_2.png) [@arnevd](https://forum.adalo.com/u/arnevd)\
**Post date:** [May 3, 2021, 7:55am UTC](https://forum.adalo.com/t/using-api-to-send-notifications/12105/10 "2021-05-03T07:55:02Z")

</div>

Victor, any idea what’s happening here?

---

<div class="post-metadata">

**Author:** ![Victor](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.adalo.com/victor/32/2054_2.png) [@Victor](https://forum.adalo.com/u/Victor)\
**Post date:** [May 3, 2021, 10:50am UTC](https://forum.adalo.com/t/using-api-to-send-notifications/12105/11 "2021-05-03T10:50:21Z")

</div>

Hi @arnevd,

I’ve just tested Push notifications via API on one of my test apps - it works for me perfectly. I did it via Postman.  
So as I think the problem is somewhere within your app.

By the way, did you make any native build of your app for iOS or Android? Push notifications won’t work if there were no builds before (see help doc, “In order for these API requests to succeed, you must first have at least one native build of your app. The build can be for either iOS or Android, and you do not need to have published your app to the app stores.”)

Best regards, Victor.

---

<div class="post-metadata">

**Author:** ![arnevd](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.adalo.com/arnevd/32/8017_2.png) [@arnevd](https://forum.adalo.com/u/arnevd)\
**Post date:** [May 5, 2021, 9:53am UTC](https://forum.adalo.com/t/using-api-to-send-notifications/12105/12 "2021-05-05T09:53:35Z")

</div>

Aah perfect, I must’ve missed that piece of information!

---

<div class="post-metadata">

**Author:** ![arnevd](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.adalo.com/arnevd/32/8017_2.png) [@arnevd](https://forum.adalo.com/u/arnevd)\
**Post date:** [May 5, 2021, 12:01pm UTC](https://forum.adalo.com/t/using-api-to-send-notifications/12105/13 "2021-05-05T12:01:18Z")

</div>

@Victor Still isn’t working. I’ve become a paid customer now because I had to before I could build the app. Still get the 400 request.

---

<div class="post-metadata">

**Author:** ![Victor](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.adalo.com/victor/32/2054_2.png) [@Victor](https://forum.adalo.com/u/Victor)\
**Post date:** [May 5, 2021, 12:16pm UTC](https://forum.adalo.com/t/using-api-to-send-notifications/12105/14 "2021-05-05T12:16:03Z")

</div>

Hi @arnevd,

If you have successfully completed at least one build of your app, and push notifications API isn’t working for you, then it would be a good idea to submit a support ticket:

> **[Submit a Support Ticket](https://info.adalo.com/submit-a-support-ticket)**
>
> Submit a support ticket for the Adalo Support team to help resolve issues, troubleshoot bugs, and offer app guidance.

Also, 400 isn’t just a response number alone. Usually you get some text along with 400 response, which may help to indicate what’s the problem.

Best regards, Victor.

---

<div class="post-metadata">

**Author:** ![arnevd](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.adalo.com/arnevd/32/8017_2.png) [@arnevd](https://forum.adalo.com/u/arnevd)\
**Post date:** [May 10, 2021, 7:41am UTC](https://forum.adalo.com/t/using-api-to-send-notifications/12105/15 "2021-05-10T07:41:13Z")

</div>

Found the solution. requests.post(urlPost, headers=head, json=body) instead of data=body. So it’s a python thing i guess
