# Invite by API - no response

**URL:** https://meta.discourse.org/t/invite-by-api-no-response/87204
**Category:** Support
**Created:** [May 10, 2018, 8:00pm UTC](https://meta.discourse.org/t/invite-by-api-no-response/87204 "2018-05-10T20:00:56Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![Sergio\_Werner](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@Sergio\_Werner](https://meta.discourse.org/u/Sergio_Werner)
#### Post date: [May 10, 2018, 8:00pm UTC](https://meta.discourse.org/t/invite-by-api-no-response/87204/1 "2018-05-10T20:00:56Z")

</div>

What am I doing wrong? I get no response from the API.

```plaintext
<?php

	$query = array(' [
		"email" => "test@gmail.com",
		"group_names" => "",
		"custom_message" => "" ]');	
		
    $paramArray['api_key'] = '....................';
    $paramArray['api_username'] = "admin";
	$url = sprintf
		(
		'%s://%s%s?%s',
		'https', 
		'forum.exemple.com/', 
		'invites', 
		http_build_query($paramArray)
		);	
		

	$invite = curl_init();
	
	curl_setopt($invite, CURLOPT_URL, $url);
	curl_setopt($invite, CURLOPT_POSTFIELDS, http_build_query($query));
	curl_setopt($invite, CURLOPT_RETURNTRANSFER, true);
	
	$resp = curl_exec($invite);
	curl_close($invite);
	
print_r($resp);
		
?>

```

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [May 10, 2018, 9:13pm UTC](https://meta.discourse.org/t/invite-by-api-no-response/87204/3 "2018-05-10T21:13:04Z")

</div>

This worked for me:

```plaintext
<?php

$fields = array(
  'api_key' => 'a71cb5058c6be27e42806ad788bc7b0008af9c15170d1be1827a24c8e8334107',
  'api_username' => 'blake.erickson',
  'email' => 'test' . rand() . '@example.com',
  'custom_message' => 'Please join my awesome forum'
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://localhost:3000/invites");
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

curl_close ($ch);

print_r($server_output);
?>

```

> <https://stackoverflow.com/questions/2138527/php-curl-and-http-post-example/2138534#2138534>

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [May 11, 2018, 12:59pm UTC](https://meta.discourse.org/t/invite-by-api-no-response/87204/4 "2018-05-11T12:59:49Z")

</div>

Maybe use system user instead of admin? Did you set up a user called admin?

---

<div class="post-metadata">

### Author: ![Sergio\_Werner](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@Sergio\_Werner](https://meta.discourse.org/u/Sergio_Werner)
#### Post date: [May 14, 2018, 9:13pm UTC](https://meta.discourse.org/t/invite-by-api-no-response/87204/5 "2018-05-14T21:13:56Z")

</div>

Yes, I am using the appropriate userid.

---

<div class="post-metadata">

### Author: ![Sergio\_Werner](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@Sergio\_Werner](https://meta.discourse.org/u/Sergio_Werner)
#### Post date: [May 14, 2018, 9:13pm UTC](https://meta.discourse.org/t/invite-by-api-no-response/87204/6 "2018-05-14T21:13:59Z")

</div>

Is port 3000 fixed or needs to be configured?

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [May 14, 2018, 9:15pm UTC](https://meta.discourse.org/t/invite-by-api-no-response/87204/7 "2018-05-14T21:15:20Z")

</div>

I’m only using port 3000 because I’m using my development environment. If you are in production it is on port 80 and you won’t need to specify that.

---

<div class="post-metadata">

### Author: ![Sergio\_Werner](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@Sergio\_Werner](https://meta.discourse.org/u/Sergio_Werner)
#### Post date: [May 14, 2018, 9:45pm UTC](https://meta.discourse.org/t/invite-by-api-no-response/87204/8 "2018-05-14T21:45:26Z")

</div>

I definitely do not know what I’m doing wrong. I followed his tips but it did not work. It does not answer anything.

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [May 14, 2018, 10:04pm UTC](https://meta.discourse.org/t/invite-by-api-no-response/87204/9 "2018-05-14T22:04:07Z")

</div>

We are happy to help but there could be an infinite list of things that is causing your issue and we need a little bit more info in order to help out in any way.

As an example of one of the things that could go wrong is that you might not have the curl php module installed or enabled on your computer.

In order to rule out any API/internet issues I would start with just using curl directly from the command line and not use php and see if you can get it to work. There are two example api calls in the docs that require authentication that you should start out with:

`curl -X GET "http://127.0.0.1:3000/admin/users/list/active.json?api_key=714552c6148e1617aeab526d0606184b94a80ec048fc09894ff1a72b740c5f19&api_username=discourse1"`

and

```
curl -X POST "http://127.0.0.1:3000/categories" \
-H "Content-Type: multipart/form-data;" \
-F "api_key=714552c6148e1617aeab526d0606184b94a80ec048fc09894ff1a72b740c5f19" \
-F "api_username=discourse1" \
-F "name=89853c20-4409-e91a-a8ea-f6cdff96aaaa" \
-F "color=49d9e9" \
-F "text_color=f0fcfd"

```

See if you are able to run those successfully against your discourse site and we can go from there.

---

<div class="post-metadata">

### Author: ![Sergio\_Werner](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@Sergio\_Werner](https://meta.discourse.org/u/Sergio_Werner)
#### Post date: [May 14, 2018, 11:14pm UTC](https://meta.discourse.org/t/invite-by-api-no-response/87204/10 "2018-05-14T23:14:26Z")

</div>

“/admin/users/list/active.json” and “/categories” work properly.  
But “/invites” does not work.

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [May 14, 2018, 11:33pm UTC](https://meta.discourse.org/t/invite-by-api-no-response/87204/11 "2018-05-14T23:33:18Z")

</div>

> [@Sergio\_Werner](#):
>
> But “/invites” does not work.

Can you show me your curl command to the `/invites` endpoint(feel free to edit out your api key).

Here is the command I just used and you can see the successful json response:

```
blake@w:~$ curl -X POST "http://192.168.56.2:3000/invites" \
> -H "Content-Type: multipart/form-data;" \
> -F "api_key=b5d6568b19aee95ee5768e1f3929cbaa076545cba0427ecbee822a8114efde7c" \
> -F "api_username=system" \
> -F "email=asdfasdf@example.com" \
> -F "custom_message=asdfasdfasdf"
{"success":"OK"}blake@w:~$

```

---

<div class="post-metadata">

### Author: ![Sergio\_Werner](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@Sergio\_Werner](https://meta.discourse.org/u/Sergio_Werner)
#### Post date: [May 15, 2018, 12:07am UTC](https://meta.discourse.org/t/invite-by-api-no-response/87204/12 "2018-05-15T00:07:57Z")

</div>

The response:

```plaintext
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.14.0</center>
</body>
</html>

```

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [May 15, 2018, 12:16am UTC](https://meta.discourse.org/t/invite-by-api-no-response/87204/13 "2018-05-15T00:16:52Z")

</div>

Thank you for showing me the response. Can I also see the curl command you used? I’m not sure yet why nginx would return a 301.

---

<div class="post-metadata">

### Author: ![Sergio\_Werner](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@Sergio\_Werner](https://meta.discourse.org/u/Sergio_Werner)
#### Post date: [May 15, 2018, 1:14am UTC](https://meta.discourse.org/t/invite-by-api-no-response/87204/14 "2018-05-15T01:14:42Z")

</div>

Excuse me. I made a small mistake.  
Calling CURL directly is working.  
It is not working in PHP.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [May 15, 2018, 1:36am UTC](https://meta.discourse.org/t/invite-by-api-no-response/87204/15 "2018-05-15T01:36:21Z")

</div>

Sounds like your PHP code isn’t following redirects, isn’t a matter of using HTTPS directly instead of HTTP?

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [May 15, 2018, 5:11am UTC](https://meta.discourse.org/t/invite-by-api-no-response/87204/16 "2018-05-15T05:11:43Z")

</div>

Enable redirects using easy\_setopt. [CURLOPT\_FOLLOWLOCATION](https://curl.haxx.se/libcurl/c/CURLOPT_FOLLOWLOCATION.html)

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [October 30, 2020, 5:35pm UTC](https://meta.discourse.org/t/invite-by-api-no-response/87204/17 "2020-10-30T17:35:46Z")

</div>


