Help:Editing using the API

From BugSigDB

Logging in[edit]

To make edits you have to be logged in to the API first. Follow the general instructions for logging in to the MediaWiki API: here (Using either a bot password or the account directly. OAuth is not supported.). Remember that future requests require whatever cookies are set here in order for them to be considered logged in.

New study[edit]

Api URL: https://bugsigdb.org/w/api.php

Send a POST request with the following parameters (in application/x-www-urlencoded form):

  • action=pfautoedit
  • format=json
  • query as follows below

The parameter named query contains additional parameters also in x-www-urlencoded form (So in essence double encoded). Parameters starting with Study will use a default value if omitted. Parameters ending in [] are list items and can be specified multiple times for multiple values.

  • editRevId=0
  • wpSummary=Editsummary for use on history and Special:Recentchanges
  • form=Study
  • Study[study design][]=type of study
  • Study[study design][is_list]=1
  • Study[Mode]=Auto
  • Study[PMID]=PMID here
  • Study[DOI]=DOI here
  • Study[URI]=URL of study
  • Study[State]=Complete or incomplete

An example using curl: curl 'https://bugsigdb.org/w/api.php' --data-raw 'action=pfautoedit&format=json&query=Study%5Bstudy%20design%5D%5B%5D%3Dcase-control%26Study%5Bstudy%20design%5D%5B%5D%3Dmeta-analysis%26Study%5Bstudy%20design%5D%5Bis_list%5D%3D1%26Study%5BMode%5D%3DAuto%26Study%5BPMID%5D%3D12345%26Study%5BDOI%5D%3DDOI%20here%26Study%5BURI%5D%3Dhttp%3A%2F%2Fexample.com%26Study%5BState%5D%3DComplete%26editRevId%3D0%26wpSummary%3DAdding%20study%20via%20API%26form%3DStudy' -H 'Cookie: mediawikiUserName=MyUserName; mediawikiUserID=76; mediawikiToken=c8a97ee560b9fd022c46c3bc5de3e3cc; mediawiki_session=mu1880l9i4p1crn91egthridbmff79sn'

This should return JSON like the following:

{
   "form" : {
      "title" : "Study"
   },
   "redirect" : "https://bugsigdb.org/Study_719",
   "responseText" : "Modified <a href=\"/Study_719\" title=\"Study 719\">Study 719</a> using form Study.",
   "status" : 200,
   "target" : "Study 719"
}

Keep the target value, as you will need that to add an experiment to this study.

New Experiment[edit]

Api URL: https://bugsigdb.org/w/api.php

Send a POST request with the following parameters (in application/x-www-urlencoded form):

  • action=pfautoedit
  • format=json
  • query as follows below

