Passing params to delete API method using golang

Actually I have cracked it. Yes, API auth working fine on all other messages.

After staring at it for a while, I decided to encode the required variable with the URL rather than passing as formdata. This seems to be different to how the Discourse app is working, but it works.

Also, the API documentation only mentions using the user_id - and I noticed it also allows user_email or username. As it happens, username is more convenient for my purpose.

In case anyone passes this way and finds it useful, this is how I adjusted the DELETE method of this library: GitHub - FrenchBen/godisco: A Golang library for the Discourse Forum API · GitHub - so it is now easy to pass variables to be encoded in either the formdata or query string. In passing the username variable as a url.Value to the querydata - this now works perfectly. Am still not sure why I cannot duplicate the behaviour of the discourse app (not sure I am encoding the formdata correctly) - but it works a charm now and using username is better for me so I am out ahead!

Many thanks again for your help…

// DELETE Method - optionally can take querydata and formdata
func (c *DiscourseClient) Delete(endpoint string, querydata url.Values, formdata url.Values) (error) {

	// Put authentication into the url
	apiAuth := url.Values{}
	apiAuth.Set("api_key", c.key)
	apiAuth.Add("api_username", c.user)

	// This adds the optional querydata settings to the URL
	for key := range querydata {
		apiAuth.Add(key, querydata.Get(key))
	}

	url := fmt.Sprintf("%s%s?%s", c.domain, endpoint, apiAuth.Encode())

	// If supplied, encode the formdata to include in the body
	body := strings.NewReader(formdata.Encode())

	req, err := http.NewRequest("DELETE", url, body)
	if err != nil {
		log.Warn("discoclient.Delete failed", err)
		return err
	}

	// We just need to know whether the delete was a success
	_, err = c.do(req)

	return err
 }