# Using custom remote contexts

**URL:** <https://community.blockcerts.org/t/using-custom-remote-contexts/2764>\
**Category:** Uncategorized\
**Created:** [March 8, 2021, 7:12pm UTC](https://community.blockcerts.org/t/using-custom-remote-contexts/2764 "2021-03-08T19:12:06Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ampatt97](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@ampatt97](https://community.blockcerts.org/u/ampatt97)\
**Post date:** [March 8, 2021, 7:12pm UTC](https://community.blockcerts.org/t/using-custom-remote-contexts/2764/1 "2021-03-08T19:12:06Z")

</div>

Any advice on adding my own contexts remotely to my credentials?

Whenever I try to implement credentials with my own context I receive a jsonld error

```
pyld.jsonld.JsonLdError: ('Could not retrieve a JSON-LD document from the URL.',)

Type: jsonld.LoadDocumentError

Code: loading document failed

Details: {'remoteDoc': {'contextUrl': None, 'documentUrl':
```

---

<div class="post-metadata">

**Author:** ![ampatt97](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@ampatt97](https://community.blockcerts.org/u/ampatt97)\
**Post date:** [March 10, 2021, 10:18pm UTC](https://community.blockcerts.org/t/using-custom-remote-contexts/2764/2 "2021-03-10T22:18:33Z")

</div>

After more testing. In my @context, if I use the url that contains the v2.1 blockcerts context from the blockcerts url ([https://www.blockcerts.org/schema/2.1/context.json](https://www.blockcerts.org/schema/2.1/context.json)) I get json-ld parsing errors, BUT if I use the [https://w3id.org/blockcerts/v2.1](https://w3id.org/blockcerts/v2.1) link that redirects to the context on the blockcerts domain then the issuer yields no errors. What is the difference between these two links as far as the issuer is concerned?

---

<div class="post-metadata">

**Author:** ![lemoustachiste](https://avatars.discourse-cdn.com/v4/letter/l/7c8e57/32.png) [@lemoustachiste](https://community.blockcerts.org/u/lemoustachiste)\
**Post date:** [March 12, 2021, 2:23pm UTC](https://community.blockcerts.org/t/using-custom-remote-contexts/2764/3 "2021-03-12T14:23:11Z")

</div>

I am not sure about the internals of jsonld which I have had to debug at times, but [w3id.org](http://w3id.org) is there to provide some sort of normalization of the data. However in early days of v3 blockcerts referencing a URL that was not going through [w3id.org](http://w3id.org) was working. So from what you describe, I don’t know what the error could be.  
Is your custom context a valid jsonld? You should be able to specify a third context or extra properties, as we do with Learning Machine (displayHTML, metadataJson, etc).

---

<div class="post-metadata">

**Author:** ![ampatt97](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@ampatt97](https://community.blockcerts.org/u/ampatt97)\
**Post date:** [March 12, 2021, 3:26pm UTC](https://community.blockcerts.org/t/using-custom-remote-contexts/2764/4 "2021-03-12T15:26:45Z")

</div>

I have successfully linked direct contexts using the additional\_global\_fields for displayHTML and others but when I try to add another url to a remote context it gives me the error, I have validated that it is valid jsonld using the jsonld playground([JSON-LD Playground](https://json-ld.org/playground/)). The main reason I need this is that the Open Badges validation is yielding error from all 4 of the open badges extensions that blockcerts uses (RecipientProfile, SignatureLine, MerkleProof2017 and MerkleProofVerification2017).

---

<div class="post-metadata">

**Author:** ![lemoustachiste](https://avatars.discourse-cdn.com/v4/letter/l/7c8e57/32.png) [@lemoustachiste](https://community.blockcerts.org/u/lemoustachiste)\
**Post date:** [March 12, 2021, 6:00pm UTC](https://community.blockcerts.org/t/using-custom-remote-contexts/2764/5 "2021-03-12T18:00:29Z")

</div>

if you can provide me with an example I can to see what’s happening locally

---

<div class="post-metadata">

**Author:** ![lemoustachiste](https://avatars.discourse-cdn.com/v4/letter/l/7c8e57/32.png) [@lemoustachiste](https://community.blockcerts.org/u/lemoustachiste)\
**Post date:** [March 12, 2021, 6:01pm UTC](https://community.blockcerts.org/t/using-custom-remote-contexts/2764/6 "2021-03-12T18:01:03Z")

</div>

or at least a link to the context you are trying to use as an extra

---

<div class="post-metadata">

**Author:** ![ampatt97](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@ampatt97](https://community.blockcerts.org/u/ampatt97)\
**Post date:** [March 19, 2021, 6:22pm UTC](https://community.blockcerts.org/t/using-custom-remote-contexts/2764/7 "2021-03-19T18:22:51Z")

</div>

I sent you the link to the remote context I am trying in a PM.

---

<div class="post-metadata">

**Author:** ![ampatt97](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@ampatt97](https://community.blockcerts.org/u/ampatt97)\
**Post date:** [June 10, 2021, 9:55pm UTC](https://community.blockcerts.org/t/using-custom-remote-contexts/2764/8 "2021-06-10T21:55:13Z")

</div>

After coming back to this I noticed this line on the cert\_schema repo [here](https://github.com/blockchain-certificates/cert-schema/blob/master/cert_schema/jsonld_helpers.py)

```auto
def to_loader_response(data, url):
    return {
        'contextUrl': None,
        'documentUrl': url,
        'document': data
    }

def load_document(url):
    """
    :param url:
    :return:
    """
    result = validators.url(url)
    if result:
        response = requests.get(
            url, headers={'Accept': 'application/ld+json, application/json'}
        )
        return response.text
    raise InvalidUrlError('Could not validate ' + url)

def jsonld_document_loader(url):
    """
    Retrieves JSON-LD at the given URL. Propagates BlockcertValidationError is url is invalid
    or doesn't exist
    :param url: the URL to retrieve
    :return: JSON-LD at the URL
    """
    data = load_document(url)
    return to_loader_response(data, url)

def preloaded_context_document_loader(url, override_cache=False):
    if url in PRELOADED_CONTEXTS:
        context = PRELOADED_CONTEXTS[url]
        return to_loader_response(context, url)
    else:
        return jsonld_document_loader(url)

```

the cert\_schema is sending a response that doesn’t include any contentType which causes the pyld to yield invalid json if you use a context that isn’t included in the Preloaded contexts list.

Edit: I was able to issue a credential with a remote context after making a change to cert\_schema’s to\_loader\_response return value but now with the custom context the verifier is yielding the “Not a Valid Blockcerts Credential” error when I attempted to verify the credential through blockcerts-verifier.

---

<div class="post-metadata">

**Author:** ![ampatt97](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@ampatt97](https://community.blockcerts.org/u/ampatt97)\
**Post date:** [June 11, 2021, 7:20pm UTC](https://community.blockcerts.org/t/using-custom-remote-contexts/2764/9 "2021-06-11T19:20:52Z")

</div>

Can someone help me understand what is happening in this function. I think this may be the source of my remote context parsing issue

```auto
const blockcertsContext = context.filter(ctx => typeof ctx === 'string').find(ctx => ctx.toLowerCase().indexOf('blockcerts') > 0);
  const blockcertsContextArray: string[] = blockcertsContext.split('/').filter(str => str !== '');

  const availableVersions: string[] = Object.keys(versionParserMap);

  return parseInt(availableVersions.filter(version => lookupVersion(blockcertsContextArray, version.toString()))[0], 10);

```

---

<div class="post-metadata">

**Author:** ![lemoustachiste](https://avatars.discourse-cdn.com/v4/letter/l/7c8e57/32.png) [@lemoustachiste](https://community.blockcerts.org/u/lemoustachiste)\
**Post date:** [June 14, 2021, 12:06pm UTC](https://community.blockcerts.org/t/using-custom-remote-contexts/2764/10 "2021-06-14T12:06:38Z")

</div>

Hi @ampatt97 glad you identified your issue, I couldn’t really understand your problem with what you shared with me.

I am a bit surprised by your first post, I believe there is a fetching action for non referenced (preloaded) contexts.

In the verifier “Not a Valid Blockcerts Credential”, you should be seeing the error in the console: [blockcerts-verifier/parse.ts at master · blockchain-certificates/blockcerts-verifier · GitHub](https://github.com/blockchain-certificates/blockcerts-verifier/blob/master/src/domain/certificates/useCases/parse.ts#L21)

Lastly the function you mentions retrieves among the different contexts the one that is referencing `blockcerts`, and then we analyze the version to know if it’s a v1, v2 or v3 certificate. I have not experienced issues with it but I guess it’s also because we are always expecting one of the contexts to be bound to `blockcerts` (either through w3id or through [blockcerts.org](http://blockcerts.org)).

If you completely moved your context to something not blockcerts, I would actually recommend that you maintain the blockcerts one, and use yours as an extension of said context, that you reference after (that way you may rewrite some of the semantics to suit your need). The other solution is to go and modify the cert-verifier-js to your needs.

---

<div class="post-metadata">

**Author:** ![ampatt97](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@ampatt97](https://community.blockcerts.org/u/ampatt97)\
**Post date:** [June 16, 2021, 6:04pm UTC](https://community.blockcerts.org/t/using-custom-remote-contexts/2764/11 "2021-06-16T18:04:17Z")

</div>

Thanks for the tip. That fixed my verification issues.
