Import a Dataset into a Dataverse

61 views
Skip to first unread message

Uus Khusni

unread,
Jun 11, 2019, 3:46:20 AM6/11/19
to Dataverse Dev
Hallo

I am from Indonesia, and newbie in dataverse. I try to call API dataverse from PHP to import dataset JSON into dataverse but i got messege

{"status":"ERROR","code":404,"message":"'/api/v1/dataverses/puslitekonomi-lipi/:import' endpoint does not exist on this server. Please check your code for typos, or consult our API guide at http://guides.dataverse.org."}

Please help us, below is my code write on PHP

$url = 'https://xxx/api/dataverses/xxx/:import?pid=xxx&release=no&key=xxx';

//create a new cURL resource
    $ch = curl_init($url);
    //echo $url;
    //HTTP username.
    $username = 'xxx';
//HTTP password.
    $password = 'xxx';
//setup request to send json via POST
    $payload = json_encode($array_dataset);
//attach encoded JSON string to the POST fields

    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

//set the content type to application/json
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type:application/json',
        'Authorization: Basic '. base64_encode("$username:$password")));

//return response instead of outputting
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//execute the POST request
    $result = curl_exec($ch);

    echo $result;
    //echo 'Request Error:' . curl_error($ch);
//close cURL resource
    curl_close($ch);

Philip Durbin

unread,
Jun 11, 2019, 8:57:54 AM6/11/19
to datave...@googlegroups.com
Hi Uus,

It's been a while since I've done any PHP but I just asked at I asked at http://irclog.iq.harvard.edu/dataverse/2019-06-11#i_97075 and Jeremy Richard figured out what the problem is, I think.

(You are welcome to join us at http://chat.dataverse.org of course!)

That "endpoint does not exist on this server" error is easy to trigger. If you go to https://demo.dataverse.org/api/doesNotExist for example, you will see that error.

The problem seems to be that the "path" in your $url is missing the word "datasets". Instead of...
... you should try something like...



curl -H "X-Dataverse-key: $API_TOKEN" -X POST $SERVER_URL/api/dataverses/$DV_ALIAS/datasets/:import?pid=$PERSISTENT_IDENTIFIER&release=yes --upload-file dataset.json

Finally, have you considered contributing a PHP client library for Dataverse? I would be happy to create a repo at https://github.com/IQSS/dataverse-client-php and give you "push" access to it! All of the client libraries listed at http://guides.dataverse.org/en/4.14/api/client-libraries.html have been contributed by the community.

Thanks,

Phil


--
You received this message because you are subscribed to the Google Groups "Dataverse Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dataverse-de...@googlegroups.com.
To post to this group, send email to datave...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dataverse-dev/545a04ea-816e-45e9-b3f3-658a0d7c43d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Reply all
Reply to author
Forward
0 new messages