API V1 Works - V2 Does not return any data

I’m trying to upgrade my PHP application to the v2 API and can’t even get it to respond back to me at all.

V1 Code that Works:

$curl = curl_init();
 curl_setopt($curl, CURLOPT_URL, 'https://kc.kobotoolbox.org/api/v1/data/'.$projectId);
 curl_setopt($curl, CURLOPT_USERPWD,  $this->user.":".$this->pw);
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$resp = curl_exec($curl);

Results in the following curl request/response:

Request: GET /api/v1/data/<projectid> HTTP/2 Host: kc.kobotoolbox.org 
Response: {"detail":"Not found."}

Now, updated for V2 no matter the endpoint I try to use I cannot get a response from Kobo:
Here’s an example:

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://kc.kobotoolbox.org/api/v2/assets.json');
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept: application/json","Authorization: ".$this->token));
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$resp = curl_exec($curl);		

This results in a Request/Response as follows:

Request: GET /api/v2/assets.json HTTP/2 Host: kc.kobotoolbox.org accept: application/json authorization: <mytoken>
Response: No Data

I’ve also tried V2 with Basic HTTP Auth and many variations of the endpoint and I cannot get any response at all.

What am I doing wrong here? Thanks in advance for any assistance.

Hi @NTBG, for the V2 API, you need to use the KPI subdomain so your https://kc.kobotoolbox.org/api/v2/assets needs to be https://kf.kobotoolbox.org/api/v2/assets :+1:

1 Like

Of course it was that easy. Thank you for your reply!

1 Like

Hello Again,
So I’m able to get a response when using the correct URL… however my deployed forms are not being returned…

Request: GET /api/v2/assets/ HTTP/2 Host: kf.kobotoolbox.org accept: application/json authorization: -mytoken-

Response: {“count”:0,“next”:null,“previous”:null,“results”:[]}

I also tried the request using PostMan, following the instructions here (Using the API — KoBoToolbox documentation) and double-checked my API key from https://kf.kobotoolbox.org/token/?format=json

Postman response is the same:

"count": 0,

"next": null,

"previous": null,

"results": []


Any suggestions as to why my deployed forms might not be showing up here?

Thank you in advance for your help.

Hi @NTBG, please ensure that you follow the correct header format shown in the docs: Authorization: Token <your token>

1 Like

That worked… thank you Josh!