The parameter named query contains additional parameters also in x-www-urlencoded form (So in essence double encoded). Parameters that can take multiple values end in [] and can be repeated. For example, if the study included participants in Canada and Norway, you would have parameters like Experiment[Location of subjects][]=Canada and Experiment[Location of subjects][]=Norway. Parameters starting with Experiment can be omitted to use a default value. The query parameters are:

  • editRevId=0 (Assuming you are creating a new experiment, not editing an existing one)
  • wpSummary= A message describing your edit (Shows up as the edit summary on history view and recent changes
  • form=Experiment
  • Experiment[Base page]= The page name representing the study this experiment is for (e.g. Study_123). If you created the Study recently, this will be the target value in the JSON response from the request to create the Study
  • Experiment[Location of subjects][]= Country name here
  • Experiment[Location of subjects][is_list]=1
  • Experiment[Host species]=Host species here
  • Experiment[Body site][]=First body site
  • Experiment[Body site][]=Second body site
  • Experiment[Body site][is_list]=1
  • Experiment[Condition][]= condition here
  • Experiment[Condition][is_list]=1
  • Experiment[Group 0 name]=NameForGroup0
  • Experiment[Group 1 name]=NameForGroup1
  • Experiment[Group 1 definition]=Group 1 definition
  • Experiment[Group 0 sample size]=sample size here
  • Experiment[Group 1 sample size]=sample size of group 2 here
  • Experiment[Antibiotics exclusion]=Antibiotic exclusion here
  • Experiment[Sequencing type]=sequencing type here
  • Experiment[Sequencing platform][]=platform
  • Experiment[Sequencing platform][is_list]=1
  • Experiment[Statistical test][]= Statistical test here
  • Experiment[Statistical test][is_list]=1
  • Experiment[Significance threshold]=threshold here
  • Experiment[MHT correction]=Yes or No here
  • Experiment[LDA Score above]=Number here
  • Experiment[Matched on][]= matched on here
  • Experiment[Matched on][is_list]=1
  • Experiment[Confounders controlled for][]=Confounding variable here
  • Experiment[Confounders controlled for][is_list]=1
  • Experiment[Pielou]=decreased/increased/unchanged
  • Experiment[Shannon]=decreased/increased/unchanged
  • Experiment[Chao1]=decreased/increased/unchanged
  • Experiment[Simpson]=decreased/increased/unchanged
  • Experiment[Inverse Simpson]=decreased/increased/unchanged
  • Experiment[Richness]=decreased/increased/unchanged
  • Experiment[State]=Complete or Incomplete


Putting it all together, if you were using curl, you would get a curl request that looks something like the following:

curl 'https://bugsigdb.com/w/api.php' --data-raw 'action=pfautoedit&format=json&query=Experiment%5BBase%20page%5D%3DStudy_473%26Experiment%5BLocation%20of%20subjects%5D%5B%5D%3DCanada%26Experiment%5BLocation%20of%20subjects%5D%5Bis_list%5D%3D1%26Experiment%5BHost%20species%5D%3DHomo%20sapiens%26Experiment%5BBody%20site%5D%5B%5D%3DAccessory%20saphenous%20vein%26Experiment%5BBody%20site%5D%5B%5D%3D1st%20arch%20mandibular%20endoderm%26Experiment%5BBody%20site%5D%5Bis_list%5D%3D1%26Experiment%5BCondition%5D%5B%5D%3D%28%2B%29-dexrazoxane%26Experiment%5BCondition%5D%5Bis_list%5D%3D1%26Experiment%5BGroup%200%20name%5D%3DNameForGroup0%26Experiment%5BGroup%201%20name%5D%3DNameForGroup1%26Experiment%5BGroup%201%20definition%5D%3DGroup%201%20definition%26Experiment%5BGroup%200%20sample%20size%5D%3D100%26Experiment%5BGroup%201%20sample%20size%5D%3D100%26Experiment%5BAntibiotics%20exclusion%5D%3DAntibiotic%20exclusion%20here%26Experiment%5BSequencing%20type%5D%3DWMS%26Experiment%5BSequencing%20platform%5D%5B%5D%3DIon%20Torrent%26Experiment%5BSequencing%20platform%5D%5B%5D%3DDNA-DNA%20Hybridization%26Experiment%5BSequencing%20platform%5D%5Bis_list%5D%3D1%26Experiment%5BStatistical%20test%5D%5B%5D%3DDunn%27s%20test%26Experiment%5BStatistical%20test%5D%5Bis_list%5D%3D1%26Experiment%5BSignificance%20threshold%5D%3D0.01%26Experiment%5BMHT%20correction%5D%3DYes%26Experiment%5BLDA%20Score%20above%5D%3D3%26Experiment%5BMatched%20on%5D%5B%5D%3Ddate%26Experiment%5BMatched%20on%5D%5Bis_list%5D%3D1%26Experiment%5BConfounders%20controlled%20for%5D%5B%5D%3Dsmoking%20behavior%26Experiment%5BConfounders%20controlled%20for%5D%5Bis_list%5D%3D1%26Experiment%5BPielou%5D%3Ddecreased%26Experiment%5BShannon%5D%3Dunchanged%26Experiment%5BChao1%5D%3Dincreased%26Experiment%5BSimpson%5D%3Ddecreased%26Experiment%5BInverse%20Simpson%5D%3Dincreased%26Experiment%5BRichness%5D%3Dunchanged%26Experiment%5BState%5D%3DComplete%26editRevId%3D0%26wpSummary%3DAdding%20experiment%20via%20API%26form%3DExperiment' -H 'Cookie: mediawikiUserName=MyUserName; mediawikiUserID=76; mediawikiToken=c8a97ee560b9fd022c46c3bc5de3e3cc; mediawiki_session=mu1880l9i4p1crn91egthridbmff79sn'

The values here were chosen at random. You would of course have to use the correct cookies for your user.

On success you should get a JSON response that looks like:

{
   "form" : {
      "title" : "Experiment"
   },
   "redirect" : "https://bugsigdb.org/Study_473/Experiment_4",
   "responseText" : "Modified <a href=\"/Study_473/Experiment_4\" title=\"Study 473/Experiment 4\">Study 473/Experiment 4</a> using form Experiment.",
   "status" : 200,
   "target" : "Study 473/Experiment 4"
}

Keep the target value, as you will need it to attach a signature to this experiment.

New signature[edit]

Api URL: http://bugsigdb.org/w/api.php

Send a POST request with the following parameters (in application/x-www-urlencoded form):

  • action=pfautoedit
  • format=json
  • query as follows below

The parameter named query contains additional parameters also in x-www-urlencoded form (So in essence double encoded). Parameters starting with Study will use a default value if omitted. Parameters ending in [] are list items and can be specified multiple times for multiple values.

  • editRevId=0
  • wpSummary=Adding signature via API
  • form=Signature
  • Signature[Base page]=The experiment id that this is attached to (target from previous api response). e.g. Study 473/Experiment 4
  • Signature[Source]=Source here
  • Signature[Description]=Description here
  • Signature[Abundance in Group 1]=increased
  • Signature[NCBI][]=Numeric NCBI id here
  • Signature[NCBI][is_list]=1
  • Signature[State]=Complete

An example curl request:

curl 'https://bugsigdb.org/w/api.php' --data-raw 'action=pfautoedit&format=json&query=Signature%5BBase%20page%5D%3DStudy%20473%2FExperiment%204%26Signature%5BSource%5D%3DSource%20here%26Signature%5BDescription%5D%3DDescription%20here%26Signature%5BAbundance%20in%20Group%201%5D%3Dincreased%26Signature%5BNCBI%5D%5B%5D%3D1581061%26Signature%5BNCBI%5D%5Bis_list%5D%3D1%26Signature%5BState%5D%3DComplete%26editRevId%3D0%26wpSummary%3DAdding%20signature%20via%20API%26form%3DSignature' -H 'Cookie: mediawikiUserName=MyUserName; mediawikiUserID=76; mediawikiToken=c8a97ee560b9fd022c46c3bc5de3e3cc; mediawiki_session=mu1880l9i4p1crn91egthridbmff79sn'

This should give a result like:

{
   "form" : {
      "title" : "Signature"
   },
   "redirect" : "https://bugsigdb.org/Study_473/Experiment_4/Signature_2",
   "responseText" : "Modified <a href=\"/Study_473/Experiment_4/Signature_2\" title=\"Study 473/Experiment 4/Signature 2\">Study 473/Experiment 4/Signature 2</a> using form Signature.",
   "status" : 200,
   "target" : "Study 473/Experiment 4/Signature 2"
}